Skip to content

fix(mcp): cap per_repo in graph_stats — monorepo context overflow#110

Merged
zzet merged 1 commit into
zzet:mainfrom
avfirsov:pr/mcp-per-repo-cap
Jun 18, 2026
Merged

fix(mcp): cap per_repo in graph_stats — monorepo context overflow#110
zzet merged 1 commit into
zzet:mainfrom
avfirsov:pr/mcp-per-repo-cap

Conversation

@avfirsov

Copy link
Copy Markdown
Contributor

Problem

On a multi-repo daemon, graph_stats emits a full per_repo breakdown. On a monorepo / many-repo workspace this block alone overflows an MCP client's context window — large enough that it made the MCP surface effectively unusable for some clients.

Fix

Cap the per_repo list in the graph_stats MCP tool so the response stays bounded regardless of repo count (totals are unaffected; only the per-repo enumeration is capped).

Tests

internal/mcp/capstats_test.go. go build ./... clean; internal/mcp tests pass.

Split out from a downstream fork as a self-contained fix.

🤖 Generated with Claude Code

…e MCP unusable

The gortex://stats resource (and graph_stats tool) inlined a full GraphStats for EVERY
tracked repo when multi-repo. On a large monorepo gortex decomposes into hundreds of
sub-repos, and the resource is advertised "read at session start to orient", so an agent
reads it on connect — dumping a per-repo rollup for ~hundreds of repos into the context
window and overflowing it before any user turn (even a "42" prompt died). Small repos were
fine because IsMultiRepo()==false skips the block entirely.

cappedRepoStats bounds per_repo to the top-N (25) repos by node count + a _truncated marker
pointing at graph_stats repo=<prefix> for the rest. Bounds both the resource and the tool.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
(cherry picked from commit f276e74)
@zzet zzet merged commit 8cab237 into zzet:main Jun 18, 2026
10 checks passed
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.

2 participants