feat(serve): honor a token_budget on get_neighbors/get_community#2069
Open
ojmucianski wants to merge 1 commit into
Open
feat(serve): honor a token_budget on get_neighbors/get_community#2069ojmucianski wants to merge 1 commit into
ojmucianski wants to merge 1 commit into
Conversation
get_neighbors and get_community render every edge/member line unbounded — on a god node or a large community that floods an MCP client's context window with 100KB+ of text in one tool result. query_graph already solves this with the ~3-chars/token cut in _subgraph_to_text; this applies the same budget rule to the two line-list tools via a shared helper (_cut_lines_to_budget): cut at a line boundary, report how many lines were dropped, and point at the narrowing path (relation_filter / get_node). Default 2000 like query_graph; output under budget is byte-identical to today.
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
get_neighborsandget_communityrender every edge/member line unbounded. On a god node or a large community, one tool call floods an MCP client's context window with 100KB+ of text — the exact problemquery_graphalready solves with the ~3-chars/token cut in_subgraph_to_text.Change
_cut_lines_to_budget(lines, token_budget, narrow_hint)helper applying the same budget rule to pre-built line lists: cut at a line boundary, report how many lines were dropped, and point at the narrowing path.token_budget(integer, default 2000 — same asquery_graph) added to both tools' input schemas.get_neighborshintsrelation_filter/get_node;get_communityhints raising the budget /get_node.Behavior
... (truncated — N more lines cut by ~2000-token budget. <hint>), matching the existing_subgraph_to_textmessage shape.Motivation context: we run graphify-mcp as a read-only code-structure organ for LLM sessions; unbounded neighbor/community dumps were the last two tools that could blow a session's context in one call. Happy to adjust naming/defaults to taste.