Native Java Model Context Protocol (MCP) server for live Spring Boot inspection via Attach API.
개요
Provide Claude, Cursor, and AI coding assistants with real-time runtime context on memory, threads, Spring beans, and database connection pools without modifying target application code. When debugging backend Java services with LLMs, static source code only tells half the story: 1. Deadlocks, thread starvation, and runaway thread allocations cannot be deduced purely from code syntax. 2. Memory leaks in Old Gen or sudden allocation spikes in Eden require live heap inspection. 3. Spring Boot bean initialization orders and active HikariCP pool saturation require dynamic runtime context. Existing tools require heavy external APM agents, modifying pom.xml files to expose open Actuator/JMX endpoints, or manually running jstack / jcmd in a terminal and copy-pasting megabytes of unformatted text into prompts. attaches locally to target JVM processes using the standard JDK Attach API (com.sun.tools.
README
JVM-MCP
Self-contained Java 21 Model Context Protocol (MCP) server with zero runtime framework overhead.
Provide Claude, Cursor, and AI coding assistants with real-time runtime context on memory, threads, Spring beans, and database connection pools without modifying target application code.
Table of Contents
- Why This Exists
- How It Works
- Quickstart: MCP Client Setup
- CLI Usage
- Exposed MCP Tools
- Architectural Principles
- Security & Defense Boundaries
- Platform & Runtime Compatibility Matrix
- Known Limitations and Trade-offs
- Contributing & Governance
- License
Why This Exists
When debugging backend Java services with LLMs, static source code only tells half the story:
- Deadlocks, thread starvation, and runaway thread allocations cannot be deduced purely from code syntax.
- Memory leaks in Old Gen or sudden allocation spikes in Eden require live heap inspection.
- Spring Boot bean initialization orders and active HikariCP pool saturation require dynamic runtime context.
Existing tools require heavy external APM agents, modifying pom.xml files to expose open Actuator/JMX endpoints, or manually running jstack / jcmd in a terminal and copy-pasting megabytes of unformatted text into prompts.
JVM-MCP attaches locally to target JVM processes using the standard JDK Attach API (com.sun.tools.attach), dynamically exposes diagnostic data over the standardized Model Context Protocol (JSON-RPC 2.0 stdio), and requires zero modifications to target applications.
How It Works
Distributed as a standalone multi-platform bundle with a stripped custom runtime via jlink/jpackage. No pre-installed JDK is required on the client machine.
+-----------------------------------------+
| Claude Desktop / Cursor / IDE |
+-----------------------------------------+
| JSON-RPC 2.0 (stdio)
v
+-----------------------------------------+
| jvm-mcp | (Virtual Threads, < 150ms cold start)
+-----------------------------------------+
| Attach API / Dynamic JMX
v
+-----------------------------------------+
| Target Java App (PID 45231) | (Zero modifications or dependencies)
+-----------------------------------------+
Installation
Pre-built standalone distributions include a minimal modular JRE via jlink (Linux/macOS) and jpackage (Windows). No pre-installed JDK is required on the host system.
One-Line Universal Installer (Linux & macOS)
curl -fsSL https://raw.githubusercontent.com/oscarbol09/jvm-mcp/main/install.sh | bash
The script automatically detects your platform architecture (linux-amd64, linux-aarch64, macos-aarch64, macos-amd64), verifies the cryptographic SHA-256 checksum against the release manifest, and unpacks jvm-mcp into ~/.local/bin.
Homebrew (macOS & Linux)
brew install oscarbol09/tap/jvm-mcp
Pre-Compiled Standalone Archives
Download release packages and corresponding .sha256 checksums from GitHub Releases:
| Platform / Architecture | Archive Name | Runtime Packaging |
|---|---|---|
| Linux (x86_64 / amd64) | jvm-mcp-linux-amd64.tar.gz |
Modular JRE (jlink) + symlink-safe launcher |
| Linux (ARM64 / aarch64) | jvm-mcp-linux-aarch64.tar.gz |
Modular JRE (jlink) + symlink-safe launcher |
| macOS (Apple Silicon ARM64) | jvm-mcp-macos-aarch64.tar.gz |
Modular JRE (jlink) + symlink-safe launcher |
| macOS (Intel x86_64) | jvm-mcp-macos-amd64.tar.gz |
Modular JRE (jlink) + symlink-safe launcher |
| Windows (x86_64 / amd64) | jvm-mcp-windows-amd64.zip |
Standalone application image (jpackage .exe) |
Verify checksum and unpack:
# Example for Linux
sha256sum -c jvm-mcp-linux-amd64.tar.gz.sha256
tar -xzf jvm-mcp-linux-amd64.tar.gz
./jvm-mcp --version
Building From Source
Requires JDK 21+ and Git:
git clone https://github.com/oscarbol09/jvm-mcp.git
cd jvm-mcp
./mvnw clean package -DskipTests
# Run the packaged fat JAR directly:
java -jar mcp-server/target/jvm-mcp-server-1.1.0-SNAPSHOT.jar --version
Quickstart: MCP Client Setup
Claude Desktop
Add jvm-mcp to your claude_desktop_config.json:
{
"mcpServers": {
"jvm-mcp": {
"command": "jvm-mcp",
"args": ["serve"]
}
}
}
(If running from the repository fat JAR directly: "command": "java", "args": ["-jar", "/path/to/jvm-mcp-server-1.1.0-SNAPSHOT.jar", "serve"])
Cursor / Windsurf
- Open Settings > Features > MCP.
- Click + Add New MCP Server.
- Name:
jvm-mcp - Type:
command - Command:
jvm-mcp serve
Once configured, ask your AI: “What Java processes are running?” or “Analyze the memory and detect deadlocks in PID 12345”.
CLI Usage
jvm-mcp doubles as a standalone diagnostic terminal CLI for local inspection:
# Verify local environment readiness and Attach API permissions
jvm-mcp doctor
# Discover running Java processes and frameworks
jvm-mcp list
# Inspect memory pools, GC pauses, and heap histogram
jvm-mcp memory
# Diagnose thread states and detect deadlock cycles
jvm-mcp threads
# Inspect Spring Boot ApplicationContext beans
jvm-mcp beans --filter "*Service*"
# Introspect PostgreSQL schema and find missing indexes via JDBC
jvm-mcp pg --url "jdbc:postgresql://localhost:5432/mydb" --missing-indexes
# Query remote Spring Boot Actuator endpoints
jvm-mcp actuator --url "http://localhost:8080" --metrics
Exposed MCP Tools
The server exposes 14 diagnostic tools to AI assistants:
| Tool Name | Description | Arguments |
|---|---|---|
list_jvms |
Lists running JVMs with PID, display name, and detected framework (Spring Boot, Quarkus, Micronaut). | None |
get_memory_summary |
Live heap/non-heap regions, GC pauses, and memory pressure. | pid (number) |
get_heap_histogram |
Top class instance counts and memory consumption via jcmd. |
pid (number), limit (number, optional) |
get_thread_diagnostics |
Thread states breakdown and deadlock detection (inspects platform and mounted virtual threads; unmounted virtual threads tracked in #10). | pid (number) |
get_thread_dump |
Full formatted thread dump with lock stack traces. | pid (number) |
list_spring_beans |
Instantiated beans in Spring ApplicationContext via JMX/Actuator. | pid (number), filter (string, optional) |
get_bean_detail |
Detailed metadata, autowired dependencies, and scope of a bean. | pid (number), beanName (string) |
list_hikari_pools |
HikariCP pool metrics, active/idle connections, and leak warnings. | pid (number) |
inspect_pg_schema |
PostgreSQL table schema, columns, row estimates, and foreign keys. | url (string), schema (string, optional) |
find_missing_indexes |
High sequential scan tables with low index usage via pg_stat_user_tables. |
url (string), schema (string, optional) |
find_slow_queries |
Slow query execution profiles from pg_stat_statements. |
url (string) |
get_actuator_health |
Recursively parsed Spring Boot /actuator/health component status. |
url (string) |
get_actuator_metrics |
Batch or individual diagnostic metric values from /actuator/metrics. |
url (string), metrics (string, optional) |
get_actuator_startup |
Startup timeline and slowest beans from /actuator/startup. |
url (string) |
Architectural Principles
- Virtual Threads & Thread-Safe Stdio: Each incoming JSON-RPC request executes on a dedicated Java 21 Virtual Thread (
Executors.newVirtualThreadPerTaskExecutor()). Outboundstdoutwrites are synchronized on a dedicated monitor lock to prevent frame interleaving. - Dynamic JDK Management Agent: JMX access is initialized dynamically via
VirtualMachine.startLocalManagementAgent(), falling back to standard$JAVA_HOME/lib/management-agent.jar. No custom agent bytecode is injected into target processes. - Zero Runtime Framework Overhead: Operates with no heavy web or application frameworks (no Spring Boot runtime, Quarkus, Netty, Jackson, or reactive engines). It uses a lightweight custom JSON-RPC engine (
SimpleJson), native JDKHttpClient, and Picocli for CLI execution, ensuring a cold start under 150ms.
Security & Defense Boundaries
- OS Process Boundary & Privileged Access Control: Enforces numeric PID validation (> 0), process liveness checks, and OS user matching (
ProcessHandle.info().user()). Cross-user attachment without operating system elevation is strictly rejected. - Automatic Sensitive Data Redaction: All diagnostic tool outputs and execution error messages returned over MCP are filtered through
SensitiveDataRedactorto sanitize Bearer tokens, Basic credentials, passwords, API keys, embedded JDBC passwords, and JWTs. - Actuator SSRF & Path Traversal Mitigation: Enforces strict
http/httpsscheme validation, disables HTTP redirect following (followRedirects: NEVER) to eliminate cloud metadata/internal network pivoting, and rejects directory traversal in endpoints. - PostgreSQL JDBC Hardening & Schema Validation: Enforces
jdbc:postgresql://protocol, validates loopback resolution, strips unsafe driver properties (socketFactory,sslrootcert,options), and validates schema names against standard SQL identifier patterns to prevent SQL injection. - Resource Bounding & Execution Timeouts: Heap histograms are bounded between 50 and 1,000 entries (capped at 100k lines), arguments are bounded via
ToolArgs, and all tool invocations execute with an enforced 15-second virtual thread timeout. - ReDoS & Recursion Guards: Sanitizes glob wildcards in
GlobMatcherto prevent quadratic backtracking and boundsSimpleJsonrecursion depth to 100.
Platform & Runtime Compatibility Matrix
| Runtime Environment | Architecture / Vendor | Status | Operational Notes |
|---|---|---|---|
| Linux | x86_64, aarch64 | Supported | Standard HotSpot Attach API. If yama/ptrace_scope is >= 1, non-child attach requires matching UID or CAP_SYS_PTRACE. |
| macOS | Apple Silicon (aarch64), Intel (x86_64) | Supported | Native jlink minimal runtime distribution. |
| Windows | x86_64 | Supported | Self-contained .exe image via jpackage. |
| OpenJDK / HotSpot | Temurin, Corretto, Zulu, Oracle, Liberica | Full Support | Standard jdk.attach implementation with dynamic local management agent. |
| IBM Semeru / OpenJ9 | OpenJ9 / IBM J9 | Experimental | OpenJ9 uses com.ibm.tools.attach. Use Actuator HTTP mode if Attach API fails. |
| Docker Containers | Isolated namespaces | Conditional | Cross-namespace attach requires --pid=host or running jvm-mcp inside the container. Alternatively use Actuator mode. |
Known Limitations and Trade-offs
- Container Boundaries: Direct host attachment across isolated Docker container namespaces fails due to separate PID and IPC namespaces. Attach from within the container namespace, use
--pid=host, or use Actuator HTTP mode (jvm-mcp actuator --url ...). - Virtual Threads Visibility (Project Loom): Current thread diagnostics leverage the standard JVM
ThreadMXBean. In Java 21, unmounted virtual threads resting in continuation queues are not surfaced byThreadMXBean. Comprehensive virtual thread inspection using HotSpot thread dumps / JVMTI is tracked under issue #10. - Jlink / Jpackage Bundling: GraalVM Native Image was evaluated and rejected because
jdk.attachdynamically loads HotSpot C++ native libraries (libattach.so/attach.dll), violating Closed-World AOT assumptions. We distribute minimal bundles containing a stripped modular JRE viajlink(Linux/macOS) andjpackageapp images (Windows), maintaining cross-platform parity with startup times under 150ms.
Contributing & Governance
- ROADMAP.md: Milestones and active development phases.
- CONTRIBUTING.md: Local environment setup, module architecture, and guide for adding MCP tools.
- SECURITY.md: Vulnerability reporting policy and defense boundaries.
- CODE_OF_CONDUCT.md: Community standards (Contributor Covenant).
License
This project is licensed under the terms of the MIT License. See the LICENSE file for details.
Copyright © 2026 oscarbol09 / JVM-MCP Contributors.
설치
This server does not publish a one-line install command.
Open the repository installation guide설정
{
"mcpServers": {
"jvm-mcp": {
"command": "jvm-mcp",
"args": ["serve"]
}
}
}