debug

A command for investigating problems in MCP servers, which are services that let AI agents use external tools or data. It can inspect protocol messages, tool execution, resources, and transport connections.

In plain words
What is it for?
Use it with commands such as `/debug protocol`, `/debug tools`, or `/debug all` when troubleshooting an MCP server.
Why use it?
It helps identify whether a server problem comes from communication, tool handling, resource access, or the connection layer. It can also increase logging, save logs, or launch MCP Inspector.

Command for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/matt-dionis/claude-code-configs/debug
Clone the repo
git clone --depth 1 https://github.com/Matt-Dionis/claude-code-configs

Made for: Claude Code.

Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,971 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01971
Opus 5 $0.00000 $0.00986
Sonnet 5 $0.00000 $0.00394
Haiku 4.5 $0.00000 $0.00197

Measured 2d ago against content hash 152d4f1344b2, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

debug scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

import { exec, spawn } from 'child_process';
configurations/mcp-servers/simple-mcp-server/.claude/commands/debug.md · 310 lines

How it starts

The opening of the file, as written. The whole thing — 310 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Debug MCP Server

Provides comprehensive debugging tools for troubleshooting MCP server issues.

Usage

/debug [component] [options]

Components

  • protocol - Debug protocol messages
  • tools - Debug tool execution
  • resources - Debug resource access
  • transport - Debug transport layer
  • all - Enable all debugging (default)

Options

  • --verbose - Extra verbose output
  • --save - Save debug logs to file
  • --inspector - Launch with MCP Inspector

Implementation

import * as fs from 'fs/promises';
import { exec, spawn } from 'child_process';
import * as path from 'path';

async function debugServer(
  component: 'protocol' | 'tools' | 'resources' | 'transport' | 'all' = 'all',
  options: {
    verbose?: boolean;
    save?: boolean;
    inspector?: boolean;
  } = {}
) {
  console.log('🔍 MCP Server Debugger');
  console.log('='.repeat(50));
  
  // Set debug environment variables
  const debugEnv = {
    ...process.env,
    DEBUG: component === 'all' ? 'mcp:*' : `mcp:${component}`,
    LOG_LEVEL: options.verbose ? 'trace' : 'debug',
    MCP_DEBUG: 'true',
  };
  
  // Create debug configuration
  const debugConfig = await createDebugConfig();
  
  // Start debug session
  if (options.inspector) {
    await launchWithInspector(debugEnv);
  } else {
    await runDebugSession(component, debugEnv, options);
  }
}

async function createDebugConfig(): Promise<string> {
  const config = {
    logging: {
      level: 'debug',
      format: 'pretty',
      includeTimestamp: true,
      includeLocation: true,
    },
    debug: {
      protocol: {
        logRequests: true,
        logResponses: true,
        logNotifications: true,
      },
      tools: {
        logCalls: true,
        logValidation: true,
        logErrors: true,
        measurePerformance: true,
      },
      resources: {
        logReads: true,
        logWrites: true,
        trackCache: true,
      },
      transport: {
        logConnections: true,
        logMessages: true,
        logErrors: true,
      },
    },
  };
  
  const configPath = '.debug-config.json';
  await fs.writeFile(configPath, JSON.stringify(config, null, 2));
  return configPath;
}

async function runDebugSession(
  component: string,
  env: NodeJS.ProcessEnv,
  options: { verbose?: boolean; save?: boolean }
) {
  console.log(`\n🔍 Debugging: ${component}`);
  console.log('Press Ctrl+C to stop\n');
  
  // Create debug wrapper
  const debugScript = `
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import debug from 'debug';
import pino from 'pino';

// Enable debug logging
const log = {
  protocol: debug('mcp:protocol'),
  tools: debug('mcp:tools'),
  resources: debug('mcp:resources'),
  transport: debug('mcp:transport'),
};

// Create logger
const logger = pino({
  level: process.env.LOG_LEVEL || 'debug',
  transport: {
    target: 'pino-pretty',
    options: {
      colorize: true,
      translateTime: 'HH:MM:ss.l',
      ignore: 'pid,hostname',
    },
  },
});

// Wrap server methods for debugging
const originalServer = await import('./src/index.js');
const server = originalServer.server;

// Intercept requests
const originalSetRequestHandler = server.setRequestHandler.bind(server);
server.setRequestHandler = (schema, handler) => {
  const wrappedHandler = async (request) => {
    const start = Date.now();
    log.protocol('→ Request: %O', request);
    logger.debug({ request }, 'Incoming request');
    
    try {
      const result = await handler(request);
      const duration = Date.now() - start;
      
      log.protocol('← Response (%dms): %O', duration, result);
      logger.debug({ result, duration }, 'Response sent');
      
      return result;
    } catch (error) {
      log.protocol('✗ Error: %O', error);
      logger.error({ error }, 'Request failed');
      throw error;
    }
  };
  
  return originalSetRequestHandler(schema, wrappedHandler);

Read the full file on GitHub · 310 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 310 lines · 0 tokens per session scan A 152d4f1344b2

Subscribe to this mod's changes

debug is a command published in the GitHub repository Matt-Dionis/claude-code-configs (625 stars, last pushed 1y ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,971 tokens. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.