Skip to content

Commit 8e21ebb

Browse files
HumanBean17claude
andcommitted
update docs for trace tool (PR-TRACE-4) (#249)
* update docs for trace tool (PR-TRACE-4) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * update skills/ for six-tool trace surface Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent b8bb21d commit 8e21ebb

5 files changed

Lines changed: 34 additions & 21 deletions

File tree

AGENTS.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ gitignored).
1919

2020
`.agents/` skills are loaded by the agent working *on* java-codebase-rag source
2121
code. `skills/` and `agents/` are shipped to consumers — they instruct an agent
22-
to call the MCP tools (`search`, `find`, `describe`, `neighbors`, `resolve`)
22+
to call the MCP tools (`search`, `find`, `describe`, `neighbors`, `resolve`, `trace`)
2323
against an indexed Java codebase. Do not mix the two: never import consumer
2424
skills/agents into `.agents/skills/` or vice versa.
2525

@@ -37,7 +37,7 @@ when needed.
3737

3838
- `README.md` — pip-first landing page: install, 5-minute walkthrough on the
3939
bank-chat fixture, MCP host wiring (Claude Code / Claude Desktop), the
40-
five-tool cheat sheet (`search` / `find` / `describe` / `neighbors` / `resolve`),
40+
six-tool cheat sheet (`search` / `find` / `describe` / `neighbors` / `resolve` / `trace`),
4141
and the CLI cheat sheet. Pointers out to other docs for depth.
4242
- [`docs/CONFIGURATION.md`](./docs/CONFIGURATION.md) — environment
4343
variables, full `.java-codebase-rag.yml` reference, **graph layer**
@@ -56,7 +56,7 @@ when needed.
5656
- `docs/CODEBASE_REQUIREMENTS.md` — Java-repo assumptions and per-file map of
5757
what to edit when a target tree doesn't match defaults.
5858
- `tests/README.md` — testing philosophy.
59-
- **`skills/explore-codebase/`** — user-facing skill shipped to java-codebase-rag consumers. Single self-contained operating manual for the 5-tool MCP. Developer workflow skills live in **`.agents/skills/`**, not here.
59+
- **`skills/explore-codebase/`** — user-facing skill shipped to java-codebase-rag consumers. Single self-contained operating manual for the 6-tool MCP. Developer workflow skills live in **`.agents/skills/`**, not here.
6060
- **`agents/java-codebase-rag-explorer.md`** — user-facing Claude Code subagent shipped to consumers. Contains the same MCP guide content as `docs/AGENT-GUIDE.md` (the single source of truth).
6161
- **`propose/`** — design proposes. **In-flight** proposes live in
6262
**`propose/active/`**. **`propose/completed/`** — landed work and rationale.
@@ -81,6 +81,7 @@ when needed.
8181
| `java_ontology.py` | Source of truth for `VALID_ROLES`, `VALID_CAPABILITIES`, `VALID_CLIENT_KINDS`, `VALID_HTTP_CALL_STRATEGIES`, `VALID_ASYNC_CALL_STRATEGIES`, `VALID_HTTP_CALL_MATCHES`. |
8282
| `chunk_heuristics.py` | Query-time chunk hints (no AST / no re-index). |
8383
| `mcp_hints.py` | MCP v2 road-sign `hints` catalog (`generate_hints`; locked v1 templates in `propose/completed/HINTS-ROAD-SIGNS-PROPOSE.md`). |
84+
| `mcp_trace.py` | Multi-hop BFS traversal engine (`trace` MCP tool). |
8485
| `index_common.py` | Embedding config (no CocoIndex dep). |
8586
| `java_index_flow_lancedb.py` | CocoIndex flow (used by `java-codebase-rag init` / `increment` / `reprocess` / `erase`). |
8687
| `java_index_v1_common.py` | Shared file walker / exclude patterns. |

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A graph-native code intelligence layer for Java microservice estates, exposed to LLM agents via the **Model Context Protocol (MCP)**.
44

5-
The system extracts a deterministic property graph from Java source (tree-sitter), stores it in **Kuzu** (graph) alongside a **LanceDB** vector index (chunks), and exposes a deliberately small MCP surface — **five tools**: `search`, `find`, `describe`, `neighbors`, `resolve` — that collapse onto three primitive agent operations: **locate**, **inspect**, **walk**.
5+
The system extracts a deterministic property graph from Java source (tree-sitter), stores it in **Kuzu** (graph) alongside a **LanceDB** vector index (chunks), and exposes a deliberately small MCP surface — **six tools**: `search`, `find`, `describe`, `neighbors`, `resolve`, `trace` — that collapse onto three primitive agent operations: **locate**, **inspect**, **walk**.
66

77
> **What this MCP is:** a **GPS for code navigation**, not a reasoning engine.
88
> Agents use a simple loop:
@@ -78,7 +78,7 @@ JAVA_CODEBASE_RAG_INDEX_DIR=/tmp/bank-chat-index \
7878
--graph-expand --expand-depth 2
7979
```
8080

81-
If vector hits come back and graph expansion adds neighbor symbols, the install works end-to-end. Wire it into your agent next — the five MCP tools (`search`, `find`, `describe`, `neighbors`, `resolve`) are reachable over stdio.
81+
If vector hits come back and graph expansion adds neighbor symbols, the install works end-to-end. Wire it into your agent next — the six MCP tools (`search`, `find`, `describe`, `neighbors`, `resolve`, `trace`) are reachable over stdio.
8282

8383
---
8484

@@ -118,15 +118,15 @@ See [`mcp.json.example`](./mcp.json.example) for the same shape in `.mcp.json` (
118118

119119
Pick **one** of two options (not both — they cover the same navigation intents):
120120

121-
1. **[`docs/AGENT-GUIDE.md`](./docs/AGENT-GUIDE.md)** (recommended for most) — standalone MCP operating manual. Copy-paste the `BEGIN`/`END` block into your project's `QWEN.md`, `CLAUDE.md`, or `AGENTS.md`. Contains: five-tool reference, `NodeFilter` / edge taxonomy, ontology glossary, recovery playbook, and navigation patterns. Self-contained — no external file dependencies.
121+
1. **[`docs/AGENT-GUIDE.md`](./docs/AGENT-GUIDE.md)** (recommended for most) — standalone MCP operating manual. Copy-paste the `BEGIN`/`END` block into your project's `QWEN.md`, `CLAUDE.md`, or `AGENTS.md`. Contains: six-tool reference, `NodeFilter` / edge taxonomy, ontology glossary, recovery playbook, and navigation patterns. Self-contained — no external file dependencies.
122122

123123
2. **[`/explore-codebase`](./skills/explore-codebase/SKILL.md)** (for hosts with skill discovery) — single self-contained skill with the complete operating manual. If your MCP host supports skill discovery (Claude Code, Qwen Code, Cursor), load `/explore-codebase` to get the full tool reference, edge taxonomy, decision tree, and recovery playbook in one shot.
124124

125125
Also: **[`docs/MANUAL-VERIFICATION-CHECKLIST.md`](./docs/MANUAL-VERIFICATION-CHECKLIST.md)** — 7-phase agent-driven verification you run after indexing your real project.
126126

127127
---
128128

129-
## The five tools, at a glance
129+
## The six tools, at a glance
130130

131131
| Tool | Purpose | Required args |
132132
|---|---|---|
@@ -135,12 +135,13 @@ Also: **[`docs/MANUAL-VERIFICATION-CHECKLIST.md`](./docs/MANUAL-VERIFICATION-CHE
135135
| `describe` | Full record + edge counts for one node. | `id` |
136136
| `resolve` | Identifier-shaped lookup (FQN-collision-safe). Returns `one` / `many` / `none`. | `identifier` |
137137
| `neighbors` | Graph walk, one hop. | `ids`, `direction`, `edge_types` |
138+
| `trace` | Multi-hop BFS traversal with pruning. | `ids`, `direction`, `edge_types` |
138139

139140
Full schemas, `NodeFilter` / `EdgeFilter` semantics, and the hints contract live in [`docs/AGENT-GUIDE.md`](./docs/AGENT-GUIDE.md). Edge types and traversal directions are listed in [`docs/EDGE-NAVIGATION.md`](./docs/EDGE-NAVIGATION.md).
140141

141142
### Three-layer architecture
142143

143-
Layer 1 (storage) → Layer 2 (5 MCP tools) → Layer 3 (skill). The [`/explore-codebase`](./skills/explore-codebase/SKILL.md) skill provides the full operating manual for Layer 2. See the [architecture diagram in `skills/README.md`](./skills/README.md#three-layer-architecture).
144+
Layer 1 (storage) → Layer 2 (6 MCP tools) → Layer 3 (skill). The [`/explore-codebase`](./skills/explore-codebase/SKILL.md) skill provides the full operating manual for Layer 2. See the [architecture diagram in `skills/README.md`](./skills/README.md#three-layer-architecture).
144145

145146
---
146147

docs/AGENT-GUIDE.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Agent Guide — `java-codebase-rag` MCP
22

3-
Copy the block between `<!-- BEGIN` and `<!-- END` into your project's `AGENTS.md`, `CLAUDE.md`, or equivalent. It is self-contained: five MCP tools, shared `NodeFilter`, edge taxonomy, tool-selection rules, and recovery moves.
3+
Copy the block between `<!-- BEGIN` and `<!-- END` into your project's `AGENTS.md`, `CLAUDE.md`, or equivalent. It is self-contained: six MCP tools, shared `NodeFilter`, edge taxonomy, tool-selection rules, and recovery moves.
44

55
---
66

77
<!-- BEGIN java-codebase-rag MCP guide -->
88

99
## java-codebase-rag MCP — operating manual
1010

11-
**Tools:** `search`, `find`, `describe`, `neighbors`, `resolve`.
11+
**Tools:** `search`, `find`, `describe`, `neighbors`, `resolve`, `trace`.
1212

1313
**Node kinds:** `Symbol` (types and methods), `Route` (HTTP and messaging entry points), `Client` (outbound HTTP call sites), `Producer` (outbound async call sites).
1414

1515
**Indexed content:** Java production sources plus SQL and YAML (use `search` `table`: `java`, `sql`, `yaml`, or `all`).
1616

1717
**Ontology: 16** — if results look structurally wrong or empty across tools, the index may be missing, stale, or built with a different `ontology_version`; you cannot re-index via MCP — ask the operator to rebuild.
1818

19-
**Responses:** On success, `search`, `find`, `describe`, `neighbors`, and `resolve` may include two top-level fields: `hints_structured` (≤5 suggested next-tool calls) and `advisories` (≤5 pure informational strings). Each `hints_structured` entry has `tool`, `args`, `actionable`, `label`, and `reason`. `actionable=true` means you can call the tool directly with `args`; `actionable=false` means partial/advisory — fill missing values or use as guidance. `reason` explains why the hint was emitted. `advisories` carry context education (fuzzy strategy warnings, role collision explanations, etc.) with no tool call suggestion. For `search`/`find`, echoed `limit`/`offset`. Hints are advisory; ignore them when `success` is false.
19+
**Responses:** On success, `search`, `find`, `describe`, `neighbors`, `resolve`, and `trace` may include two top-level fields: `hints_structured` (≤5 suggested next-tool calls) and `advisories` (≤5 pure informational strings). Each `hints_structured` entry has `tool`, `args`, `actionable`, `label`, and `reason`. `actionable=true` means you can call the tool directly with `args`; `actionable=false` means partial/advisory — fill missing values or use as guidance. `reason` explains why the hint was emitted. `advisories` carry context education (fuzzy strategy warnings, role collision explanations, etc.) with no tool call suggestion. For `search`/`find`, echoed `limit`/`offset`. Hints are advisory; ignore them when `success` is false.
2020

2121
**Use this MCP when** you need whole-codebase structure: callers/callees, route handlers, HTTP/async seams, clients/producers, or fuzzy entry points for a concept.
2222

@@ -35,15 +35,15 @@ When MCP disagrees with the open file, **the file wins**; treat the mismatch as
3535

3636
1. **Locate**`resolve` for identifier-shaped strings; `search` for natural language or code fragments; `find` for structured `NodeFilter` discovery.
3737
2. **Inspect**`describe(id)` for the full record and `edge_summary` (per-label `in`/`out` counts).
38-
3. **Walk**`neighbors` in a loop with explicit **`direction`** and **`edge_types`**. Multi-hop traces are **your** reasoning, not a separate tool.
38+
3. **Walk**`neighbors` in a loop with explicit **`direction`** and **`edge_types`**, or `trace` for multi-hop BFS with server-side pruning in one call.
3939

4040
### Forced reasoning preamble (every tool call)
4141

4242
Before each MCP call, output one short line:
4343

4444
```
45-
Q-class: <semantic | structured | inspect | walk>
46-
Pick: <search|find|describe|neighbors|resolve> Why: <≤8 words>
45+
Q-class: <semantic | structured | inspect | walk | trace>
46+
Pick: <search|find|describe|neighbors|trace|resolve> Why: <≤8 words>
4747
```
4848

4949
Then use real JSON shapes (see below). If the call fails or returns nothing useful, use the **Recovery playbook** — do not thrash.
@@ -178,7 +178,7 @@ Prefer **`resolve` → `describe(id=…)`** over **`describe(fqn=…)`** when an
178178
| Handler for route | route id | `neighbors(ids, "in", ["EXPOSES"])` |
179179
| Who implements interface T? | type symbol id | `neighbors(ids, "in", ["IMPLEMENTS"])` |
180180
| Who injects type T? | type symbol id | `neighbors(ids, "in", ["INJECTS"])` |
181-
| Impact / "what breaks if I change X"? | no magic tool | loop `neighbors` `in` with `CALLS`, `INJECTS`, … until bounded |
181+
| Impact / "what breaks if I change X"? | `trace` or `neighbors` loop | `trace(id, "in", ["CALLS","OVERRIDES"], max_depth=3)` or loop `neighbors` `in` with `CALLS`, `INJECTS` |
182182

183183
**Rules of thumb:**
184184

@@ -188,6 +188,14 @@ Prefer **`resolve` → `describe(id=…)`** over **`describe(fqn=…)`** when an
188188

189189
### Tool reference
190190

191+
#### `trace`
192+
193+
Multi-hop BFS traversal with server-side pruning. Returns structured paths, a node dict, and traversal stats. Use when the question implies a path or chain (3+ hops), needs to cross a service boundary, or a `neighbors` loop has exceeded 2 hops without converging. Args: `ids` (string or array), **`direction`**, **`edge_types`** (stored labels only — no composed dot-keys), `max_depth` (1–5, default 3), `max_paths` (default 20), `max_nodes_discovered` (100–2000, default 500), `filter` (hard gate `NodeFilter`), `edge_filter` (CALLS edge attribute filtering), `prune_roles` (soft gate — edges recorded, frontier stops), `fan_out_cap` (per-node edge limit, default 5), `collapse_trivial` (collapse wrapper chains, default true), `include_unresolved` (interleave unresolved call sites).
194+
195+
Returns `TraceOutput` with `nodes` (dict of `NodeRef`), `edges` (list of `TraceEdge` with `hop`, `parent_edge_id`, `collapsed`, `cross_service_boundary`), `paths` (ranked root-to-leaf), and `stats` (budget, pruning counts). Cross-service edges (`HTTP_CALLS`, `ASYNC_CALLS`) are boundary signals — BFS stops at the service boundary and includes the downstream node for the agent to continue with a separate `trace` call.
196+
197+
**`trace` vs `neighbors`:** Use `neighbors` for single-hop adjacency (full unfiltered result). Use `trace` for multi-hop path questions, impact analysis, or when `neighbors` returns high fan-out (>8 CALLS edges).
198+
191199
#### `search`
192200

193201
Ranked chunk retrieval. Args: `query`, `table` (`java`|`sql`|`yaml`|`all`, default `java`), `hybrid` (bool), `limit` (default 5), `offset`, `path_contains`, optional `filter` (symbol-applicable `NodeFilter` only).
@@ -272,7 +280,7 @@ After two failed attempts on the same intent, stop and report tool name, args, a
272280

273281
### Common navigation patterns
274282

275-
These patterns combine the five tools above. Use the decision tree to pick the right starting tool.
283+
These patterns combine the six tools above. Use the decision tree to pick the right starting tool.
276284

277285
| Intent | Tool chain |
278286
| ------ | ---------- |
@@ -287,7 +295,10 @@ These patterns combine the five tools above. Use the decision tree to pick the r
287295
| All inbound to route R | `neighbors(route_id, "in", ["HTTP_CALLS","ASYNC_CALLS","EXPOSES"])` |
288296
| Implementors of interface T | `neighbors(type_id, "in", ["IMPLEMENTS"])` |
289297
| Where is T injected | `neighbors(type_id, "in", ["INJECTS"])` |
290-
| Impact of changing X | `resolve``describe` → bounded `neighbors(in, ["CALLS","INJECTS","IMPLEMENTS","EXTENDS"])` depth ≤2 |
298+
| Impact of changing X | `resolve``trace(id, "in", ["CALLS","OVERRIDES"], max_depth=3)` or `neighbors` loop depth ≤2 |
299+
| "What happens when route R is called?" | `find(kind="route")``trace(route_id, "out", ["EXPOSES","CALLS"], max_depth=4)` |
300+
| "Trace from X to database" | `trace(id, "out", ["CALLS"], max_depth=4, prune_roles=["DTO","EXCEPTION"])` |
301+
| "What calls this across services?" | `trace(id, "out", ["CALLS","HTTP_CALLS","ASYNC_CALLS"], max_depth=5)` |
291302

292303
### Canonical workflow: "explain feature X"
293304

@@ -305,5 +316,5 @@ These patterns combine the five tools above. Use the decision tree to pick the r
305316
When MCP behaviour, `NodeFilter` keys, edge labels, or node kinds change:
306317

307318
1. Update this file's copy block and bump the **Ontology:** line to match `ast_java.ONTOLOGY_VERSION`.
308-
2. Update the five-tool cheat sheet in `README.md` and the "Driving the MCP from an agent" bullet there.
319+
2. Update the six-tool cheat sheet in `README.md` and the "Driving the MCP from an agent" bullet there.
309320
3. If enrichment semantics changed, add a "Re-index required" callout in [`docs/CONFIGURATION.md`](./CONFIGURATION.md) §3.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TRACE-TOOL -- Multi-hop navigation shortcut
22

3-
**Status**: active (experimental)
3+
**Status**: completed (merged to `experimental` as PR-TRACE-1a through PR-TRACE-4)
44
**Target branch**: `experimental` — not `master`. `trace` is an experiment; it ships on a dedicated branch and is not merged to `master` until validated in production.
55
**Author**: Dmitry + Computer
66
**Date**: 2026-05-25

skills/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# skills/ — RAG navigation skill for the java-codebase-rag MCP
22

3-
One self-contained skill for navigating indexed Java codebases via the 5-tool MCP (`search` / `find` / `describe` / `neighbors` / `resolve`). Skills are agent-side prompt scaffolding — they are **not** a second MCP API and **not** CLI subcommands.
3+
One self-contained skill for navigating indexed Java codebases via the 6-tool MCP (`search` / `find` / `describe` / `neighbors` / `resolve` / `trace`). Skills are agent-side prompt scaffolding — they are **not** a second MCP API and **not** CLI subcommands.
44

55
## Layout
66

@@ -14,7 +14,7 @@ skills/
1414

1515
The comprehensive operating manual. Includes:
1616

17-
- **Five-tool reference**`search`, `find`, `describe`, `neighbors`, `resolve` with full argument shapes
17+
- **Six-tool reference**`search`, `find`, `describe`, `neighbors`, `resolve`, `trace` with full argument shapes
1818
- **Node kinds** — Symbol, Route, Client, Producer
1919
- **Edge taxonomy** — stored edges, composed dot-keys, direction semantics
2020
- **NodeFilter reference** — all filter keys by node kind, strict frame rules

0 commit comments

Comments
 (0)