heap-seance
Heap Seance is an MCP server and CLI toolkit for Java memory leak investigation, offering a two-stage escalation model with structured forensic workflows.
Two Main Workflows:
/leak-scan— Conservative mode: takes 3 class histogram snapshots and GC pressure analysis, returning a verdict with confidence level and recommended next steps/leak-deep— Full forensics mode: escalates from/leak-scanby adding JFR recordings, heap dumps, MAT leak analysis, and async-profiler allocation profiling to produce a root holder hypothesis and remediation suggestions
Individual Capabilities:
Discover JVM processes (
java_list_processes): List all running JVMs viajcmd -lto identify investigation targetsCapture class histograms (
java_class_histogram): Snapshot live object counts/sizes per class to detect monotonically growing typesMonitor GC pressure (
java_gc_snapshot): Samplejstat -gcutilover time to assess old-gen usage and GC strainStart JFR recordings (
java_jfr_start): Capture Java Flight Recorder data with configurable duration/profileSummarize JFR files (
java_jfr_summary): Parse.jfrfiles to extract event types and countsGenerate heap dumps (
java_heap_dump): Produce.hproffiles for offline memory forensicsRun MAT analysis (
java_mat_suspects): Execute Eclipse MAT on heap dumps to identify leak suspects, dominator trees, and retention chainsProfile allocations (
java_async_alloc_profile): Generate async-profiler flame graphs showing which call paths drive the most allocations
All tools return a unified schema including status, evidence, metrics, a confidence level (none/low/medium/high), next recommended action, and paths to saved artifacts (.jfr, .hprof, MAT reports).
Supports Java 8+ targets (full support for Java 8; additional JFR features for Java 9+), integrates with Claude Code via slash commands, and can run standalone via CLI.
How It Works
Heap Seance follows a two-stage escalation model. No deep forensics unless the evidence demands it.
/leak-scan /leak-deep
| |
v v
3x class histogram (all of scan, plus)
+ GC pressure snapshot JFR recording
| heap dump
v MAT leak suspects
monotonic growth? async-profiler alloc profile
old-gen pressure? |
| v
+--- both true? -----> auto-escalate to deep
|
+--- otherwise ------> verdict + next stepsConfidence is earned, not assumed. high requires at least two independent strong signals. A single growing class is watch. Growth plus GC pressure is suspicious. Add a MAT dominator or JFR correlation and you get probable_memory_leak.
Related MCP server: javaperf
Quick Start
Requires uv, Python 3.10+, and a JDK 17+ for tooling (the target app can run any Java version).
1. Clone
git clone https://github.com/your-org/heap-seance.git2. Add .mcp.json to your Java project
In the project you want to investigate, create a .mcp.json:
{
"mcpServers": {
"heap-seance": {
"command": "uv",
"args": ["run", "--directory", "/path/to/heap-seance", "python", "-m", "heap_seance_mcp.server"],
"env": {
"JAVA_HOME": "/path/to/jdk-17",
"MAT_BIN": "/path/to/ParseHeapDump.sh",
"ASYNC_PROFILER_BIN": "/path/to/asprof"
}
}
}
}--directory points to where you cloned Heap Seance. uv run handles the virtual environment and dependencies automatically. ASYNC_PROFILER_BIN is optional — if missing, deep mode continues with JFR + MAT.
3. Copy the Claude Code commands
Copy the .claude/commands/ folder into your Java project so the /leak-scan and /leak-deep slash commands are available:
cp -r /path/to/heap-seance/.claude/commands/ .claude/commands/4. Run
/leak-scan my-service # conservative scan
/leak-deep 12345 # full forensics by PIDHeap Seance resolves the target process, collects evidence, and returns a structured verdict.
MCP Tools
Tool | What it does |
| Discover running JVMs via |
| Snapshot live object counts per class |
| Sample |
| Capture a JFR recording |
| Summarize JFR event types and counts |
| Full heap dump ( |
| Run MAT leak suspects analysis |
| Allocation flame graph via async-profiler |
Every tool returns the same unified schema:
{
"status": "ok | warn | error",
"evidence": ["..."],
"metrics": {},
"confidence": "none | low | medium | high",
"next_recommended_action": "...",
"raw_artifact_path": "..."
}Investigation Workflow
Start your app and let it initialize fully.
/leak-scan <name-or-pid>— takes the first histogram snapshot.Exercise the suspect behavior — the scan prompts you between each of the 3 histogram samples to perform the action you suspect is leaking (open/close views, send requests, repeat workflows). This is critical — without load between samples, leaks stay invisible.
Read the verdict. Focus on
Confidence,Key Evidence,Suspect Types./leak-deep <name-or-pid>if the scan flags growth, or if you want full forensics regardless.Fix and re-scan. Bounded caches, weak refs, listener cleanup — then
/leak-scanagain to confirm the signal drops.Keep artifacts.
.jfr,.hprof, and MAT reports are saved for team review.
What you get back
/leak-scan returns: Verdict, Confidence, Key Evidence, Suspect Types, Artifacts, Next Steps.
/leak-deep goes further: Verdict, Confidence, Root Holder Hypothesis (who retains the growing objects and via which field/chain), Supporting Evidence, Artifacts, Remediation Hypotheses (concrete fix suggestions), Verification Plan.
Confidence ladder
Confidence | What it means | Signals required |
| No leak evidence | — |
| Weak growth, no GC pressure | histogram only |
| Growth + GC is losing | histogram + GC pressure |
| Probable leak, corroborated | histogram + GC + MAT/JFR |
Prerequisites
Tooling JDK (required):
JDK 17+ for
jcmd,jmap,jstat— set viaJAVA_HOMEin.mcp.jsonThe target application can run any Java version (including Java 8)
Deep forensics (for /leak-deep):
Eclipse MAT CLI (
ParseHeapDump.sh/.bat) — required for deep modeasync-profiler — optional tie-breaker
Optional tools:
jfrCLI — used for JFR summary if available, falls back tojcmd JFR.viewotherwise. JFR is skipped entirely for Java 8 targets (incompatible format).
Check your setup:
./scripts/check_prereqs.sh # macOS / Linux
scripts\check_prereqs.bat # WindowsEnvironment overrides
Set these in your .mcp.json env block (recommended) or as shell variables:
Variable | Required | Description |
| recommended | JDK 17+ installation path — |
| for deep mode | Path to |
| optional | Path to async-profiler binary — tie-breaker evidence, deep mode works without it |
| optional | Where |
| optional | Transport protocol: |
| optional | Bind address for SSE/HTTP transport (default: |
| optional | Port for SSE/HTTP transport (default: |
CLI flags --sse and --streamable-http can be used instead of MCP_TRANSPORT.
See .mcp.json.example for a full config template.
Compatibility notes
Java 8 targets: histogram + GC + MAT work fully. JFR is skipped (v0.9 format incompatible with modern tools).
Windows: MAT works via
ParseHeapDump.bat. async-profiler is optional — if missing, deep mode continues with JFR + MAT. Locale-specific decimal separators (comma vs dot) injstatoutput are handled automatically.MAT + JAVA_HOME: MAT is launched with the JDK from
JAVA_HOME, so it works even if the system default Java is too old for MAT.
CLI Usage (without Claude Code)
uv run heap-seance --mode scan --match your-app
uv run heap-seance --mode deep --pid 12345 --output json# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"python3 -m venv .venv
source .venv/bin/activate # Windows: .\.venv\Scripts\Activate.ps1
pip install -e .
heap-seance --mode scan --match your-appTests
python3 -m unittest discover -s tests -p "test_*.py"Example Java scenarios for validation live in examples/java-scenarios/ — a real leak, a bounded cache (no leak), and a burst allocator (no leak).
Contributing
Contributions welcome! See CONTRIBUTING.md for guidelines on adding tools, signals, and skills.
License
This project is dual-licensed under either of
at your option.
Available Tools
8 toolsjava_async_alloc_profileD
| Name | Required | Description | Default |
|---|---|---|---|
| pid | Yes | ||
| duration_s | No | ||
| out_file | No |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
java_class_histogramD
| Name | Required | Description | Default |
|---|---|---|---|
| pid | Yes | ||
| live_only | No |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
java_gc_snapshotD
| Name | Required | Description | Default |
|---|---|---|---|
| pid | Yes | ||
| interval_s | No | ||
| samples | No |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
java_heap_dumpD
| Name | Required | Description | Default |
|---|---|---|---|
| pid | Yes | ||
| live_only | No | ||
| out_file | No |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
java_jfr_startD
| Name | Required | Description | Default |
|---|---|---|---|
| pid | Yes | ||
| profile | No | profile | |
| duration_s | No | ||
| out_file | No |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
java_jfr_summaryD
| Name | Required | Description | Default |
|---|---|---|---|
| jfr_file | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
java_list_processesD
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
java_mat_suspectsD
| Name | Required | Description | Default |
|---|---|---|---|
| heap_dump_file | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
No output parameters | ||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Tool has no description.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
Tool has no description.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Tool has no description.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Tool has no description.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
Tool has no description.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
Tool has no description.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
8 tool updates
v1.0.0- First observed
java_async_alloc_profile - First observed
java_class_histogram - First observed
java_gc_snapshot - First observed
java_heap_dump - First observed
java_jfr_start - First observed
java_jfr_summary - First observed
java_list_processes - First observed
java_mat_suspects
TDQS
Scored across 8 tools
Tools cover distinct diagnostic actions—process listing, heap dump, class histogram, MAT suspects, JFR start/summary, GC snapshot, allocation profile—so an agent can usually pick based on the futored operation. Minor proximity exists between heap_dump and class_histogram, but names plus conceptual roles keep them separate.
All names share the java_ prefix and snake_case, which helps. However, the verb placement is inconsistent: list_processes and jfr_start use a verb, while mat_suspects, class_histogram, and gc_snapshot are pure noun phrases without an obvious action word.
Eight tools is well within the ideal range for a focused Java diagnostics server. Each tool covers a distinct diagnostic technique (JFR, heap analysis, allocation profiling, GC snapshots), and none feel redundant or extraneous.
The server covers the core heap and JFR workflows: process discovery, heap dumps, class histograms, MAT suspect analysis, and JFR capture/summarization. The main gap is the lack of a JFR stop or thread dump tool, but agents can still achieve the primary diagnosis goals.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
MCP server for progressive tool usage at any scale (see https://klavis.ai)
Augments MCP Server - A comprehensive framework documentation provider for Claude Code
Repository knowledge graph MCP server for codebase understanding and debugging.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceJava diagnostics MCP server for LLM integration with Alibaba Arthas, enabling analysis and diagnosis of Java applications.56MIT
- AlicenseAqualityDmaintenanceMCP 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.262610MIT
- AlicenseNot gradedqualityCmaintenanceToken-efficient MCP server for multi-language project analysis (Java, TypeScript, JavaScript, Markdown, Python) with plugins, semantic search, and static analysis.MIT
- AlicenseNot gradedqualityDmaintenanceThis MCP server connects Claude Desktop to a Velociraptor instance and local forensic tools. It enables remote endpoint investigation and local evidence analysis through natural language commands.1MIT