# How to Use Tool Filtering to Limit Exposed MCP Tools in code-review-graph

> Limit exposed MCP tools in code-review-graph using the tools CLI flag or CRG_TOOLS env variable. Control tool visibility for cleaner code reviews.

- Repository: [Tirth Kanani/code-review-graph](https://github.com/tirth8205/code-review-graph)
- Tags: how-to-guide
- Published: 2026-08-06

---

**You can restrict which MCP tools are available in code-review-graph by using the `--tools` CLI flag or the `CRG_TOOLS` environment variable to specify a comma-separated allow-list of tool names.**

code-review-graph ships with **30+ MCP tools** by default, which can overwhelm LLM token limits or introduce latency in resource-constrained environments. The repository provides a built-in filtering mechanism that lets you expose only the specific tools your workflow requires, without modifying any source code. This capability is implemented in [`code_review_graph/main.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/main.py) and documented in the README under the *Tool Filtering* section.

## How Tool Filtering Works

The filtering logic centers on the helper function `_apply_tool_filter` in [`code_review_graph/main.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/main.py). This function receives the full set of available tools and removes any tool whose name is **not** present in your supplied allow-list.

According to the source code at lines 22-48, `_apply_tool_filter` compares each tool name against the filtered list before the server starts. When the server initializes via `main()`, it invokes this filter before the MCP event loop begins (lines 85-92), ensuring that only your specified tools are registered with FastMCP.

## Configuration Methods

You can supply the tool allow-list through two mechanisms, with the CLI flag taking precedence over the environment variable. If neither is set, all 30+ tools remain exposed.

### CLI Flag (Preferred Method)

Pass a comma-separated list of tool names to the `--tools` argument when starting the server:

```bash
code-review-graph serve \
    --tools query_graph_tool,semantic_search_nodes_tool,detect_changes_tool

```

This method provides the highest precedence and is recommended for per-project configurations.

### Environment Variable (Fallback)

Set the `CRG_TOOLS` environment variable before launching the server:

```bash
export CRG_TOOLS=query_graph_tool,semantic_search_nodes_tool
code-review-graph serve

```

This approach is useful for containerized deployments or shared development environments where you want consistent defaults.

### Client Configuration Example

When configuring the server in a client like Claude Desktop or Cursor, include the tools flag in the JSON configuration:

```json
{
  "mcpServers": {
    "code-review-graph": {
      "command": "code-review-graph",
      "args": [
        "serve",
        "--tools",
        "query_graph_tool,semantic_search_nodes_tool,detect_changes_tool,get_review_context_tool"
      ]
    }
  }
}

```

The CLI argument parsing is handled in [`code_review_graph/cli.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/cli.py), which forwards the values to the main entry point.

## Key Implementation Details

The tool filtering feature involves three core components:

- **[`code_review_graph/main.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/main.py)** – Contains `_apply_tool_filter` and the orchestration logic that applies filtering before server startup.
- **[`code_review_graph/cli.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/cli.py)** – Handles argument parsing for the `--tools` flag.
- **[`README.md`](https://github.com/tirth8205/code-review-graph/blob/main/README.md)** – Documents the filtering behavior and precedence rules (lines 12-24).

## Summary

- Use the **`--tools`** CLI flag or **`CRG_TOOLS`** environment variable to limit exposed MCP tools.
- The CLI flag takes precedence over the environment variable when both are present.
- Filtering occurs in `_apply_tool_filter` before the MCP event loop starts, ensuring only requested tools are registered.
- All 30+ tools remain available if no filter is specified.

## Frequently Asked Questions

### What happens if I specify a tool name that doesn't exist?

The server ignores invalid tool names silently during the filtering process. Only tools that exist in the default set and match your allow-list are registered; non-existent names are simply skipped without raising an error.

### Can I use wildcards or patterns for tool names?

No, the filtering mechanism requires explicit tool names. As implemented in `_apply_tool_filter`, the comparison is a direct string match against the allow-list, so you must specify each tool name exactly as defined in the source code.

### Does tool filtering affect server startup time?

Startup time remains negligible because `_apply_tool_filter` performs a simple list comparison on the existing tool registry. The operation occurs before the FastMCP event loop begins, adding no perceptible latency to the initialization process.

### How do I see the full list of available tool names?

Check the repository documentation or examine the tool registration in [`code_review_graph/main.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/main.py). The README (lines 12-24) provides examples of commonly used tool names, and the source code defines all 30+ available tools that you can include in your filter.