MCP Debugging
Effective debugging of MCP integrations requires monitoring the communication between the Host (Client) and the Server across different layers.
Key Debugging Tools
- mcp-inspector: An interactive, transport-agnostic web UI for testing tools, resources, and prompts.
- Server Logs:
-
- Stdio: Logs to
stderrare automatically captured by the host. - HTTP: Requires server-side aggregation or checking browser Network panels.
- Stdio: Logs to
-
- Client Developer Tools: Most hosts (like Claude Desktop) provide logs and connection status.
Implementing Logging
- ❌ NEVER log to
stdoutin stdio servers (it breaks the JSON-RPC stream). - ✅ ALWAYS log to
stderr. - Protocol Logging: Use
notifications/messageto send structured logs to the client.-
- python:
ctx.session.send_log_message(level="info", data="...") - TypeScript:
server.sendLoggingMessage({ level: "info", data: "..." })
- python:
-
Common Issues
1. Working Directory & Paths
Servers launched via config files often have an undefined working directory.
- Rule: Always use absolute paths for executable commands, file arguments, and
.envlocations.
2. Environment Variables
Stdio servers do not inherit all system environment variables.
- Fix: Explicitly define required variables (like API keys) in the
envsection of the client configuration.
3. Capability Mismatches
Errors like -32602 (Invalid params) often occur when a server tries to use a feature (like sampling) that the client hasn't enabled.
- Fix: Inspect the initial
initializehandshake to verify negotiated capabilities.
Host-Specific: Claude Desktop
- Logs:
-
- Windows:
%APPDATA%\Claude\logs\mcp.log - macOS:
~/Library/Logs/Claude/mcp.log
- Windows:
-
- DevTools: Enable via
developer_settings.json({"allowDevTools": true}) and pressCtrl+Alt+I.
References
- Source:
00_Raw/mcp/Debugging.md - mcp-inspector
- mcp-transport
- mcp-server-development
- mcp-best-practices
- mcp-client-development