davila7/claude-code-templates · warning

Could not analyze MCPs:

Error message

Could not analyze MCPs:

What it means

YearInReview2025 MCP analysis caught an error and returns empty MCP data ({mcps: [], total: 0, events: []}); the report's MCP section is blanked.

Source

Thrown at cli-tool/src/analytics/core/YearInReview2025.js:810

            // Use modification time with slight offset for each MCP
            if (modifiedAt.getFullYear() === 2025) {
              const timestamp = new Date(modifiedAt.getTime() + (index * 1000)); // 1 second apart
              mcpEvents.push({
                name: name,
                timestamp: timestamp
              });
            }
          }
        });
      }

      return {
        mcps: mcps,
        total: mcps.length,
        events: mcpEvents.sort((a, b) => a.timestamp - b.timestamp)
      };
    } catch (error) {
      console.warn('Could not analyze MCPs:', error.message);
      return { mcps: [], total: 0, events: [] };
    }
  }

  /**
   * Analyze subagent usage
   * @param {string} claudeDir - Claude directory path
   * @returns {Promise<Object>} Subagents data
   */
  async analyzeSubagents(claudeDir) {
    const fs = require('fs-extra');
    const path = require('path');

    try {
      const projectsDir = path.join(claudeDir, 'projects');
      if (!await fs.pathExists(projectsDir)) {
        return { subagents: [], total: 0, events: [] };
      }

View on GitHub (pinned to a0851ed10c)

Solutions

  1. Validate the config: jq . ~/.claude.json — fix or restore if invalid
  2. Back up and let Claude Code regenerate the config if corruption is broad
  3. Ignore if MCP stats aren't important for you
  4. Update the CLI for tolerant MCP config parsing
Defensive patterns

Strategy: validation

Validate before calling

const raw = await fs.readFile(cfgPath, 'utf8').catch(() => null);
const cfg = raw ? (() => { try { return JSON.parse(raw); } catch { return null; } })() : null;
const servers = cfg?.mcpServers && typeof cfg.mcpServers === 'object' ? Object.keys(cfg.mcpServers) : [];

Type guard

function hasMcpServers(cfg) {
  return !!cfg && typeof cfg === 'object' &&
    typeof cfg.mcpServers === 'object' && cfg.mcpServers !== null;
}

Try / catch

try { return analyzeMcps(cfg); }
catch (error) { console.warn('Could not analyze MCPs:', error.message); return { mcps: [], total: 0, events: [] }; }

Prevention

When it happens

Trigger: Reading ~/.claude.json (or settings) to enumerate configured MCP servers fails — invalid JSON, oversized file, unexpected mcpServers shape.

Common situations: ~/.claude.json corrupted by a crashed write; mcpServers entries with unusual structures from manual editing or other tools; file locked on Windows.

Related errors


AI-assisted analysis of davila7/claude-code-templates@a0851ed10c (2026-08-28). Data as JSON: /api/errors/45202f66a5ee47ce. Report an issue: GitHub.