Skip to content

feat(mcp): codemap://files/{path} + codemap://symbols/{name} resources (§ 1.8)#67

Merged
SutuSebastian merged 1 commit intomainfrom
feat/mcp-resources-files-symbols
May 4, 2026
Merged

feat(mcp): codemap://files/{path} + codemap://symbols/{name} resources (§ 1.8)#67
SutuSebastian merged 1 commit intomainfrom
feat/mcp-resources-files-symbols

Conversation

@SutuSebastian
Copy link
Copy Markdown
Contributor

Summary

Ships § 1.8 from research note — two new MCP / HTTP resources for direct agent reads:

  • codemap://files/{path} — per-file roll-up (symbols, imports, exports, coverage)
  • codemap://symbols/{name} — symbol lookup with {matches, disambiguation?} envelope + ?in=<path-prefix> filter

Saves the recipe-compose round-trip when the agent just wants "everything about this file" or "where is this symbol?".

What lands

codemap://files/{path}

{
  "path": "src/foo.ts",
  "language": "ts",
  "line_count": 30,
  "symbols": [...],
  "imports": [{"source": "...", "resolved_path": "...", "specifiers": ["bar"], "is_type_only": false, "line_number": 1}],
  "exports": [...],
  "coverage": null | {"measured_symbols": 5, "avg_coverage_pct": 78.4, "per_symbol": [...]}
}
  • imports.specifiers parsed inline (callers don't need JSON.parse).
  • Returns undefined when path not in index — distinguishes "unknown URI" from "valid URI, empty roll-up".

codemap://symbols/{name}

{
  "matches": [{"name": "foo", "kind": "function", "file_path": "src/foo.ts", "line_start": 5, "line_end": 15, "signature": "function foo(): void"}],
  "disambiguation": {"n": 2, "by_kind": {"function": 2}, "files": ["src/foo.ts", "src/legacy/foo.ts"], "hint": "Multiple matches. Narrow with --kind <kind> or --in <path>."}
}

Caching policy

Resource Caching
codemap://recipes, codemap://schema, codemap://skill Lazy-cache (catalog-style; constant for server-process lifetime)
codemap://files/{path}, codemap://symbols/{name} Live every call — index can change between requests under --watch; caching would serve stale data

Implementation notes

Test plan

  • 9 new unit tests in resource-handlers.test.ts — single match, multi-match, disambiguation, ?in filter, URI-decode, unknown path, empty name, listResources advertising
  • bun run check passes — format, lint, typecheck, all 23 golden queries
  • All existing tests pass (no regressions)
  • CodeRabbit review

Doc-governance compliance

  • Rule 10 lockstep — both templates/agents/ AND .agents/ codemap rule + skill updated with new URI templates + caching policy.
  • Patch changeset — pre-v1; additive resources; no schema bump; no breaking change to existing consumers.

Out of scope

  • codemap://files/{path} with ?coverage=true|false filter to opt out of expensive coverage roll-up — premature optimization; current single-row + per-file coverage scan is fast enough on real-world projects.
  • codemap://symbols/{name}?kind=<k> filterfindSymbolsByName already supports it via the engine; not exposed in this PR's URI surface to keep the v1 contract small. Add if demand emerges.
  • Other research note § 1 candidates still parked: § 1.3 cyclomatic complexity, § 1.5 boundary violations, § 1.6 unused type members (advisory), § 1.9 recipe-recency, § 1.10 rename-preview.

§ 1.8 from research note. Two new MCP / HTTP resources reusing
existing substrate (no schema bump):

codemap://files/{path}
- Per-file roll-up: {path, language, line_count, symbols, imports,
  exports, coverage}.
- imports.specifiers parsed inline (callers don't need JSON.parse).
- coverage is {measured_symbols, avg_coverage_pct, per_symbol} when
  ingested, else null.
- URI-encode the path; query is fail-closed (returns undefined when
  path not in index — distinguishes "unknown URI" from "valid URI,
  empty roll-up").

codemap://symbols/{name}
- Returns {matches, disambiguation?} envelope (reuses
  findSymbolsByName + buildShowResult from show-engine — same shape
  as `show <name>` per PR #39).
- Optional ?in=<path-prefix> query parameter mirrors `show --in`
  (directory prefix or exact file). Uses the WHATWG URL parser.
- Empty name → undefined; multi-match → disambiguation block.

Caching policy:
- Catalog-style resources (recipes, schema, skill) lazy-cache (existing
  pattern).
- Data-shaped resources (files, symbols) read LIVE every call — no
  caching. Index can change between requests under --watch; caching
  would silently serve stale data.

Both available over MCP read_resource AND HTTP GET /resources/
{encoded-uri} via the existing dispatcher (no new transport plumbing
needed; readResource() switch extended).

Tests:
- 9 new tests in resource-handlers.test.ts cover both endpoints +
  listResources advertising. Pattern mirrors mcp-server.test.ts (use
  initCodemap + resolveCodemapConfig + tmpdir fixture).
- bun run check passes (format, lint, typecheck, all 23 golden
  queries).

Rule 10 lockstep: both templates/agents/ and .agents/ codemap rule +
skill updated:
- Rule body — Resources bullet extended with new URIs + caching policy.
- Skill body — per-URI bullet for each new resource with shape spec.

Patch changeset: pre-v1; additive resources; no schema bump; no
breaking change to existing resource consumers.

Files: 7 changed (1 src impl, 1 src test, 4 lockstep, 1 changeset).
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 4, 2026

🦋 Changeset detected

Latest commit: 4ed406b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@stainless-code/codemap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

Warning

Rate limit exceeded

@SutuSebastian has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 10 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6ea7eef4-4b65-4714-b6c6-a3e8fe664fbf

📥 Commits

Reviewing files that changed from the base of the PR and between f121d84 and 4ed406b.

📒 Files selected for processing (7)
  • .agents/rules/codemap.md
  • .agents/skills/codemap/SKILL.md
  • .changeset/mcp-resources-files-symbols.md
  • src/application/resource-handlers.test.ts
  • src/application/resource-handlers.ts
  • templates/agents/rules/codemap.md
  • templates/agents/skills/codemap/SKILL.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/mcp-resources-files-symbols

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 49 minutes and 10 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@SutuSebastian SutuSebastian merged commit 3e03db7 into main May 4, 2026
10 checks passed
@SutuSebastian SutuSebastian deleted the feat/mcp-resources-files-symbols branch May 4, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant