Heap Analyzer MCP Server
Provides tools to analyze and compare JVM thread dumps, summarizing thread states and detecting deadlocks.
README
Heap Analyzer MCP Server
This repository provides a Python-based MCP (Model Context Protocol) server that exposes tools for analyzing JVM thread dumps:
- analyze_thread_dump: Parses a JVM thread dump text file and returns a summary of thread states and potential deadlocks.
- compare_thread_dumps: Parses two JVM thread dump text files and returns a comparison of thread state counts and deadlocks.
Prerequisites
- Python 3.9+
- pip (Python package installer)
Installation
Option 1: Clone and Build from Source (Recommended)
-
Clone the repository:
git clone https://github.com/rajendrag/jvm-heap-analyzer-mcp.git cd jvm-heap-analyzer-mcp -
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate -
Build the wheel:
pip install build python -m build -
Install the package:
pip install dist/heap_analyzer_mcp_server-0.1.0-py3-none-any.whl
Option 2: Development Installation
For development or if you want to modify the code:
git clone https://github.com/rajendrag/jvm-heap-analyzer-mcp.git
cd jvm-heap-analyzer-mcp
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -e .
Usage with MCP Clients
After installation, the server can be used with any MCP-compatible client. The console script heap-analyzer-mcp-server will be available in your PATH.
Claude Desktop Configuration
-
Locate your Claude Desktop config directory:
- macOS:
~/Library/Application Support/Claude/ - Windows:
%APPDATA%\Claude\
- macOS:
-
Create or edit the
claude_desktop_config.jsonfile:{ "mcpServers": { "heap-analyzer-mcp": { "command": "heap-analyzer-mcp-server", "args": [] } } } -
Restart Claude Desktop to load the new server configuration.
Generic MCP Client Configuration
For other MCP clients, use this configuration:
{
"name": "heap-analyzer-mcp",
"command": "heap-analyzer-mcp-server",
"args": [],
"env": {},
"timeout": 120000
}
Alternative: Using Python Module Directly
If you prefer not to use the console script:
{
"name": "heap-analyzer-mcp",
"command": "python",
"args": ["-m", "heap_analyzer_mcp"],
"env": {}
}
Testing the Server
You can test the server manually to ensure it's working:
# Test that the server starts without errors
echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}}' | heap-analyzer-mcp-server
# Test import functionality
python -c "from heap_analyzer_mcp.__main__ import main; print('✅ Server is working!')"
Available Tools
1. analyze_thread_dump
Analyzes a single JVM thread dump file.
Parameters:
path(required): Path to the thread dump text filemax_threads(optional): Maximum number of threads to analyze (default: 5000)
Example usage in MCP client:
{
"path": "/path/to/thread_dump.txt",
"max_threads": 5000
}
Example response:
{
"summary": "Analyzed 4 threads (limit 5000). States: RUNNABLE=2, WAITING=2",
"counts": {
"RUNNABLE": 2,
"WAITING": 2,
"BLOCKED": 0,
"TIMED_WAITING": 0,
"NEW": 0,
"TERMINATED": 0
},
"deadlocks": [
{
"threads": ["Thread-1", "Thread-2"],
"monitor": "java.lang.Object@12345"
}
]
}
2. compare_thread_dumps
Compares two JVM thread dump files and shows the differences.
Parameters:
path_a(required): Path to the first thread dump filepath_b(required): Path to the second thread dump filemax_threads(optional): Maximum number of threads to analyze (default: 5000)diff_mode(optional): Level of detail in comparison (default: "full")"summary": Returns only summary and notes"states": Returns summary, counts, and deltas"full": Returns all fields including deadlock details
Example usage in MCP client:
{
"path_a": "/path/to/dump1.txt",
"path_b": "/path/to/dump2.txt",
"diff_mode": "full",
"max_threads": 5000
}
Example response:
{
"summary": "State deltas: RUNNABLE=+1, WAITING=-1; Deadlocks present only in A",
"counts_a": {"RUNNABLE": 2, "WAITING": 2, "BLOCKED": 0, "TIMED_WAITING": 0, "NEW": 0, "TERMINATED": 0},
"counts_b": {"RUNNABLE": 3, "WAITING": 1, "BLOCKED": 0, "TIMED_WAITING": 0, "NEW": 0, "TERMINATED": 0},
"deltas": {"RUNNABLE": 1, "WAITING": -1, "BLOCKED": 0, "TIMED_WAITING": 0, "NEW": 0, "TERMINATED": 0},
"deadlocks_a": [{"threads": ["Thread-1", "Thread-2"], "monitor": "java.lang.Object@12345"}],
"deadlocks_b": [],
"notes": "Deadlocks present only in A"
}
Sample Thread Dumps
The repository includes sample thread dumps in the tests/ directory that you can use for testing:
tests/sample_thread_dump.txttests/sample_thread_dump_2.txt
Development and Testing
Running Tests
-
Install test dependencies:
pip install -e .[test] -
Run tests:
pytest -q
Alternative Testing (without MCP dependencies)
If you can't install MCP dependencies in your environment:
PYTHONPATH=src python3 -m pytest -q
This uses the tools adapter to test functionality without requiring the full MCP runtime.
Project Structure
jvm-heap-analyzer-mcp/
├── src/heap_analyzer_mcp/
│ ├── __init__.py
│ ├── __main__.py # MCP server and tool implementations
│ ├── parser.py # Core thread dump parsing logic
│ └── tools_adapter.py # MCP tool behavior for testing
├── tests/ # Test files and sample thread dumps
├── pyproject.toml # Package configuration
└── README.md # This file
Limitations and Notes
- File size limit: Thread dump files larger than 10MB are rejected for safety
- File access: Files must be accessible by the server process (consider file permissions)
- Thread limit: By default, analysis is limited to 5000 threads per dump
- Communication: The server uses stdio for communication with MCP clients
Troubleshooting
Server Won't Start
- Verify installation:
heap-analyzer-mcp-server --help - Check Python environment:
which pythonandwhich heap-analyzer-mcp-server - Try running directly:
python -m heap_analyzer_mcp
Client Can't Connect
- Ensure the server binary is in your PATH
- Verify the client configuration file syntax
- Check that the virtual environment is activated when starting the client
- Look at client logs for specific error messages
Permission Issues
- Ensure thread dump files are readable by the server process
- On Windows, you may need to use full paths in the configuration
Import Errors
- Verify all dependencies are installed:
pip list | grep mcp - Try reinstalling:
pip uninstall heap-analyzer-mcp-server && pip install dist/heap_analyzer_mcp_server-0.1.0-py3-none-any.whl
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
pytest - Submit a pull request
License
This project is open source. Please check the repository for license details.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。