Skip to main content
Glama
dronsv
by dronsv

jdwp-mcp

通过 JDWP 调试运行中的 JVM — 适用于任何兼容 MCP 的智能体。

License: MIT

通过自然语言附加到运行中的 Java 进程、暂停线程、检查堆栈和对象、设置断点并评估状态。 只需一个提示词,即可启动带有实时运行时数据的智能体驱动诊断循环。

适用于 Claude Code、Codex、Cursor 或任何兼容 MCP 的智能体。

查看实际效果

某个服务查询挂起了。查找根本原因:

> Attach to localhost:5005 and find out why a query is stuck.

智能体附加到进程,暂停所有线程,并扫描问题:

connected localhost:5005
paused
24 threads, 2 blocked

Thread pool-3-thread-7 is waiting for a monitor lock:
#0 RolapResult.loadMembers:142
  monitor=@3f2a  state=BLOCKED
#1 RolapResult.execute:89

Lock is held by pool-3-thread-2, which is running:
#0 SqlStatement.execute:218
  sql="SELECT ... FROM fact_table"   -- full scan on 36M rows

Root cause: the query bypassed the aggregate table and fell back to
a full fact-table scan. Thread-7 is waiting for thread-2 to finish.

一个提示词。六次工具调用。锁竞争和根本原因已识别。

快速入门

1. 安装

pip install jdwp-mcp
# Pre-built binary
curl -fsSL https://raw.githubusercontent.com/dronsv/jdwp-mcp/main/install.sh | sh

# Cargo (requires Rust)
cargo install --git https://github.com/dronsv/jdwp-mcp

# From source
git clone https://github.com/dronsv/jdwp-mcp && cd jdwp-mcp && cargo build --release

2. 配置您的智能体

claude mcp add jdwp jdwp-mcp

对于 Codex、Cursor 或其他兼容 MCP 的智能体,请添加到 .mcp.json

{
  "mcpServers": {
    "jdwp": {
      "command": "jdwp-mcp"
    }
  }
}

3. 使用 JDWP 启动您的 Java 应用

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar app.jar

4. 调试

Attach to localhost:5005 and set a breakpoint at com.example.MyService line 42

5. 自动批准(可选)

调试涉及许多快速的工具调用。自动批准可消除确认提示:

# Allow all jdwp tools for this project
claude config set --project allowedTools 'mcp__jdwp__*'
claude config set allowedTools 'mcp__jdwp__*'

仅对您信任的项目启用——jdwp 工具可以暂停线程、修改变量并在目标 JVM 上调用方法。

提示词包

选择适合您情况的包:

应用挂起或缓慢

Attach to localhost:5005
Pause the JVM and find all blocked or waiting threads
Show the stack for the blocked thread with variables
Who holds the lock? Show their stack too

日志中出现异常

Attach to localhost:5005
Set an exception breakpoint for NullPointerException
Wait for the exception to fire
Show the stack and all local variables at the throw site

需要了解代码路径

Attach to localhost:5005
Trace method calls on com.example.service
[send your HTTP request]
Show the trace result — which methods were called?

断点驱动的调试

Attach to localhost:5005
Find classes matching UserService
List methods of UserService with line numbers
Set a breakpoint at UserService line 45
When it hits, show the stack with all variables
Step over to the next line

Claude Code 命令

如果您克隆此仓库,将获得现成的斜杠命令:

  • /investigate-hang — 诊断挂起的 JVM(暂停、查找阻塞线程、追踪锁)

  • /investigate-exception — 捕获实时异常并检查抛出位置

  • /trace-request — 追踪请求经过的方法

以及一个自主调查智能体 (.claude/agents/jdwp-investigator.md),可用于诊断挂起、死锁、异常和意外的代码路径。

请参阅 .claude/settings.example.json 以获取推荐的自动批准和更新检查配置。

最佳首选使用场景

  • 挂起的请求和死锁

  • 阻塞的线程池

  • 可疑的 SQL 或运行时状态不匹配

  • 无需 IDE 访问的断点驱动诊断

  • 通过 kubectl port-forward 进行远程调试

为什么选择这个而不是 jstack 或 IDE?

  • 在您的智能体内工作 — 无需切换工具,无需单独的调试器窗口

  • 将附加 + 检查 + 推理结合在一个循环中 — 智能体决定下一步查看什么

  • 对话式 — 描述问题,智能体运行调试会话

  • 大型代码库的真实依据 — 在具有深层框架堆栈(Spring、Hibernate、OLAP 引擎)的复杂项目中,智能体在静态追踪代码路径时可能会迷失。实时调试为智能体提供了实际的运行时状态:哪个线程持有锁、生成了什么 SQL、变量当前的值到底是什么

工具

连接与控制 attach, disconnect, pause, continue, step into/over/out

断点与事件 set_breakpoint (带条件), clear, list, exception_breakpoint, watch (字段修改), wait_for_event

检查 get_stack (自动解析对象), get_variable, inspect, eval, set_value, snapshot, find_class, list_methods, list_threads, vm_info

追踪 trace (在包上启用方法级追踪), trace_result (获取调用路径)

不适用于

  • 事后堆内存分析

  • 常驻生产环境的可观测性

  • JDWP 附加或线程暂停在操作上不安全的生产环境

操作说明

JDWP 会改变运行时行为。暂停线程和设置断点可能会造成干扰。在生产环境中请谨慎使用;优先选择预发布环境或受控的维护窗口。

部署场景

请参阅 docs/deploy.md 了解 Maven、Gradle、Tomcat、Docker、Kubernetes (port-forward) 和 SSH 隧道的设置。

示例

架构

Agent  -->  MCP Server  -->  JDWP Client  -->  TCP  -->  JVM
              |
        Translates tool calls to JDWP,
        tracks session state, summarizes
        runtime objects for the agent.

从源码构建

cargo build --release
cargo test

许可证

MIT

Install Server
A
security – no known vulnerabilities
A
license - permissive license
C
quality - C tier

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dronsv/jdwp-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server