MCPcopy
hub / github.com/codeaashu/claude-code / getMcpConfigsByScope

Function getMcpConfigsByScope

src/services/mcp/config.ts:888–1026  ·  view source on GitHub ↗
(
  scope: 'project' | 'user' | 'local' | 'enterprise',
)

Source from the content-addressed store, hash-verified

886 * @returns Servers with scope information and any validation errors
887 */
888export function getMcpConfigsByScope(
889 scope: 'project' | 'user' | 'local' | 'enterprise',
890): {
891 servers: Record<string, ScopedMcpServerConfig>
892 errors: ValidationError[]
893} {
894 // Check if this source is enabled
895 const sourceMap: Record<
896 string,
897 'projectSettings' | 'userSettings' | 'localSettings'
898 > = {
899 project: 'projectSettings',
900 user: 'userSettings',
901 local: 'localSettings',
902 }
903
904 if (scope in sourceMap && !isSettingSourceEnabled(sourceMap[scope]!)) {
905 return { servers: {}, errors: [] }
906 }
907
908 switch (scope) {
909 case 'project': {
910 const allServers: Record<string, ScopedMcpServerConfig> = {}
911 const allErrors: ValidationError[] = []
912
913 // Build list of directories to check
914 const dirs: string[] = []
915 let currentDir = getCwd()
916
917 while (currentDir !== parse(currentDir).root) {
918 dirs.push(currentDir)
919 currentDir = dirname(currentDir)
920 }
921
922 // Process from root downward to CWD (so closer files have higher priority)
923 for (const dir of dirs.reverse()) {
924 const mcpJsonPath = join(dir, '.mcp.json')
925
926 const { config, errors } = parseMcpConfigFromFilePath({
927 filePath: mcpJsonPath,
928 expandVars: true,
929 scope: 'project',
930 })
931
932 // Missing .mcp.json in parent directories is expected, but malformed files should report errors
933 if (!config) {
934 const nonMissingErrors = errors.filter(
935 e => !e.message.startsWith('MCP config file not found'),
936 )
937 if (nonMissingErrors.length > 0) {
938 logForDebugging(
939 `MCP config errors for ${mcpJsonPath}: ${jsonStringify(nonMissingErrors.map(e => e.message))}`,
940 { level: 'error' },
941 )
942 allErrors.push(...nonMissingErrors)
943 }
944 continue
945 }

Callers 8

findUnmatchedFunction · 0.85
McpParsingWarningsFunction · 0.85
TrustDialogFunction · 0.85
getSettingsWithAllErrorsFunction · 0.85
mcpRemoveHandlerFunction · 0.85
getMcpConfigByNameFunction · 0.85
getClaudeCodeMcpConfigsFunction · 0.85

Calls 12

isSettingSourceEnabledFunction · 0.85
getCwdFunction · 0.85
parseFunction · 0.85
logForDebuggingFunction · 0.85
jsonStringifyFunction · 0.85
addScopeToServersFunction · 0.85
getGlobalConfigFunction · 0.85
parseMcpConfigFunction · 0.85
getCurrentProjectConfigFunction · 0.85
getEnterpriseMcpFilePathFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected