Heap Seance MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add -e "JAVA_HOME=${JAVA_HOME}" -e "MAT_BIN=${MAT_BIN}" heap-seance -- uv run --directory /path/to/heap-seance python -m heap_seance_mcp.server
Required:JAVA_HOMEMAT_BIN+ 1 optional
README.md

Summoning retained objects from the heap to investigate memory leaks.

Heap Seance

Summoning retained objects from the heap — so you can interrogate what refuses to die.

An MCP server + CLI toolkit that channels the spirits of jcmd, jmap, jstat, jfr, Eclipse MAT, and async-profiler into a structured leak investigation workflow — designed to run inside Claude Code.

2 slash commands. 8 MCP tools. Conservative by default.


How It Works • Quick Start • MCP Tools • Workflow • Prerequisites • Contributing


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 steps

Confidence 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.

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.git

2. 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 PID

Heap Seance resolves the target process, collects evidence, and returns a structured verdict.

MCP Tools

Tool What it does
java_list_processes() Discover running JVMs via jcmd -l
java_class_histogram(pid) Snapshot live object counts per class
java_gc_snapshot(pid) Sample jstat -gcutil over time
java_jfr_start(pid) Capture a JFR recording
java_jfr_summary(jfr_file) Summarize JFR event types and counts
java_heap_dump(pid) Full heap dump (.hprof)
java_mat_suspects(heap_dump) Run MAT leak suspects analysis
java_async_alloc_profile(pid) 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

  1. Start your app and let it initialize fully.
  2. /leak-scan <name-or-pid> — takes the first histogram snapshot.
  3. Exercise the suspect behavior — the scan prompts you between each of

Tools (8)

java_list_processesDiscover running JVMs via jcmd -l
java_class_histogramSnapshot live object counts per class
java_gc_snapshotSample jstat -gcutil over time
java_jfr_startCapture a JFR recording
java_jfr_summarySummarize JFR event types and counts
java_heap_dumpFull heap dump (.hprof)
java_mat_suspectsRun MAT leak suspects analysis
java_async_alloc_profileAllocation flame graph via async-profiler

Environment Variables

JAVA_HOMErequiredPath to JDK 17+
MAT_BINrequiredPath to Eclipse MAT ParseHeapDump.sh
ASYNC_PROFILER_BINPath to async-profiler binary

Configuration

claude_desktop_config.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"}}}}

Try it

Run a leak scan on my Java service to check for monotonic growth.
Perform a deep leak investigation on PID 12345 including a heap dump and MAT analysis.
List all running JVM processes to identify the target for profiling.
Summarize the JFR recording located at /tmp/recording.jfr.

Frequently Asked Questions

What are the key features of Heap Seance?

Two-stage escalation model for conservative leak investigation. Structured confidence-based verdicts for memory leaks. Integration with standard Java tools like jcmd, jmap, and async-profiler. Automated MAT leak suspects analysis. Designed for seamless use within Claude Code.

What can I use Heap Seance for?

Investigating unexplained memory growth in production Java services. Automating the collection of heap dumps and JFR recordings during incident response. Correlating GC pressure snapshots with object allocation patterns. Validating memory leak fixes by comparing class histograms before and after changes.

How do I install Heap Seance?

Install Heap Seance by running: git clone https://github.com/SegfaultSorcerer/heap-seance.git

What MCP clients work with Heap Seance?

Heap Seance works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Heap Seance docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare