fix(mcp): cap per_repo in graph_stats — monorepo context overflow#110
Merged
Conversation
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a multi-repo daemon,
graph_statsemits a fullper_repobreakdown. 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_repolist in thegraph_statsMCP 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/mcptests pass.Split out from a downstream fork as a self-contained fix.
🤖 Generated with Claude Code