{"record":{"id":"c44d14edb36cf6ff","repo":"davila7/claude-code-templates","slug":"failed-to-parse-mcp-content-for-componentdata-na","errorCode":null,"errorMessage":"Failed to parse MCP content for ${componentData.name}: ${error.message}","messagePattern":"Failed to parse MCP content for (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli-tool/src/index.js","lineNumber":2365,"sourceCode":"      const commandsDir = path.join(targetDir, '.claude', 'commands');\n      await fs.ensureDir(commandsDir);\n      targetPath = path.join(commandsDir, `${fileName}.md`);\n      \n    } else if (type === 'mcp') {\n      // For MCPs, merge with existing .mcp.json\n      const targetMcpFile = path.join(targetDir, '.mcp.json');\n      let existingConfig = {};\n      \n      if (await fs.pathExists(targetMcpFile)) {\n        existingConfig = await fs.readJson(targetMcpFile);\n      }\n      \n      // Parse MCP content and merge\n      let mcpConfig;\n      try {\n        mcpConfig = JSON.parse(componentData.content);\n      } catch (error) {\n        throw new Error(`Failed to parse MCP content for ${componentData.name}: ${error.message}`);\n      }\n      \n      // Remove description field before merging (CLI processing)\n      if (mcpConfig.mcpServers) {\n        for (const serverName in mcpConfig.mcpServers) {\n          if (mcpConfig.mcpServers[serverName] && typeof mcpConfig.mcpServers[serverName] === 'object') {\n            delete mcpConfig.mcpServers[serverName].description;\n          }\n        }\n      }\n      \n      // Merge configurations\n      const mergedConfig = {\n        ...existingConfig,\n        ...mcpConfig\n      };\n      \n      // Deep merge mcpServers","sourceCodeStart":2347,"sourceCodeEnd":2383,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/index.js#L2347-L2383","documentation":"The CLI fetches the MCP component's JSON content and calls JSON.parse on it before merging into the user's MCP config. If the component file (or its embedded content field in components.json) is not valid JSON, the parse throws and the installer wraps it with the component name and the underlying parse error. This is a data-integrity error: the shipped component payload is malformed.","triggerScenarios":"Installing an MCP component via `npx claude-code-templates --mcp <name>` where the component's .json file contains a syntax error (trailing comma, comment, unquoted key, BOM) or the content was truncated during catalog generation.","commonSituations":"A maintainer hand-edited an MCP json and left a trailing comma or comment; the published components.json was generated from a partially saved file; the component contains template placeholders that are not valid JSON.","solutions":["Inspect the raw component JSON: open cli-tool/components/mcp/<category>/<name>.json and run it through a JSON validator to find the syntax error","Fix the JSON syntax (remove comments/trailing commas, quote keys), then re-run python scripts/generate_components_json.py and republish","If you can't edit the catalog, pin/roll back to a previous CLI version whose bundled catalog had a valid copy: npx claude-code-templates@<older-version> --mcp <name>","As a last resort, manually copy the corrected mcpServers block into your .mcp.json / claude_desktop config, matching what the installer would merge"],"exampleFix":"// before (component file)\n{\n  \"mcpServers\": {\n    \"example\": { \"command\": \"npx\", // note comment and trailing comma below\n      \"args\": [\"-y\", \"example\"], }\n  }\n}\n// after\n{\n  \"mcpServers\": {\n    \"example\": { \"command\": \"npx\", \"args\": [\"-y\", \"example\"] }\n  }\n}","handlingStrategy":"validation","validationCode":"const raw = componentData.content;\nlet parsed;\ntry { parsed = JSON.parse(raw); } catch (e) { console.error(`${componentData.name} has invalid JSON: ${e.message}`); process.exit(1); }","typeGuard":"function isValidMcpConfig(v) { return typeof v === 'object' && v !== null && typeof v.mcpServers === 'object' && v.mcpServers !== null; }","tryCatchPattern":"try { mcpConfig = JSON.parse(componentData.content); } catch (error) { if (error instanceof SyntaxError) { console.error(`Skipping malformed MCP component ${componentData.name}: ${error.message}`); return; } throw error; }","preventionTips":["Validate component JSON in CI with a JSON.parse check over components.json entries","Use strict JSON (no comments/trailing commas) in all MCP component files","Add a lint step to generate_components_json.py that fails the build on parse errors"],"tags":["json","mcp","component-install","catalog"],"backgroundTag":"invalid-json-payload","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}