()
| 841 | * @returns Servers with scope information and any validation errors from current directory's .mcp.json |
| 842 | */ |
| 843 | export function getProjectMcpConfigsFromCwd(): { |
| 844 | servers: Record<string, ScopedMcpServerConfig> |
| 845 | errors: ValidationError[] |
| 846 | } { |
| 847 | // Check if project source is enabled |
| 848 | if (!isSettingSourceEnabled('projectSettings')) { |
| 849 | return { servers: {}, errors: [] } |
| 850 | } |
| 851 | |
| 852 | const mcpJsonPath = join(getCwd(), '.mcp.json') |
| 853 | |
| 854 | const { config, errors } = parseMcpConfigFromFilePath({ |
| 855 | filePath: mcpJsonPath, |
| 856 | expandVars: true, |
| 857 | scope: 'project', |
| 858 | }) |
| 859 | |
| 860 | // Missing .mcp.json is expected, but malformed files should report errors |
| 861 | if (!config) { |
| 862 | const nonMissingErrors = errors.filter( |
| 863 | e => !e.message.startsWith('MCP config file not found'), |
| 864 | ) |
| 865 | if (nonMissingErrors.length > 0) { |
| 866 | logForDebugging( |
| 867 | `MCP config errors for ${mcpJsonPath}: ${jsonStringify(nonMissingErrors.map(e => e.message))}`, |
| 868 | { level: 'error' }, |
| 869 | ) |
| 870 | return { servers: {}, errors: nonMissingErrors } |
| 871 | } |
| 872 | return { servers: {}, errors: [] } |
| 873 | } |
| 874 | |
| 875 | return { |
| 876 | servers: config.mcpServers |
| 877 | ? addScopeToServers(config.mcpServers, 'project') |
| 878 | : {}, |
| 879 | errors: errors || [], |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | /** |
| 884 | * Get all MCP configurations from a specific scope |
no test coverage detected