java-heap-mcp is a Java MCP server for loading and analyzing Java heap dumps with Eclipse Memory Analyzer (MAT) components. It exposes focused MCP tools for dump lifecycle, OQL/SQL, histograms, dominators, object inspection, GC-root paths, and leak-suspect analysis.
The server speaks MCP over stdio, so it can be registered directly with the local Codex CLI. From the repository root, run:
codex mcp add javaHeapMcp -- /absolute/path/to/java-heap-mcp/scripts/run-server.shUse the real absolute path to this repository. Verify the registration with codex mcp list, then start a new Codex session if needed. Codex can use the heap tools through stdio; the workbench uses the same server's optional HTTP API instead.
The equivalent ~/.codex/config.toml entry is:
[mcp_servers.javaHeapMcp]
command = "/absolute/path/to/java-heap-mcp/scripts/run-server.sh"
args = []If the server is not executable, run chmod +x scripts/run-server.sh once. The server writes diagnostics to stderr and keeps protocol responses on stdout.
- Java 25+ Maven project
- Long-lived multi-dump cache with stable dump handles
- Service-managed cache under
~/.cache/java-heap-mcpby default - Named project workflow (each project tracks its cached heap dump + active handle)
- MAT plugin jars downloaded from the official Eclipse distribution during the Maven build
- Headless Apache Calcite heap schema embedded from
mat-calcite-plugin - Official MCP Java SDK server with stdio transport and tool/schema negotiation
- Optional built-in web UI for local loading and analysis
- Project principles and quality gates are defined in
.specify/memory/constitution.md. - Feature specs, plans, and tasks are expected to align with those constitution requirements.
heap_load_dumpheap_open_projectheap_list_projectsheap_list_dumpsheap_unload_dumpheap_get_overviewheap_run_oqlheap_get_oql_grammar(no heap handle required; returns the supported Calcite SQL grammar, heap schema, functions, and examples)heap_get_histogramheap_get_dominatorsheap_inspect_objectheap_find_path_to_gc_rootsheap_find_leak_suspects
mvn -Dmaven.repo.local=.m2 test./scripts/run-server.shEnvironment variables:
JAVA_HEAP_MCP_CACHE_DIRJAVA_HEAP_MCP_DEFAULT_LIMITJAVA_HEAP_MCP_MAX_LIMITJAVA_HEAP_MCP_TOOL_TIMEOUT_SECONDSJAVA_HEAP_MCP_GC_ROOT_PATH_LIMITJAVA_HEAP_MCP_WEB_UI_ENABLED(true/false, defaultfalse)JAVA_HEAP_MCP_WEB_UI_PORT(default7777)JAVA_HEAP_MCP_WEB_UI_MAX_UPLOAD_BYTES(default0= unlimited)
To enable the web UI:
JAVA_HEAP_MCP_WEB_UI_ENABLED=true JAVA_HEAP_MCP_WEB_UI_PORT=7777 ./scripts/run-server.shThen open: http://127.0.0.1:7777/
The HTTP API includes CORS headers and browser preflight support so the separate java-heap-workbench dev server can connect from http://127.0.0.1:4173.
If MAT reports NoClassDefFoundError: Could not initialize class for QueryRegistry or Icons, stop and restart the MCP server after any runtime/classpath change. These are JVM-level class-initialization failures and cannot be repaired by refreshing the browser.
heap_run_oql first executes queries through the embedded Calcite engine. This enables SQL joins, filters, grouping, ordering, lateral table functions, and MAT-aware functions such as retainedSize, shallowSize, getField, getValues, and getMapEntries. For example:
select toString(file) as file_name, count(*) as count
from java.net.URL
group by toString(file)
order by count(*) descCalcite uses double-quoted identifiers for fully qualified Java class names when needed (for example, from "java.util.HashMap"). Existing MAT OQL remains supported as a fallback. OQL diagnostics are written to the MCP process stderr. Each request logs the normalized single-line query plus its limit and offset; parse/runtime failures log the same query with the full exception.
Agents can call heap_get_oql_grammar before writing a query. The same read-only description is available from the HTTP API at GET /api/oql-grammar (also GET /api/oql/grammar). It describes the server's one-SELECT contract, the MAT Calcite heap schema, reference/table/collection functions, and working examples. The payload links to the Apache Calcite SQL reference and MAT Calcite plugin for complete background.
- Load a heap into a named project:
- MCP:
heap_load_dumpwith{ "project": "my-service", "path": "/abs/path/dump.hprof" } - Web UI: choose the
.hproffile with the browser file picker and click Load - If no project is supplied, the service assigns a short Docker-style name such as
calm_tesla.
- MCP:
- Re-open an existing cached project:
- MCP:
heap_open_projectwith{ "project": "my-service" }
- MCP:
- List projects and active handles:
- MCP:
heap_list_projects
- MCP:
- Analyze with overview, dominators, leak suspects, histogram, and OQL using the returned handle.
- MAT is downloaded and unpacked into
target/mat/by Maven because the bundles are published through Eclipse update-site/RCP distribution artifacts rather than Maven Central. - Web UI uploads are streamed directly to disk in fixed-size chunks before indexing/load (not buffered fully in memory).
- The current automated tests cover cache metadata, fingerprinting, and manager/tooling behavior. End-to-end MAT integration tests against real HPROF dumps are the next step.
- Eclipse Memory Analyzer (MAT) JARs are build outputs under
target/mat/and are not stored in source control. - Third-party licensing details are documented in
THIRD_PARTY_NOTICES.md. - Included license texts are in
licenses/:licenses/EPL-2.0.txtlicenses/MIT-DEFLATE.txt