feat(serve): add --tools flag and CRG_TOOLS env var for MCP tool filtering#301
Closed
sdeonvacation wants to merge 1 commit into
Closed
feat(serve): add --tools flag and CRG_TOOLS env var for MCP tool filtering#301sdeonvacation wants to merge 1 commit into
sdeonvacation wants to merge 1 commit into
Conversation
…ering CRG exposes 28 MCP tools by default, adding ~8k description tokens per LLM turn. In token-constrained environments this overhead can exceed the savings from graph queries. Add _apply_tool_filter() that accepts a comma-separated allow-list of tool names. Unlisted tools are removed via FastMCP.remove_tool() before the server starts. The allow-list can be provided via: 1. --tools CLI flag (highest precedence) 2. CRG_TOOLS environment variable (fallback) When neither is set, all tools remain available (no breaking change). Filtering to 5-10 tools reduces per-turn overhead by 70-85%. Includes 7 async tests covering: no-filter noop, argument-based filtering, env var fallback, argument precedence over env, empty string noop, and whitespace handling.
Owner
|
This PR now has merge conflicts with main after recent merges. Could you rebase on the latest main? The feature looks good. |
tirth8205
added a commit
that referenced
this pull request
Apr 18, 2026
Kept --tools flag / CRG_TOOLS env var (PR #301) alongside --http/--host/--port Streamable HTTP transport flags added by origin/main; merged both sets of changes in cli.py, main.py, README.md, and tests/test_main.py. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
|
Closed: changes merged directly into main as commit a3a043b (feat(serve): add --tools flag and CRG_TOOLS env var for MCP tool filtering). Conflicts with --http/--host/--port HTTP transport flags were resolved by keeping both features. |
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.
Summary
--toolsCLI flag toservesubcommand andCRG_TOOLSenv var fallback for filtering which MCP tools are exposedFastMCP.remove_tool()before the server startsMotivation
CRG exposes 28 MCP tools by default, adding ~8k description tokens per LLM turn. In token-constrained environments (e.g. agentic coding tools calling CRG via MCP), this overhead can exceed the savings from graph queries — especially when only 5-10 tools are actually needed.
Filtering to a working set reduces per-turn overhead by 70-85%, making CRG net-positive on tokens from the first few queries.
Usage
MCP client config example:
{ "mcpServers": { "code-review-graph": { "command": "code-review-graph", "args": ["serve", "--tools", "query_graph_tool,semantic_search_nodes_tool,detect_changes_tool"] } } }Changes
code_review_graph/main.py_apply_tool_filter()+ updatemain()signaturecode_review_graph/cli.py--toolsarg toservesubparser, pass tomain()tests/test_main.pyREADME.mdTesting
All 794 existing tests pass. 7 new tests added:
test_no_filter_keeps_all_tools— noop when unsettest_filter_via_argument— keeps only listed toolstest_filter_via_env_var—CRG_TOOLSenv var workstest_argument_takes_precedence_over_env— CLI wins over envtest_empty_string_is_noop— empty string doesn't remove all toolstest_whitespace_handling— spaces around names are stripped