Stop Reading Raw Stacktraces: AI-Powered Java Thread Dump Analysis with MCP
Source: Dev.to
Introduction
Let’s be honest: who actually enjoys digging through 500 MB log files to find a needle in a haystack? Production is down, alerts are popping up, and you’re scrolling through hundreds of lines of a thread dump, hunting for the monitor lock that’s holding everything up or trying to determine whether http-nio-8080-exec-1 was already stuck at the same line seconds ago. It’s tedious, error‑prone, and boring.
What if your debugging tools didn’t just display data but actually understood it? Imagine asking an AI agent (e.g., Claude, Cursor, or Junie):
“Hey, why is the database pool hanging?”
and having it run your trusted analysis tools in the background to give you an answer.
In this article I’ll show how I revitalized TDA (Thread Dump Analyzer)—a classic open‑source GUI for Java thread‑dump analysis—by integrating it with the new Model Context Protocol (MCP). An AI agent, powered by MCP, can directly access local log files, find deadlocks, and identify performance bottlenecks faster and more accurately than manual analysis.
Welcome to the era of agentic debugging.
Adding the TDA MCP Server
Create or update your mcp.json configuration with a TDA server entry:
{
"mcpServers": {
"tda": {
"command": "java",
"args": [
"-Djava.awt.headless=true",
"-jar", "path/to/tda.jar",
"--mcp"
]
}
}
}
The --mcp flag tells TDA to start in MCP‑compatible mode.
Integrating with Junie (IntelliJ)
I integrated the MCP server into Junie, the AI assistant inside IntelliJ, by:
- Refactoring the TDA source to work with MCP.
- Adding the TDA server configuration to Junie’s settings.
After a successful integration, Junie’s settings panel lists the available commands for the TDA MCP server.
System Prompt for Log Handling
To ensure the agent uses the MCP server for log parsing (and avoids costly token usage), add the following system prompt to .junie/instructions.md (or to .cursorrules for Cursor users):
When you encounter a log file that appears to contain Java thread dumps:
1. DO NOT try to read or "cat" the entire file if it's large.
2. Use the `tda-analyzer` MCP toolset.
3. First, call `parse_log(path="...")` to initialize the analysis.
4. Use `get_summary()`, `check_deadlocks()`, and `find_long_running()` to perform the analysis.
5. Provide your insights based on the structured data returned by these tools rather than the raw log text.
Using the Integrated Analyzer
With the prompt in place, you can ask Junie (or any MCP‑compatible agent) to analyze a log:
Junie: "Please analyze the thread dump in /var/logs/app.log."
The agent will automatically:
- Call
parse_log(path="/var/logs/app.log"). - Run
check_deadlocks()andfind_long_running(). - Summarize the findings with
get_summary().
The output includes:
- Whether deadlocks were detected.
- Any long‑running threads.
- A concise summary of each thread dump.
If the agent is running inside the same codebase that produced the thread dumps, it can even suggest concrete code changes to fix the identified issues.
Benefits of MCP‑Powered TDA
- Speed – Temporal analysis across multiple snapshots that used to take minutes now completes in seconds.
- Accuracy – Structured data from the MCP tools eliminates mis‑interpretation of raw logs.
- Focus – Developers stay in their “flow” instead of grepping through massive files.
Future Work
- Refine the TDA MCP toolset (e.g., add
filter_by_thread_name). - Deepen IDE integrations (Cursor, IntelliJ via Junie).
- Encourage community contributions to the open‑source MCP module.
Get Started
- TDA Release 2.6 – https://github.com/your-org/tda/releases/tag/v2.6
- Explore the MCP module and contribute via pull requests.
Stop reading raw stack traces and start chatting with your JVM!