MCPcopy Index your code
hub / github.com/codeaashu/claude-code / parseMcpConfig

Function parseMcpConfig

src/services/mcp/config.ts:1297–1377  ·  view source on GitHub ↗
(params: {
  configObject: unknown
  expandVars: boolean
  scope: ConfigScope
  filePath?: string
})

Source from the content-addressed store, hash-verified

1295 * @returns Validated configuration with any errors
1296 */
1297export function parseMcpConfig(params: {
1298 configObject: unknown
1299 expandVars: boolean
1300 scope: ConfigScope
1301 filePath?: string
1302}): {
1303 config: McpJsonConfig | null
1304 errors: ValidationError[]
1305} {
1306 const { configObject, expandVars, scope, filePath } = params
1307 const schemaResult = McpJsonConfigSchema().safeParse(configObject)
1308 if (!schemaResult.success) {
1309 return {
1310 config: null,
1311 errors: schemaResult.error.issues.map(issue => ({
1312 ...(filePath && { file: filePath }),
1313 path: issue.path.join('.'),
1314 message: 'Does not adhere to MCP server configuration schema',
1315 mcpErrorMetadata: {
1316 scope,
1317 severity: 'fatal',
1318 },
1319 })),
1320 }
1321 }
1322
1323 // Validate each server and expand variables if requested
1324 const errors: ValidationError[] = []
1325 const validatedServers: Record<string, McpServerConfig> = {}
1326
1327 for (const [name, config] of Object.entries(schemaResult.data.mcpServers)) {
1328 let configToCheck = config
1329
1330 if (expandVars) {
1331 const { expanded, missingVars } = expandEnvVars(config)
1332
1333 if (missingVars.length > 0) {
1334 errors.push({
1335 ...(filePath && { file: filePath }),
1336 path: `mcpServers.${name}`,
1337 message: `Missing environment variables: ${missingVars.join(', ')}`,
1338 suggestion: `Set the following environment variables: ${missingVars.join(', ')}`,
1339 mcpErrorMetadata: {
1340 scope,
1341 serverName: name,
1342 severity: 'warning',
1343 },
1344 })
1345 }
1346
1347 configToCheck = expanded
1348 }
1349
1350 // Check for Windows-specific npx usage without cmd wrapper
1351 if (
1352 getPlatform() === 'windows' &&
1353 (!configToCheck.type || configToCheck.type === 'stdio') &&
1354 (configToCheck.command === 'npx' ||

Callers 3

runFunction · 0.85
getMcpConfigsByScopeFunction · 0.85

Calls 4

expandEnvVarsFunction · 0.85
getPlatformFunction · 0.85
entriesMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected