How Arthas + MCP Enable AI-Powered Java Runtime Diagnosis
The article explains how the open‑source Java diagnostic tool Arthas now supports the Model Context Protocol (MCP), allowing AI assistants to invoke Arthas commands directly for CPU, latency, version, and Spring Bean issues, while covering installation, usage scenarios, and production safeguards.
What is Arthas
Arthas is an open‑source Java online diagnosis tool released by Alibaba in 2018, with over 35 000 stars on GitHub. It attaches a Java Agent to a running JVM, enabling non‑intrusive, no‑restart diagnostics. watch – prints method arguments and return values while the method executes, without modifying source code. trace – records the call chain and timing of each method, allowing precise identification of slow spots. stack – shows which call chain triggered a given method. jad – decompiles a class that is running in the JVM, confirming the exact code version. tt – records method‑call history for later replay, useful for intermittent issues. dashboard – displays real‑time JVM memory, thread and GC status. ognl – executes OGNL expressions to read Spring beans or other in‑memory data.
Model Context Protocol (MCP)
MCP (Model Context Protocol) is an open protocol introduced by Anthropic that standardises how large AI models invoke external tools and services. Instead of only responding with text, an AI model can issue actions such as database queries, API calls or command execution via MCP.
Major AI IDEs (e.g., Cursor, Claude Desktop) are adding MCP support, turning the protocol into an “AI plugin” standard. When Arthas implements MCP, every Arthas diagnostic capability becomes callable by an AI client.
Arthas MCP Server
The MCP support is provided by the Arthas MCP Server , which exposes an HTTP Server‑Sent Events (SSE) endpoint. AI clients connect using the MCP protocol and can invoke Arthas commands. arthas_command – executes any Arthas command. jvm_info – retrieves basic JVM information. thread_info – shows thread status and stack traces. class_info – inspects class metadata. method_trace – traces a method’s call chain. watch_method – monitors method arguments and return values. ognl_execute – runs an OGNL expression. decompile_class – decompiles a class.
These tools cover more than 90 % of typical online Java problem scenarios.
Installation and Startup
Install Arthas
One‑line script installation:
curl -O https://arthas.aliyun.com/arthas-boot.jar
java -jar arthas-boot.jarAfter launching, Arthas lists all Java processes on the host; select the target PID to attach.
Alternatively, download the binary zip:
wget https://github.com/alibaba/arthas/releases/latest/download/arthas-bin.zip
unzip arthas-bin.zip
sh as.shStart MCP Server
Arthas automatically starts an HTTP API at http://localhost:39394. The MCP Server builds on this API.
Mode 1 – Independent arthas-mcp-server – clone the repository and run with uvx (Python) or npm (Node):
# Python version
uvx arthas-mcp-serverMode 2 – Direct use of Arthas built‑in HTTP API – implement a custom MCP adapter on top of the existing API.
Configure Claude Desktop
Add the following JSON to claude_desktop_config.json:
{
"mcpServers": {
"arthas": {
"command": "uvx",
"args": ["arthas-mcp-server"]
}
}
}Restart Claude Desktop; the Arthas tool icon appears, indicating a successful connection.
Practical Scenarios
Scenario 1 – High CPU Usage
Traditional manual steps: top -Hp <pid> → identify hot thread → convert to hex → jstack dump → locate stack trace (minutes).
"Help me check why this Java process CPU is so high"
The AI calls thread -n 5 to fetch the five busiest threads, returns their stack traces, and the developer analyses the output.
Scenario 2 – Slow API Response
Identifying the bottleneck in a long call chain is difficult without knowing the entry point.
"Interface /api/order/list is slow, help me investigate"
The AI infers the controller class, runs trace, and prints per‑method timings, revealing the slow step.
Scenario 3 – Code Version Mismatch
When local tests pass but production behaves differently, developers previously used jad or inspected JAR timestamps.
"Confirm whether OrderService.processOrder is the latest version online"
The AI invokes jad, decompiles the class, and returns the source code for comparison.
Scenario 4 – Spring Bean State Inspection
To view a bean field (e.g., cache status), developers would craft an OGNL expression manually:
ognl "@[email protected]('userService').cache"With AI, a natural‑language request such as "show the current value of UserService.cache " triggers automatic OGNL generation and execution.
Precautions
Production safety – commands like trace and watch add runtime overhead. Filter high‑frequency methods or limit the tracing scope before using them on high‑traffic interfaces.
AI judgment – AI‑generated analysis of Arthas output is usually correct but must be verified. OGNL expressions may contain syntax errors; review them before execution.
MCP Server access control – the server exposes powerful JVM operations. Bind to 127.0.0.1 or add authentication to prevent external access.
Resource cleanup – run stop when Arthas is no longer needed to detach from the JVM and free resources.
References
Arthas website: https://arthas.aliyun.com
GitHub repository: https://github.com/alibaba/arthas
Arthas MCP Server source: https://github.com/alibaba/arthas/tree/master/arthas-mcp-server
Command reference documentation: https://arthas.aliyun.com/doc/commands.html
MCP protocol specification: https://modelcontextprotocol.io
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
