davila7/claude-code-templates · error · Error
Failed to parse MCP content for ${componentData.name}: ${err
Error message
Failed to parse MCP content for ${componentData.name}: ${error.message} What it means
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.
Source
Thrown at cli-tool/src/index.js:2365
const commandsDir = path.join(targetDir, '.claude', 'commands');
await fs.ensureDir(commandsDir);
targetPath = path.join(commandsDir, `${fileName}.md`);
} else if (type === 'mcp') {
// For MCPs, merge with existing .mcp.json
const targetMcpFile = path.join(targetDir, '.mcp.json');
let existingConfig = {};
if (await fs.pathExists(targetMcpFile)) {
existingConfig = await fs.readJson(targetMcpFile);
}
// Parse MCP content and merge
let mcpConfig;
try {
mcpConfig = JSON.parse(componentData.content);
} catch (error) {
throw new Error(`Failed to parse MCP content for ${componentData.name}: ${error.message}`);
}
// Remove description field before merging (CLI processing)
if (mcpConfig.mcpServers) {
for (const serverName in mcpConfig.mcpServers) {
if (mcpConfig.mcpServers[serverName] && typeof mcpConfig.mcpServers[serverName] === 'object') {
delete mcpConfig.mcpServers[serverName].description;
}
}
}
// Merge configurations
const mergedConfig = {
...existingConfig,
...mcpConfig
};
// Deep merge mcpServersView on GitHub (pinned to a0851ed10c)
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
Example fix
// before (component file)
{
"mcpServers": {
"example": { "command": "npx", // note comment and trailing comma below
"args": ["-y", "example"], }
}
}
// after
{
"mcpServers": {
"example": { "command": "npx", "args": ["-y", "example"] }
}
} Defensive patterns
Strategy: validation
Validate before calling
const raw = componentData.content;
let parsed;
try { parsed = JSON.parse(raw); } catch (e) { console.error(`${componentData.name} has invalid JSON: ${e.message}`); process.exit(1); } Type guard
function isValidMcpConfig(v) { return typeof v === 'object' && v !== null && typeof v.mcpServers === 'object' && v.mcpServers !== null; } Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- No files were copied from Cloudflare component directory
- Cloudflare component files not found at: ${componentsDir}
- Docker component files not found at: ${componentsDir}
- Components file not found
- Warning: Could not read settings.json for project ${projectD
AI-assisted analysis of davila7/claude-code-templates@a0851ed10c (2026-08-28).
Data as JSON: /api/errors/c44d14edb36cf6ff.
Report an issue: GitHub.