[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3

Common Issues & Fixes

🔍 Testing & Debugging10 min100 BASE XP

The MCP Debugging Playbook

After helping thousands of developers debug MCP servers, here are the most common issues and their fixes.

Top 10 MCP Issues

#SymptomCauseFix
1Server not detected by HostWrong path in configUse absolute paths in claude_desktop_config.json
2"Cannot find module" errorCommonJS/ESM mismatchAdd "type": "module" to package.json
3Tools don't appear in clientServer didn't declare tools capabilityEnsure tools are registered before server.connect()
4Garbled response / parse errorconsole.log() corrupting stdoutReplace ALL console.log with console.error
5Tool called with wrong argumentsPoor Zod descriptionsAdd detailed .describe() to every parameter
6Connection drops randomlyServer process crashes on errorWrap all tool handlers in try/catch, return isError: true
7"Transport closed" errorServer exited prematurelyCheck for missing dependencies or startup errors in stderr
8SSE connection timeoutMissing CORS or wrong endpointVerify CORS headers and the correct SSE endpoint URL
9Environment variables undefinedNot passed through configAdd "env" object to the server config in Host settings
10Resource returns emptyAsync resolution not awaitedEnsure resource handler is async and awaits all I/O

Debug Logging Pattern

// Always log to stderr, never stdout!
function debugLog(message: string, data?: any) {
  if (process.env.DEBUG === "true") {
    console.error(`[DEBUG] ${new Date().toISOString()} ${message}`, 
      data ? JSON.stringify(data, null, 2) : "");
  }
}

// Usage in tool handlers:
server.tool("my_tool", "...", { ... }, async (args) => {
  debugLog("Tool called with args:", args);
  try {
    const result = await doWork(args);
    debugLog("Tool result:", result);
    return { content: [{ type: "text", text: result }] };
  } catch (e: any) {
    debugLog("Tool error:", { message: e.message, stack: e.stack });
    return { isError: true, content: [{ type: "text", text: e.message }] };
  }
});
🚧 Critical Rule: Issue #4 (console.log corrupting stdout) is the #1 cause of "mysterious" MCP failures. When debugging, the FIRST thing to check is whether ANY library you import writes to stdout. Some logging libraries default to stdout — configure them for stderr.
SYNAPSE VERIFICATION
QUERY 1 // 3
What is the #1 cause of mysterious MCP server failures?
Network issues
console.log() or libraries writing to stdout, corrupting the JSON-RPC stream
Memory leaks
Incorrect TypeScript types
Watch: 139x Rust Speedup
Common Issues & Fixes | Testing & Debugging — MCP Academy