Skip to main content
Glama
README.md
# jvmsrc — Give your coding agent a Java IDE

<div align="center">

[![CI](https://github.com/Sintexer/jvmsrc/actions/workflows/ci.yml/badge.svg)](https://github.com/Sintexer/jvmsrc/actions/workflows/ci.yml)
[![npm version](https://img.shields.io/npm/v/jvmsrc)](https://www.npmjs.com/package/jvmsrc)
[![License: MIT](https://img.shields.io/github/license/Sintexer/jvmsrc)](https://github.com/Sintexer/jvmsrc/blob/master/LICENSE)
[![Node](https://img.shields.io/node/v/jvmsrc)](https://www.npmjs.com/package/jvmsrc)

**An MCP server and CLI** that gives your coding agent the one thing it is missing on JVM codebases: **the actual classpath**.

</div>

Your IDE knows which library version your build uses. Your coding agent does not. It guesses from `~/.gradle/caches` or `~/.m2` and often reads the wrong JAR.
`jvmsrc` asks your build tool (**Gradle** and **Maven**) for the resolved classpath. Then it gives the agent **real source**, **real signatures** and **real structure** for the exact version in use.

---

## Quick Start

Requires **Node ≥ 20** and **Java on `PATH`** (for the CFR decompiler and `javap`).

**Only step 1 is required.** When your client connects, `jvmsrc` sends MCP instructions that tell your agent when and how to use its tools. No project rule or hook is needed.

### 1. Add the MCP server — run in your terminal

```bash
claude mcp add jvmsrc -- npx -y jvmsrc mcp
```

<details>
<summary><strong>Other clients (Cursor, Windsurf, VS Code, any MCP host)</strong></summary>

Add this to the MCP config of your client, then restart the client:

```json
{
  "mcpServers": {
    "jvmsrc": {
      "command": "npx",
      "args": ["-y", "jvmsrc", "mcp"]
    }
  }
}
```

VS Code (`mcp.json`) uses the key `servers` instead of `mcpServers`.

To install the CLI globally, run `npm install -g jvmsrc`. Then use `"command": "jvmsrc"` and `"args": ["mcp"]`.
`jvmsrc config` prints a paste-ready block with environment hints.

</details>

### 2. Optional: check the connection in your agent chat

> *"Use jvmsrc: which methods does `<a library class from your project>` declare?"*

The first call runs Gradle (about 5–10 s). Later calls use the cache.

### 3. Optional: add a project rule

Skip this step if your agent uses `jvmsrc` for dependency questions. If it keeps reaching for `javap` instead, you can add this reminder to `CLAUDE.md`, `AGENTS.md` or your Cursor rules:

```markdown
## Dependencies (jvmsrc)
For any question about a third-party library class, method or version, use the jvmsrc MCP tools
(search_classes → get_class_structure → get_class_source with methodNames; resolve_dependencies for versions).
When working inside one module, pass modulePath (':app' or the file you are editing) to get that module's versions.
Never use javap, unzip/jar on JARs, or ~/.gradle/caches. Code under this repo's src/ → grep/read as usual.
```

Details, and an optional Claude Code hook that blocks the shell fallbacks: [Make your agent use it](#make-your-agent-use-it).

<p align="center">
  <img src="docs/assets/jvmsrc-demo.gif" alt="jvmsrc resolving a Spring class in Claude Code" width="100%" />
  <br />
  <em>Claude Code resolving HandlerInterceptor signatures via jvmsrc — 3 calls, correct answer, no cache walking.</em>
</p>

---

## Why jvmsrc

Question: *"Does `AbstractTradingService` have a public helper we can reuse in our override?"* (a private library, no public Javadoc)

| | Without `jvmsrc` | With `jvmsrc` |
|:---|:---|:---|
| **Agent turns** | ~25 | 3 |
| **How it works** | `find ~/.gradle`, then `jar tf` and `javap` on a JAR it picked by guess | `search_classes` → `get_class_structure` → `get_method_signature` |
| **Version used** | Wrong (`2.4.1`, the project uses `3.0.0-SNAPSHOT`) | The one Gradle resolved |
| **Result** | "No helper exists, write your own" | Finds `maskSensitiveFields()`, correct override on the first try |

Typical result on JVM projects with private libraries (author's own use, not a benchmark):

* About **50K tokens saved** per "what is on this external class" question.
* Far fewer agent loops that walk Gradle caches, open wrong JARs or give up.
* Tasks that touch internal SDKs become safe to delegate.

### How it works

1. **Build tool query:** `jvmsrc` asks your build tool (Gradle) for the exact resolved classpath.
2. **Cache:** it caches the result and watches your build files, so the data stays current.
3. **Small tools:** it exposes precise tools (signatures, structure, search) instead of full-source dumps. Context stays small.

---

## Tools your agent gets

The MCP server runs over stdio (`jvmsrc mcp`). It needs no environment variables by default.

| Tool | What it does |
|:---|:---|
| **`search_classes`** | Find a class by simple name or glob; returns compact FQN + lib name lists |
| **`find_subtypes`** | Pass `typeName` to find implementing classes (not subinterfaces) or subclasses on the selected classpath. Set `directOnly: true` for immediate matches. |
| **`get_class_structure`** | Retrieves class overview (purpose + method names) or declared signatures |
| **`get_package_docs`** | Reads an exact package's description and type summaries from source, filling gaps from the dependency's matching Javadoc JAR. Lists each contributing module or JAR separately. |
| **`get_method_signature`**| Fetches real overloads for a method, with parameter names and generics |
| **`find_in_class_source`**| Greps one known class's source for a string or identifier (literal; regex optional) |
| **`get_class_source`** | Retrieves method bodies or line ranges (used as a last resort) |
| **`search_in_artifact`** | Greps text across all classes in one resolved dependency JAR; `docs: true` searches the class pages of its Javadoc JAR instead |
| **`resolve_dependencies`**| Analyzes the actual dependency graph this project uses |

If a dependency publishes Javadoc but no usable source file, `get_class_structure` and `get_method_signature` can still show its class description and documented overloads. Prose from the Javadoc JAR is labelled `docsSource: "javadoc-jar"`. Signatures still come from bytecode (`sourceAvailable: false`); use `bytecodeOnly: true` on a signature lookup to skip docs entirely.

For example, ask: *Which classes on `:app`'s classpath implement `org.springframework.retry.RetryPolicy`?* Hierarchy lookup reads dependency JARs and existing compiled module output. It does not compile your project or search uncompiled source files.

> [!TIP]
> Every source response includes `sourceAvailable`: `true` for real sources (Javadoc, parameter names, generics), `false` for CFR decompilation (structure reliable, names may be synthetic). Nested types (`Outer$Inner`, including `ImmutableList.Builder`) return structure, signatures, method excerpts, and decompiled source from the enclosing type.

> [!NOTE]
> **Multimodule:** omit `modulePath` and jvmsrc auto-picks the unique owning module; on a miss it lists candidate `modulePath`s. **Methods:** `search_classes` matches declared method names when the index has source enrichment; for body text in a known JAR use `search_in_artifact`. `get_class_source` `methodNames` also walks superclasses for unmatched names.

> [!NOTE]
> **Inputs are forgiving.** `projectRoot` can be omitted (the workspace is used, or set `JVMSRC_PROJECT_ROOT`); `modulePath` accepts `app`, `/app`, `:app`, or a file/directory inside the module (omit it, or pass `"*"`, to search all modules; a file under `src/test/` also selects the test classpath); `className` accepts a simple name, `Outer.Inner`, or a trailing `.class`/`.java`. When jvmsrc reinterprets an input (simple name to FQN, subdirectory to Gradle root), the result ends with a `note:` line. Pass `forceRefresh: true` only after something changed that the build files do not show, such as a SNAPSHOT republish. To save tokens on every turn, `projectRoot`, `configuration` and `forceRefresh` (except on `resolve_dependencies`) are accepted but not listed in the tool schemas.

### Private repository credentials (optional)

Only needed when your Gradle build requires credential env vars for a private Maven/Artifactory/Nexus-style repo. MCP hosts often do **not** inherit your interactive shell, so set those vars on the **jvmsrc MCP process** (then restart the server).

`REPO_USER` / `REPO_PASS` below are **sample names only** — jvmsrc does not require them. Use the variable names your Gradle scripts document:

```json
{
  "mcpServers": {
    "jvmsrc": {
      "command": "jvmsrc",
      "args": ["mcp"],
      "env": {
        "REPO_USER": "your-username",
        "REPO_PASS": "your-password"
      }
    }
  }
}
```

Omit the `env` block when the project does not need it.

---

## Make your agent use it

If your client does not pass MCP server instructions to the agent, or you want to enforce a project policy, either option below can help. Both are optional.

**1. Rule in the agent instructions.** Use the [optional project rule](#3-optional-add-a-project-rule) as a reminder.

**2. (Claude Code) Hook that blocks shell fallbacks.** [`docs/hooks/block-jvm-fallbacks.mjs`](docs/hooks/block-jvm-fallbacks.mjs) denies `javap`, `unzip`/`jar` on JARs, and `~/.gradle/caches` / `~/.m2` access. It tells the agent to use `jvmsrc` instead. Save the script in a stable place. Add this to `.claude/settings.json` (project) or `~/.claude/settings.json` (all projects):

```json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{ "type": "command", "command": "node /absolute/path/to/block-jvm-fallbacks.mjs" }]
      }
    ]
  }
}
```

Set `JVMSRC_HOOK_DISABLE=1` to switch it off for a while. Other clients have their own hook systems; read their current docs before you port it.

To check whether your client passes along the server instructions, ask the agent *"What instructions does the jvmsrc MCP server give?"*

---

## How It Compares

| Tool | Approach | Gap |
| :--- | :--- | :--- |
| **Cache Indexers** / `~/.gradle` grep | Scan global caches | No per-project resolved version |
| **Static Parsers** (e.g., `build.gradle` parser) | Parse declarations only | Misses transitive dependencies, BOMs, dynamic versions |
| **`mcp-javadoc`** / path-only CFR | User supplies manual JAR paths | No automatic build/classpath resolution |
| **Gradle MCP** (Tooling API) | Task/build focused | Not optimized for classpath-accurate FQN source lookup |
| **`jvmsrc`** | **Queries actual build tool & caches** | **Version-correct sources and signatures for agents** |

---

## Target Audience

Primarily **Java + Spring Boot** projects on **Gradle** and **Maven**. Other JVM languages (Kotlin, Scala, Groovy) work today — see [PLAN.md](PLAN.md).

---

## Detailed Reference

<details>
<summary>Requirements & Compatibility</summary>

**Runtime:** Node.js ≥ 20, Java on `PATH`.

**Project types:** JVM codebases (Java, Kotlin, Scala, Groovy). `jvmsrc` calls the build tool, not your editor.

| Build system | Status |
|---|---|
| **Gradle** | Supported — multimodule included |
| **Maven** | Supported — multimodule reactor, nearest-wins conflict resolution, `system` scope, sources JARs + CFR |
| Bazel | Planned ([SPEC.md](SPEC.md)) |

`-p` / `projectRoot` can be the build root or any directory inside it; jvmsrc walks up to the Gradle root (`gradlew` / `settings.gradle(.kts)`) or Maven reactor root (`pom.xml`); the nearest root wins. MCP tools can omit `projectRoot`, and the CLI can omit `-p` (it uses `JVMSRC_PROJECT_ROOT`, else the build that contains the working directory). Uses `./gradlew` / `./mvnw` when present, else `gradle` / `mvn`.

</details>

<details>
<summary>Known Limitations</summary>

Early software; the supported path is narrow:

| Area | Today |
|---|---|
| Build tool | **Gradle** and **Maven** (single-module and multi-module reactors) |
| Integration | Bundled **Gradle init script** (`--init-script`) and **Maven core extension** (`-Dmaven.ext.class.path`) — zero project mutation |
| Classpaths | Standard JVM + Kotlin MPP `jvm*` configurations when Gradle exposes them |
| Output | Original source when available (`.java`, `.kt`, `.scala`, `.groovy` from a sources JAR or inter-project `src`; `sourceLanguage` names it), else CFR-decompiled Java. For Kotlin classes, structure and signatures add KDoc and real parameter names to the javap result, and `methodNames` excerpts work. For Scala and Groovy, use `startLine` / `endLine` |

Composite builds, Android-only layouts, and exotic configurations are not fully validated. See [PLAN.md](PLAN.md).

</details>

<details>
<summary>Security & Privacy</summary>

* **No telemetry.**
* **Local only** — caches and diagnostics stay on disk; never writes under your project root.
* **Subprocesses** via argv only (no shell interpolation) — see [SECURITY.md](SECURITY.md).
* Optional `JVMSRC_ALLOWED_ROOTS` to lock down which projects jvmsrc may resolve.
* **Files it writes:** the cache, config and log folders only (OS defaults from [`env-paths`](https://www.npmjs.com/package/env-paths); see [Environment Variables](#detailed-reference)). It does **not** edit your agent config, `CLAUDE.md` or hooks. You add those yourself.

**Uninstall**

```bash
claude mcp remove jvmsrc        # Claude Code. Other clients: delete the "jvmsrc" entry from the MCP config
npm uninstall -g jvmsrc         # only if you installed it globally
```

Then delete the jvmsrc cache folder (`JVMSRC_CACHE_ROOT`, or the OS default), the rule block in your agent instructions and the hook entry, if you added them.

</details>

<details>
<summary>CLI Command Reference</summary>

```bash
jvmsrc com.example.MyClass                                     # shorthand for get; project = build containing cwd
jvmsrc com.example.MyClass -p /path/to/gradle-project          # explicit project
jvmsrc get com.example.MyClass -p /path/to/project -q > MyClass.java
jvmsrc resolve -p /path/to/project --force-refresh
jvmsrc config jdk-roots add /path/to/jdks                      # one-time JDK roots setup
jvmsrc doctor java -p /path/to/project                         # check JDK requirement + selection
jvmsrc diagnostics last                                         # latest failure message
jvmsrc mcp                                                     # run as MCP server
```

**Useful flags:** `-p` / `--project` (optional), `--module` (`:core:api`, or a file inside the module), `--configuration`, `--include-test` (implied when `--module` is under `src/test/`), `--force-refresh`, `--verbose` (Gradle stderr only), `--method`, `--start-line` / `--end-line`.

**Repo fixture for testing:**
`test/fixtures/gradle-smoke` —
`jvmsrc get com.smoke.Core -p test/fixtures/gradle-smoke --module :core`.

</details>

<details>
<summary>Troubleshooting</summary>

* **Resolution failures:** Run `jvmsrc diagnostics last` (or `jvmsrc diagnostics last 5`)
* **Custom JDK install roots:** Add once with `jvmsrc config jdk-roots add /path/to/jdks`
* **JDK mismatch debugging:** Run `jvmsrc doctor java -p /path/to/project`
* **After upgrading jvmsrc:** Restart your MCP host
* **Stale classpath:** Run `jvmsrc resolve --force-refresh`
* **Tool-usage analysis:** Set `JVMSRC_CALL_LOG=1` in the MCP server `env`; calls are logged to `calls.log` next to the failure log (macOS: `~/Library/Logs/jvmsrc/`)

</details>

<details>
<summary>Environment Variables</summary>

| Variable | Purpose |
|---|---|
| `JVMSRC_JAVA_HOME` | Force JDK home for Gradle/CFR child processes |
| `JVMSRC_CONFIG_DIR` | Global jvmsrc config directory (absolute) |
| `JVMSRC_CACHE_ROOT` | Cache root (absolute) |
| `JVMSRC_LOG_DIR` | Diagnostic logs (absolute) |
| `JVMSRC_CALL_LOG` | `1` = append one line per MCP tool call to `calls.log` (opt-in; see SPEC §6.3) |
| `JVMSRC_ALLOWED_ROOTS` | Allowed `projectRoot` prefixes |
| `JVMSRC_PROJECT_ROOT` | Default project root when MCP `projectRoot` / CLI `-p` is omitted and the client sends no workspace roots (falls back to the working directory) |
| `JVMSRC_MAX_SOURCE_OUTPUT_CHARS` | Max source body size (default 524288) |
| `JVMSRC_MAX_FULL_SOURCE_CHARS` | Unscoped full-file `get_class_source` larger than this is refused with `SOURCE_OUTPUT_TOO_LARGE` (default 65536) |
| `JVMSRC_GRADLE_TIMEOUT_MS` | Gradle timeout |
| `JVMSRC_USE_SYSTEM_GRADLE` | `1` = run `gradle` on `PATH`, not the project's `./gradlew` (see [SECURITY.md](SECURITY.md#gradle-wrapper-trust)) |
| `JVMSRC_MAVEN_TIMEOUT_MS` | Maven timeout (default 600000) |
| `JVMSRC_USE_SYSTEM_MAVEN` | `1` = run system `mvn`, not the project's `./mvnw` (see [SECURITY.md](SECURITY.md#maven-wrapper-trust)) |
| `JVMSRC_MAVEN_BIN` | Explicit `mvn` executable path when not using `./mvnw` |
| `JVMSRC_MAX_JAR_BYTES` | Max size of a JAR read into memory (default 524288000 = 500 MB); larger JARs return `ZIP_READ_ERROR` |
| `JVMSRC_REGEX_TIMEOUT_MS` | Wall-clock limit for regex mode in `find_in_class_source` / `search_in_artifact` (default 2000) |
| `JVMSRC_CFR_PATH` | Custom CFR JAR |

Defaults follow [`env-paths`](https://www.npmjs.com/package/env-paths) conventions per OS. Full layout: [SPEC.md](SPEC.md) §6.

When `JVMSRC_JAVA_HOME` is not set, jvmsrc auto-discovers local JDKs from common paths such as `~/.jdks` (IntelliJ), `~/.gradle/jdks`, SDKMan, jenv, asdf, and OS-specific system install directories, plus your global configured JDK roots from `jvmsrc config jdk-roots ...`.

</details>

<details>
<summary>AI Agent Reviews</summary>

> ### Finally, an MCP That Doesn't Make Me Decompile JARs
>
> *"This tool is a revelation for anyone tired of LLMs hallucinating non-existent Spring APIs. It actually reads bytecode, providing accurate class definitions and source lookups without the usual 'vibes-based' guesswork. The `search_classes` functionality is incredibly precise, and the thoughtful implementation of `javap` fallback and granular scope controls (`overview`/`declared`/`effective`) makes navigating complex JARs painless. It’s fast, honest when it can't find a class, and handles cache management perfectly. A must-have for any dev struggling with dependency hell — it’s like having a senior engineer who actually enjoys reading documentation."*
> — **Claude (AI Reviewer)**

</details>

---

## Project Documentation

| Document | Contents |
|:---|:---|
| [SPEC.md](SPEC.md) | Schemas, contracts, CLI/MCP details |
| [CONTRIBUTING.md](CONTRIBUTING.md) | Build, test, PR notes |
| [RELEASING.md](RELEASING.md) | Branching, semver, npm releases |
| [CHANGELOG.md](CHANGELOG.md) | Version history |
| [PLAN.md](PLAN.md) | Status and checkpoint plan |
| [SECURITY.md](SECURITY.md) | Vulnerability reporting |

## Building from Source

```bash
git clone https://github.com/Sintexer/jvmsrc.git
cd jvmsrc
bun install && bun run setup:cfr && bun run setup:maven-analyzer && bun run build
node dist/cli.js --version
```

Full contributor workflow: [CONTRIBUTING.md](CONTRIBUTING.md).

---

I built `jvmsrc` because I kept running into the same wall: agents that are great at writing Java but blind to the actual classpath. If it saves you the same 25-turn grind it saved me, that's exactly why this exists. Found a bug, have an idea, or just want to say it helped? Open an issue or a PR — I read everything.

## License

MIT — see [LICENSE](LICENSE).