Skip to content

fix(mcp): serve tools without a root index + monorepo-aware front-load hook (#964) - #966

Merged
colbymchenry merged 1 commit into
mainfrom
fix/964-mcp-and-hook-monorepo
Jun 23, 2026
Merged

colbymchenry merged 1 commit into
mainfrom
fix/964-mcp-and-hook-monorepo

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

Closes #964.

Problem

The MCP server gated tool availability on whether the server root had a .codegraph/ index. In a monorepo where only sub-projects are indexed, the agent saw zero tools and couldn't reach an indexed sub-project even by projectPath; a session started before codegraph init never surfaced the tools afterward (both reporters hit this — @MaiLunJiye, @iacore). The Claude front-load hook had the mirror gap: it only walked up for an index, so it stayed silent at a monorepo root — exactly where it's most useful.

Changes

MCP server

  • Always expose the tool surface. When the root isn't indexed, send a per-project instructions variant (SERVER_INSTRUCTIONS_NO_ROOT_INDEX — "pass projectPath") instead of the "inactive" note. Safety is preserved by response shape (success-shaped guidance, never isError), not by hiding tools.
  • Reword the no-default-project guidance to be per-project, not per-session, and sharpen the projectPath schema description.

Front-load hook (UserPromptSubmit)

  • Scan down (bounded depth 4, workspace-root-gated, skips node_modules/.git, capped) for indexed sub-projects, and shape the injection by topology: front-load the sub-project the prompt names, nudge about the rest, or list them by projectPath when ambiguous.

Verification

  • Full suite: 1703 passed, 3 skipped (+11 new frontload-hook.test.ts, updated mcp-unindexed.test.ts).
  • Live two-package monorepo run (real claude -p, sonnet/high): the hook front-loads the correct sub-project with zero cross-package leakage (cli prompts never touch preact, and vice-versa).
  • Honest note: the front-load's net speed effect is the pre-existing multi-file-vs-single-file tradeoff (helps multi-file flows, neutral/slight regression on single-file ones) — unchanged by this work, which only brings monorepos to parity with single-repo behavior. The CHANGELOG claims the capability, not a speed win. Kill-switch CODEGRAPH_NO_PROMPT_HOOK=1 still applies.

🤖 Generated with Claude Code

… monorepo-aware (#964)

The MCP server gated tool availability on whether the server root had a
.codegraph/ index, so in a monorepo where only sub-projects are indexed the
agent saw zero tools — and couldn't reach an indexed sub-project even by
projectPath. A session started before `codegraph init` also never surfaced the
tools afterward. The Claude front-load hook had the mirror gap: it only walked
UP for an index, so it stayed silent at a monorepo root.

MCP server:
- Always expose the tool surface; when the root isn't indexed, send a
  per-project instructions variant (pass projectPath) instead of the
  "inactive" note. Safety comes from response SHAPE (success-shaped guidance,
  never isError), not from hiding tools.
- Reword the no-default-project guidance to be per-project, not per-session,
  and sharpen the projectPath schema description.

Front-load hook (UserPromptSubmit):
- Scan DOWN (bounded depth, workspace-root-gated) for indexed sub-projects and
  shape the injection by topology: front-load the one the prompt names, nudge
  about the rest, or list them when ambiguous.

Verified: full suite (1703 passed); a live two-package monorepo run confirms the
hook front-loads the correct sub-project with no cross-package leakage. The
front-load's net speed effect is the existing multi-file-vs-single-file
tradeoff, unchanged by this work.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@colbymchenry
colbymchenry merged commit 85a8f32 into main Jun 23, 2026
1 check passed
@colbymchenry
colbymchenry deleted the fix/964-mcp-and-hook-monorepo branch June 23, 2026 17:57
stupidloud added a commit to stupidloud/codegraph that referenced this pull request Jun 25, 2026
Brings in 9 upstream commits incl. monorepo-aware front-load prompt-hook
(planFrontload + findIndexedSubprojectRoots, colbymchenry#964/colbymchenry#966), serve-tools-
without-root-index, O(K²) import-resolution fix, .gitignore-respecting
embedded-repo discovery, and stray-daemon-socket "Transport closed" fix.

Fork resolutions:
- package.json: keep @stupidloud scope; follow upstream description;
  version 1.1.1-sl.1 (align upstream major.minor.patch + fork suffix).
- codegraph.ts: keep fork's `spawn` import alongside upstream's
  `planFrontload` import.
- CHANGELOG.md: stays removed (fork does not maintain it).
- Semantic-search wiring (vectorManager) intact through wireLayers().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

Allow MCP tools to be exposed without requiring an index at the MCP server root path

1 participant