多语言调试工具

MCP Debugger是一款支持多种语言的代理辅助调试工具,通过日志驱动的工作流帮助开发者快速定位和解决问题。

  • by metruzanca
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 metruzanca/mcp-debugger

使用说明

MCP调试器

受Cursor调试模式的启发,此MCP使任何代理都可以调试任何语言,只要它们有方法发出网络请求。

在本自述文件中,“调试器”是指代理辅助、日志驱动的调试工作流。确实如此 不 指用于遍历编译后的机器代码的低级/本机调试器(如gdb/lldb)。

用法

安装后,只需使用 /debug 命令后面是问题的描述:

/debug my button click handler isn't firing

代理将处理其余的工作——启动日志服务器、添加检测工具,并指导您完成调试过程。

示例:Flask+React+调试器输出

下面的示例显示了一个常见的流程:

  1. Flask将服务器端事件发送到日志服务器
  2. React从以下位置发送客户端事件 useEffect
  3. 调试器读取这些日志并测试假设

Flask(Python)日志记录到日志服务器

import requests
from flask import Flask, jsonify, request

app = Flask(__name__)
LOG_SERVER_URL = "http://localhost:6969"

def send_debug_log(event: str, **fields) -> None:
    payload = {"source": "flask", "event": event, **fields}
    try:
        requests.post(LOG_SERVER_URL, json=payload, timeout=0.4)
    except requests.RequestException:
        # Keep app behavior unchanged even if logging fails.
        pass

@app.post("/api/checkout")
def checkout():
    body = request.get_json(silent=True) or {}
    user_id = body.get("userId")
    items = body.get("items", [])

    send_debug_log("checkout.request.received", user_id=user_id, item_count=len(items))

    if not user_id:
        send_debug_log("checkout.request.rejected", reason="missing_user_id")
        return jsonify({"error": "missing userId"}), 400

    send_debug_log("checkout.request.accepted", user_id=user_id)
    return jsonify({"ok": True})

反应 useEffect 日志记录

import { useEffect } from "react";

type CheckoutProps = { userId: string | null; itemCount: number };

export function CheckoutPage({ userId, itemCount }: CheckoutProps) {
  useEffect(() => {
    fetch("http://localhost:6969", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        source: "react",
        event: "checkout.page.mounted",
        userId,
        itemCount,
      }),
    }).catch(() => {
      // Ignore logging errors in UI flow.
    });
  }, [userId, itemCount]);

  return <button>Checkout</button>;
}

调试器读取输出示例

[react] checkout.page.mounted userId=null itemCount=2
[flask] checkout.request.received user_id=null item_count=2
[flask] checkout.request.rejected reason=missing_user_id

代理可以从这些日志中形成的假设

  • userId 当页面装载时(身份验证引导和签出调用之间的计时/竞争),未准备好。
  • 检查有效载荷结构下降 userId 在发送请求之前。
  • 会话状态存在于一个层(客户端或服务器)中,但不会在两者之间一致传播。

然后,调试器会要求提供额外的目标日志,以消除假设并确认根本原因。

实时日志查看器

调试时,打开 http://localhost:6969 您可以在浏览器中通过SSE实时查看日志流。

安装

npx -y github:metruzanca/mcp-debugger

光标

  1. 打开的游标→ 设置→ MCP服务器
  2. 添加新的MCP服务器:
    • 姓名: mcp-debugger
    • 命令: npx
    • Args: ["-y", "github:metruzanca/mcp-debugger"]
  3. 点击“添加服务器”
  4. 重新启动游标

开放代码

添加到MCP服务器配置中:

  • 服务器名称: mcp-debugger
  • 命令: npx
  • 论据: ["-y", "github:metruzanca/mcp-debugger"]

克劳德桌面

增添 claude_desktop_config.json:

{
  "mcpServers": {
    "mcp-debugger": {
      "command": "npx",
      "args": ["-y", "github:metruzanca/mcp-debugger"]
    }
  }
}

运作原理

  1. 代理启动日志收集服务器
  2. 代理生成关于可能导致问题的假设
  3. 代理添加 fetch('http://localhost:6969', { method: 'POST', body: /* data */ }) 在验证点编码
  4. 对于基于UI的应用程序,代理会要求您重现错误
  5. 代理根据收集的日志数据验证假设
  6. Agent迭代地改进假设,直到找到根本原因

需求

  • Node.js 18+