Skip to content

fix(mcp): cap search_graph default limit to 200 (was 500K)#231

Open
amitmynd wants to merge 1 commit intoDeusData:mainfrom
amitmynd:fix/search-graph-default-limit
Open

fix(mcp): cap search_graph default limit to 200 (was 500K)#231
amitmynd wants to merge 1 commit intoDeusData:mainfrom
amitmynd:fix/search-graph-default-limit

Conversation

@amitmynd
Copy link
Copy Markdown

Problem

search_graph with a broad file_pattern (e.g. **/ads/**) returns output that exceeds LLM tool result limits. In my case, querying a 12K-node project returned 3,358,396 characters, which Claude Code couldn't process:

search_graph (MCP)(project: "Users-amitbhalla-Downloads-myndintegrated", file_pattern: "**/ads/**")

Error: result (3,58,396 characters) exceeds maximum allowed tokens.

Root cause

The default limit for the regex/file_pattern search path uses MCP_HALF_SEC_US (500,000), which appears to be a microsecond timeout constant that was accidentally used as a row count. When no explicit limit is passed, the query returns up to 500K rows, serializing all of them into the JSON response.

  • src/mcp/mcp.c:1344: cbm_mcp_get_int_arg(args, "limit", MCP_HALF_SEC_US) (500,000)
  • src/store/store.c:2304: fallback to ST_HALF_SEC (also 500,000)
  • Tool description says "Default: unlimited"

Fix

Changed the default limit to 200 in both the MCP handler and the store layer. Updated the tool description to reflect this.

Before: 1,287 matching nodes, all returned, 3.3M characters output
After: 1,287 total (reported in total field), 200 returned, 57K characters output, has_more: true

Pagination with offset and limit continues to work as expected for callers that need more results.

Changes

File Change
src/mcp/mcp.c Default limit 500,000 -> 200 in handle_search_graph
src/store/store.c Fallback limit ST_HALF_SEC -> 200 in cbm_store_search
src/mcp/mcp.c Tool description: "Default: unlimited" -> "Default: 200"

Test plan

  • Build succeeds with make -f Makefile.cbm cbm
  • search_graph with broad file_pattern returns 200 results (57K chars) instead of all matches (3.3M chars)
  • Response includes total: 1287, has_more: true for pagination
  • list_projects and --help work correctly
  • Explicit limit param still overrides the default

🤖 Generated with Claude Code

The default limit for search_graph used MCP_HALF_SEC_US (500,000),
a microsecond timeout constant misused as a row count. Broad queries
like file_pattern="**/ads/**" on a 12K-node project returned all
1,287 matches (3.3M characters), exceeding LLM tool result limits.

Changes:
- MCP handler: default limit 500,000 -> 200
- Store layer: fallback limit ST_HALF_SEC (500,000) -> 200
- Tool description: "Default: unlimited" -> "Default: 200"

Pagination via offset/limit still works. The response includes
total count and has_more flag for callers that need more results.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DeusData DeusData added bug Something isn't working stability/performance Server crashes, OOM, hangs, high CPU/memory labels Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working stability/performance Server crashes, OOM, hangs, high CPU/memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants