Skip to content

feat(serve): honor a token_budget on get_neighbors/get_community#2069

Open
ojmucianski wants to merge 1 commit into
Graphify-Labs:v8from
ojmucianski:feat/token-budget-neighbors-community
Open

feat(serve): honor a token_budget on get_neighbors/get_community#2069
ojmucianski wants to merge 1 commit into
Graphify-Labs:v8from
ojmucianski:feat/token-budget-neighbors-community

Conversation

@ojmucianski

Copy link
Copy Markdown

Problem

get_neighbors and get_community render 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 problem query_graph already solves with the ~3-chars/token cut in _subgraph_to_text.

Change

  • New _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 as query_graph) added to both tools' input schemas.
  • get_neighbors hints relation_filter / get_node; get_community hints raising the budget / get_node.

Behavior

  • Output under budget is byte-identical to today — no change for small results.
  • Over budget: truncated at a line boundary with ... (truncated — N more lines cut by ~2000-token budget. <hint>), matching the existing _subgraph_to_text message 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.

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.
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