mcp-spy

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

MCP Spy - Debug MCP Communication

MCP Spy - 调试MCP通信

Debug Model Context Protocol server integrations.
调试模型上下文协议(Model Context Protocol)服务器集成。

Overview

概述

MCP Spy helps debug:
  • Message traffic between Claude and MCP servers
  • Latency issues
  • Failed requests
  • Protocol compliance
MCP Spy可帮助调试以下问题:
  • Claude与MCP服务器之间的消息流量
  • 延迟问题
  • 请求失败
  • 协议合规性

Traffic Analysis

流量分析

View Recent Traffic

查看近期流量

bash
undefined
bash
undefined

Check MCP logs

查看MCP日志

tail -f ~/.claude/debug/mcp-*.log
tail -f ~/.claude/debug/mcp-*.log

Or specific server

或指定服务器

tail -f ~/.claude/debug/mcp-cm.log
undefined
tail -f ~/.claude/debug/mcp-cm.log
undefined

Filter by Type

按类型过滤

bash
undefined
bash
undefined

Tool calls only

仅查看工具调用

grep "tool_use" ~/.claude/debug/mcp-*.log
grep "tool_use" ~/.claude/debug/mcp-*.log

Errors only

仅查看错误

grep -i "error|failed" ~/.claude/debug/mcp-*.log
grep -i "error|failed" ~/.claude/debug/mcp-*.log

Specific tool

特定工具

grep "beads_add" ~/.claude/debug/mcp-*.log
undefined
grep "beads_add" ~/.claude/debug/mcp-*.log
undefined

Latency Analysis

延迟分析

Measure Response Times

测量响应时间

bash
undefined
bash
undefined

Time a specific tool

测试特定工具的耗时

time claude --print "Run beads_ready" --dangerously-skip-permissions 2>&1 | head -1
undefined
time claude --print "Run beads_ready" --dangerously-skip-permissions 2>&1 | head -1
undefined

Find Slow Calls

查找缓慢调用

bash
undefined
bash
undefined

Look for latency warnings in logs

在日志中查找延迟警告

grep -i "timeout|slow|latency" ~/.claude/debug/mcp-*.log
undefined
grep -i "timeout|slow|latency" ~/.claude/debug/mcp-*.log
undefined

Failed Request Analysis

失败请求分析

Find Failures

查找失败案例

bash
undefined
bash
undefined

All errors

所有错误

grep -i "error" ~/.claude/debug/mcp-*.log
grep -i "error" ~/.claude/debug/mcp-*.log

Parse error responses

解析错误响应

grep ""error":" ~/.claude/debug/mcp-*.log | jq '.'
undefined
grep ""error":" ~/.claude/debug/mcp-*.log | jq '.'
undefined

Common Issues

常见问题

  1. Connection refused - Server not running
  2. Timeout - Server too slow
  3. Invalid JSON - Malformed request/response
  4. Unknown tool - Tool not registered
  1. Connection refused - 服务器未运行
  2. Timeout - 服务器响应过慢
  3. Invalid JSON - 请求/响应格式错误
  4. Unknown tool - 工具未注册

MCP Server Debug

MCP服务器调试

Check Server Status

检查服务器状态

bash
undefined
bash
undefined

Test server connection

测试服务器连接

curl -X POST http://localhost:3000/mcp/list_tools
-H "Content-Type: application/json"
-d '{}'
undefined
curl -X POST http://localhost:3000/mcp/list_tools
-H "Content-Type: application/json"
-d '{}'
undefined

Server Logs

服务器日志

bash
undefined
bash
undefined

View server logs (if running as process)

查看服务器日志(如果以进程运行)

tail -f logs/mcp-server.log
tail -f logs/mcp-server.log

Or in terminal running server

或在运行服务器的终端中查看

Logs appear in stdout

日志会输出到标准输出

undefined
undefined

Test Tool Directly

直接测试工具

bash
undefined
bash
undefined

Call tool directly

直接调用工具

curl -X POST http://localhost:3000/mcp/call_tool
-H "Content-Type: application/json"
-d '{ "name": "beads_ready", "args": {} }'
undefined
curl -X POST http://localhost:3000/mcp/call_tool
-H "Content-Type: application/json"
-d '{ "name": "beads_ready", "args": {} }'
undefined

Protocol Debugging

协议调试

Inspect Messages

检查消息

bash
undefined
bash
undefined

Pretty print JSON messages

格式化打印JSON消息

grep "message" ~/.claude/debug/mcp-*.log | jq '.'
undefined
grep "message" ~/.claude/debug/mcp-*.log | jq '.'
undefined

Validate Requests

验证请求

bash
undefined
bash
undefined

Check request format

检查请求格式

gemini -m pro -o text -e "" "Validate this MCP request format:
$(grep "request" ~/.claude/debug/mcp-*.log | tail -1)
Check:
  1. Required fields present
  2. Types correct
  3. Schema compliance"
undefined
gemini -m pro -o text -e "" "Validate this MCP request format:
$(grep "request" ~/.claude/debug/mcp-*.log | tail -1)
Check:
  1. Required fields present
  2. Types correct
  3. Schema compliance"
undefined

Troubleshooting Guide

故障排除指南

Server Won't Start

服务器无法启动

bash
undefined
bash
undefined

Check if port in use

检查端口是否被占用

lsof -i :3000
lsof -i :3000

Check server process

检查服务器进程

ps aux | grep mcp
ps aux | grep mcp

Start with verbose

以 verbose 模式启动

node server/index.ts --verbose
undefined
node server/index.ts --verbose
undefined

Tool Not Found

工具未找到

bash
undefined
bash
undefined

List available tools

列出可用工具

curl http://localhost:3000/mcp/list_tools | jq '.tools[].name'
curl http://localhost:3000/mcp/list_tools | jq '.tools[].name'

Check tool registration

检查工具注册情况

grep "registerTool|toolRegistry" server/*.ts
undefined
grep "registerTool|toolRegistry" server/*.ts
undefined

Slow Responses

响应缓慢

bash
undefined
bash
undefined

Profile tool execution

分析工具执行耗时

time curl -X POST http://localhost:3000/mcp/call_tool
-H "Content-Type: application/json"
-d '{"name": "slow_tool", "args": {}}'
time curl -X POST http://localhost:3000/mcp/call_tool
-H "Content-Type: application/json"
-d '{"name": "slow_tool", "args": {}}'

Check for blocking operations

检查阻塞操作

grep -i "await|sync" tools/slow_tool/index.ts
undefined
grep -i "await|sync" tools/slow_tool/index.ts
undefined

JSON Parse Errors

JSON解析错误

bash
undefined
bash
undefined

Find malformed JSON

查找格式错误的JSON

grep -B 5 "JSON|parse" ~/.claude/debug/mcp-*.log | grep -i error
grep -B 5 "JSON|parse" ~/.claude/debug/mcp-*.log | grep -i error

Validate JSON

验证JSON格式

echo '{"test": ...}' | jq '.'
undefined
echo '{"test": ...}' | jq '.'
undefined

Monitoring

监控

Watch Traffic Live

实时查看流量

bash
undefined
bash
undefined

Real-time log monitoring

实时日志监控

tail -f ~/.claude/debug/mcp-*.log | grep --line-buffered "tool_use|result"
undefined
tail -f ~/.claude/debug/mcp-*.log | grep --line-buffered "tool_use|result"
undefined

Traffic Stats

流量统计

bash
undefined
bash
undefined

Count calls per tool

统计各工具的调用次数

grep "tool_use" ~/.claude/debug/mcp-.log |
grep -oP '"name":"[^"]
"' |
sort | uniq -c | sort -rn
undefined
grep "tool_use" ~/.claude/debug/mcp-.log |
grep -oP '"name":"[^"]
"' |
sort | uniq -c | sort -rn
undefined

Health Dashboard

健康仪表盘

bash
#!/bin/bash
bash
#!/bin/bash

mcp-health.sh

mcp-health.sh

echo "=== MCP Server Health ==="
echo "=== MCP Server Health ==="

Check server

检查服务器状态

if curl -s http://localhost:3000/health > /dev/null 2>&1; then echo "Server: UP" else echo "Server: DOWN" fi
if curl -s http://localhost:3000/health > /dev/null 2>&1; then echo "Server: UP" else echo "Server: DOWN" fi

Recent errors

近期错误数

ERRORS=$(grep -c "error" ~/.claude/debug/mcp-*.log 2>/dev/null || echo 0) echo "Recent errors: $ERRORS"
ERRORS=$(grep -c "error" ~/.claude/debug/mcp-*.log 2>/dev/null || echo 0) echo "Recent errors: $ERRORS"

Tool count

工具数量

TOOLS=$(curl -s http://localhost:3000/mcp/list_tools 2>/dev/null | jq '.tools | length' || echo 0) echo "Registered tools: $TOOLS"
undefined
TOOLS=$(curl -s http://localhost:3000/mcp/list_tools 2>/dev/null | jq '.tools | length' || echo 0) echo "Registered tools: $TOOLS"
undefined

Best Practices

最佳实践

  1. Enable logging - Keep debug logs on during development
  2. Check health first - Verify server running before debugging
  3. Test isolation - Test tools directly before through Claude
  4. Monitor latency - Watch for degradation
  5. Log rotation - Don't let logs grow unbounded
  6. Error alerts - Set up monitoring for failures
  1. 启用日志 - 开发期间保持调试日志开启
  2. 先检查健康状态 - 调试前先验证服务器是否运行
  3. 隔离测试 - 通过Claude测试前先直接测试工具
  4. 监控延迟 - 留意性能下降情况
  5. 日志轮转 - 避免日志无限制增长
  6. 错误告警 - 为故障设置监控告警