javaperf

io.github.theSharque由 GitHub 账号 theSharque 发布v1.4.2更新于 Oct 24, 2026

Java profiling MCP via jcmd/jfr/jps. Diagnose performance, analyze threads, inspect JFR recordings.

已验证STDIO仅桌面开发者工具安全与监控

概览

AI 生成的概览

本地 MCP 服务器,借助 JDK 的 jps、jcmd、jfr 工具,让助手对运行中的 Java 应用做性能剖析与诊断。

可以做什么
  • 列出运行中的 Java 进程,查看 JVM 信息、运行时长、版本与启动参数
  • 启动、列出并停止 JFR 录制,再把录制解析为摘要、CPU、调用频率、内存、GC、网络、文件 I/O、锁与原生方法剖析
  • 生成线程转储、检测死锁并分析锁等待链
  • 检查堆:类直方图、增长对比、堆转储与堆摘要
  • 执行 jcmd 诊断:原生内存、GC 类统计、终结器、编译器代码缓存与编译队列
  • 从录制中构建某个方法的调用树
适用场景
适合在同一台机器上排查 Java 性能问题:CPU 占用高、内存泄漏、GC 压力、锁竞争、死锁或 I/O 缓慢,无需手动敲 jcmd 和 jfr 命令。
运行要求
以本地 stdio 进程运行,通常通过 npx 从 npm 包 javaperf 启动。需要 Node.js v18+ 以及支持 JFR 的 JDK(8u262+ 或 11+);jps、jcmd、jfr 通过 JAVA_HOME 或 PATH 查找,必要时需在服务器配置中设置 JAVA_HOME。必须与目标 JVM 在同一主机、以同一操作系统用户运行。
安装前请注意
它会附加到运行中的 JVM,可能影响应用:heap_histogram 的 all 选项会触发 Full GC,可能造成应用停顿;heap_dump 会在 recordings 目录写入 .hprof 文件。录制与转储都保存在本地磁盘。它只在 MCP 进程所在主机和用户账户下有效,无法访问其他机器上的 JVM。

安装

在 SourceWeft 中

  1. 打开 控制台中的 javaperf,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

javaperf

[npm version]

MCP (Model Context Protocol) server for profiling Java applications via JDK utilities (jcmd, jfr, jps)

Enables AI assistants to diagnose performance, analyze threads, and inspect JFR recordings without manual CLI usage.

📦 Install: npm install -g javaperf or use via npx 🌐 npm: https://www.npmjs.com/package/javaperf

How to connect to Claude Desktop / IDE

Add the server to your MCP config. Example for claude_desktop_config.json:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json Linux: ~/.config/Claude/claude_desktop_config.json

json
{  "mcpServers": {    "javaperf": {      "command": "npx",      "args": ["-y", "javaperf"]    }  }}

For Cursor IDE: Settings → Features → Model Context Protocol → Edit Config, then add the same block inside mcpServers. See the Integration section for more options (local dev, custom JAVA_HOME, etc.).

Requirements

  • Node.js v18+
  • JDK 8u262+ or 11+ with JFR support

JDK tools (jps, jcmd, jfr) are auto-detected via JAVA_HOME or which java. If not found, set JAVA_HOME to your JDK root.

Quick Start

For Users (using npm package)

bash
# No installation needed - use directly in Cursor/Claude Desktop# Just configure it as described in Integration section below

For Developers

  1. Clone the repository:
bash
git clone https://github.com/theSharque/mcp-jperf.gitcd mcp-jperf
  1. Install dependencies:
bash
npm install
  1. Build the project:
bash
npm run build

Usage

Development Mode

bash
npm run dev

Production Mode

bash
npm start

MCP Inspector

Debug and test with MCP Inspector:

bash
npx @modelcontextprotocol/inspector node dist/index.js

Integration

Cursor IDE

  1. Open Cursor Settings → Features → Model Context Protocol
  2. Click "Edit Config" button
  3. Add one of the configurations below
Option 1: Via npm (Recommended)

Installs from npm registry automatically:

json
{  "mcpServers": {    "javaperf": {      "command": "npx",      "args": ["-y", "javaperf"]    }  }}
Option 2: Via npm link (Development)

For local development with live changes:

json
{  "mcpServers": {    "javaperf": {      "command": "javaperf"    }  }}

Requires: cd /path/to/mcp-jperf && npm link -g

Option 3: Direct path
json
{  "mcpServers": {    "javaperf": {      "command": "node",      "args": ["dist/index.js"],      "cwd": "${workspaceFolder}",      "env": {        "JAVA_HOME": "/path/to/your/jdk"      }    }  }}

If list_java_processes fails with "jps not found", the MCP server may not inherit your shell's JAVA_HOME. Add the env block above with your JDK root path (e.g. /usr/lib/jvm/java-17 or ~/.sdkman/candidates/java/current).

Claude Desktop

Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):

json
{  "mcpServers": {    "javaperf": {      "command": "npx",      "args": ["-y", "javaperf"]    }  }}

Continue.dev

Edit .continue/config.json:

json
{  "mcpServers": {    "javaperf": {      "command": "npx",      "args": ["-y", "javaperf"]    }  }}

Tools

ToolDescription
list_java_processesList running Java processes (pid, mainClass, args). Use topN (default 10) to limit.
start_profilingStart JFR. Pass pid, duration (seconds). Optional: preset (default effective: profile), settingsFile (path to .jfc, mutually exclusive with preset), memorysize, stackdepth (default 128).
profile_jfr_networkSocket I/O summary from .jfr (jdk.SocketRead, jdk.SocketWrite). Optional filepath (default new_profile), topN.
profile_jfr_file_ioFile read/write summary (jdk.FileRead, jdk.FileWrite). Optional filepath, topN.
profile_jfr_locksMonitor contention (JavaMonitorBlocked) and j.u.c parking (ThreadPark). Optional filepath, topN. Live waits: analyze_threads structured=true.
profile_jfr_nativeNative-method CPU hotspots (jdk.NativeMethodSample). Optional filepath, topN.
native_memory_summaryjcmd VM.native_memory summary — requires JVM with -XX:NativeMemoryTracking=summary or detail. Pass pid.
gc_class_statsjcmd GC.class_stats when available (often JDK 21+). Pass pid.
gc_finalizer_infojcmd GC.finalizer_info. Pass pid.
compiler_codecachejcmd Compiler.codecache. Pass pid.
compiler_queuejcmd Compiler.queue. Pass pid.
list_jfr_recordingsList active JFR recordings for a process. Use before stop_profiling to get recordingId.
stop_profilingStop recording and save to recordings/new_profile.jfr. Requires pid and recordingId.
check_deadlockCheck for Java-level deadlocks. Returns structured JSON with threads, locks, and cycle.
analyze_threadsThread dump (jstack) with deadlock summary. Pass pid, optional topN (default 10), structured (JSON lock-wait chains). Live snapshot; historical locks: profile_jfr_locks.
heap_histogramClass histogram (GC.class_histogram). Pass pid, optional topN (20), all (triggers full GC — may pause app). Static snapshot; use heap_live_histogram_diff for growth.
heap_live_histogram_diffTwo histograms spaced by intervalSeconds (default 5). Top classes by instance/byte growth. First step in memory-leak workflow. Pass pid, optional topN, all, minInstanceDelta.
heap_dumpCreate .hprof for MAT/VisualVM. After heap_live_histogram_diff, use MAT Path to GC Roots. Pass pid. Saved to recordings/heap_dump.hprof.
heap_infoBrief heap summary. Pass pid.
vm_infoJVM info: uptime, version, flags. Pass pid.
trace_methodBuild call tree for a method from .jfr. Pass className, methodName. Optional: filepath (default new_profile), topN.
parse_jfr_summaryParse .jfr into summary: top methods, GC stats, anomalies. Optional: filepath (default new_profile), events, topN.
profile_memoryMemory profile: top allocators by bytes/count, allocation stacks, OldObjectSample by class. Optional: filepath, topN, sortBy (bytes/count). Pair with gc_efficiency, heap_live_histogram_diff.
gc_efficiencyGC efficiency from .jfr: pause vs freed bytes per collector. Optional: filepath, topN. After stop_profiling.
profile_timeCPU bottleneck profile (bottom-up). Optional: filepath (default new_profile), topN.
profile_frequencyCall frequency profile (leaf frames). Optional: filepath (default new_profile), topN.

Example Workflow

  1. List processes → list_java_processes
  2. Start recording → start_profiling with pid and duration (e.g. 60)
  3. Wait for duration seconds (or let it run)
  4. Check recordings (optional) → list_jfr_recordings to get recordingId
  5. Stop and save → stop_profiling with pid and recordingId
  6. Analyze → parse_jfr_summary, profile_memory, gc_efficiency, profile_time, profile_frequency, trace_method, profile_jfr_network, profile_jfr_file_io, profile_jfr_locks, or profile_jfr_native (events must exist in the recording — use start_profiling with a suitable preset or .jfc via settingsFile)

Example Workflow: Memory leak hypothesis

  1. List processes → list_java_processes
  2. Find growing classes → heap_live_histogram_diff with pid, intervalSeconds: 5
  3. Record under load → start_profiling → wait → stop_profiling
  4. Allocation profile → profile_memory on new_profile (check oldObjectSamplesByClass for suspect class)
  5. GC pressure → gc_efficiency on the same .jfr
  6. Confirm retention → heap_dump → Eclipse MAT → Path to GC Roots (exclude weak/soft references)
  7. AI builds a coherent leak hypothesis from the combined results (no dedicated tool)

Remote JVM (stdio MCP)

javaperf uses stdio MCP and attaches to JVMs via local jps/jcmd. That only works on the OS account and host where the MCP process runs.

To diagnose a JVM on another machine:

  • Run the MCP server (your IDE connector, Cursor, or Claude Desktop) on that machine, for example SSH remote workspace, Codespaces, CI runner checkout on the server, or a shell session on the same host as the process.
  • Do not rely on piping jcmd over plain SSH from another host unless you deliberately run MCP there; attaching across hosts is outside this server’s scope.

Requirements (same user, local attach) listed under Limitations still apply.

Limitations

  • Sampling: JFR samples ~10ms; fast methods may not appear in ExecutionSample
  • Local only: Runs on the machine where MCP is started
  • Permissions: Must run as same user as target JVM for jcmd access

来源:README.md,提交 9d97a88

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

2
  1. v1.4.2最新Sep 27, 2026
  2. v1.4.1Sep 16, 2026

评分

已满足适用检查项的 40%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分

    请在仓库或注册中心条目中声明许可证。