Skip to content

feat(mcp): --tools flag to select exposed MCP tools (#716) - #717

Open
gustav-fff wants to merge 2 commits into
mainfrom
triage-bot/issue-716
Open

feat(mcp): --tools flag to select exposed MCP tools (#716)#717
gustav-fff wants to merge 2 commits into
mainfrom
triage-bot/issue-716

Conversation

@gustav-fff

Copy link
Copy Markdown
Collaborator

Closes #716

Root cause

fff-mcp unconditionally registers find_files, grep, and multi_grep in the rmcp ToolRouter and ships the full 75-line MCP_INSTRUCTIONS blob (crates/fff-mcp/src/main.rs:19-93 on pre-fix main). Every client pays the schema + instructions cost even if it only needs one tool.

Fix

Add --tools <name,...> (clap ValueEnum, snake_case, comma-separated, default = all three).

  • FffServer::new now takes the exposed set, filters the router via ToolRouter::remove_route, and stores instructions built by a new build_instructions() helper.
  • Unknown tool names cause clap to fail startup with the list of valid values.
  • Instructions are assembled dynamically: sections that reference disabled tools (e.g. rule 4 about multi_grep, grep/multi_grep constraint syntax) are omitted so the model is not told to use tools it cannot call.

Behavior with no flag is identical to before.

Steps to reproduce

Before the fix, on origin/main:

cd fff
cargo run -p fff-mcp -- --help 2>&1 | grep -- --tools
# no output — flag does not exist

# Even a client that only wants find_files:
cargo run -p fff-mcp
# advertises find_files, grep, multi_grep + 75 lines of MCP_INSTRUCTIONS

After the fix:

cargo run -p fff-mcp -- --tools find_files --help
# lists --tools with valid values

cargo run -p fff-mcp -- --tools bogus
# error: invalid value 'bogus' for '--tools <TOOLS>...'
#   [possible values: find_files, grep, multi_grep]

cargo run -p fff-mcp -- --tools find_files,grep
# advertises only find_files + grep; instructions omit multi_grep rules

Expected: unknown names hard-fail at startup; enabled subset is the only thing list_tools returns; get_info().instructions no longer mentions the disabled tools.

How verified

$ cargo test -p fff-mcp
running 17 tests
...
test server::tests::router_defaults_to_all_three_tools ... ok
test server::tests::router_exposes_only_find_files_when_requested ... ok
test server::tests::router_exposes_only_grep_pair_when_multi_grep_dropped ... ok
test instructions::tests::default_all_tools_mentions_all_three ... ok
test instructions::tests::grep_without_multi_grep_drops_multi_grep_rule ... ok
test instructions::tests::multi_grep_only_keeps_multi_grep_rules ... ok
test instructions::tests::only_find_files_drops_grep_and_multi_grep_sections ... ok
test result: ok. 17 passed; 0 failed

cargo clippy -p fff-mcp --no-deps clean; cargo fmt applied.

Automated triage via Gustav. Honk-Honk 🪿

Add a CLI-configurable tool selector to fff-mcp. Default stays
"all three" so existing configs are unchanged; picking a subset
removes the unused tools from the router and drops the parts of
MCP_INSTRUCTIONS that describe them, saving system-prompt tokens.

- clap ValueEnum accepts find_files,grep,multi_grep (snake_case).
  Unknown names fail startup with the list of valid values.
- FffServer::new takes the exposed set, filters the rmcp
  ToolRouter via remove_route, and builds instructions dynamically.
- MCP_INSTRUCTIONS is now assembled by build_instructions() in a
  new instructions module; sections referring to disabled tools
  (e.g. multi_grep rule 4, grep constraint syntax) are omitted.

Closes #716

@dmtrKovalenko dmtrKovalenko left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation is pretty sloppy but it makes sense @gustav-fff can you please make at least comments less sloppy

- ExposedTool + tool_name are pub(crate); ALL is a const array.
- Drop the re-export of build_instructions; server imports it directly.
- Server reuses ExposedTool::ALL instead of a hardcoded list.
- Shorter --tools clap doc (clap already prints valid values).
@gustav-fff

Copy link
Copy Markdown
Collaborator Author

[triage-bot] DIRECTED: pushed 1dcdc2b.

  • `ExposedTool` + `tool_name` now `pub(crate)`; replaced `fn all()` with a `const ALL`.
  • Dropped the `pub use build_instructions` re-export; `server.rs` imports it directly.
  • `FffServer::new` iterates `ExposedTool::ALL` instead of a hardcoded 3-item list.
  • Trimmed the `--tools` clap doc from 2 lines to 1 (clap already prints the valid values on error).

`cargo test -p fff-mcp` 17/17, `cargo clippy -p fff-mcp --no-deps` clean.

Honk-Honk 🪿

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.

[Suggestion]: fff-mcp: let the user choose which tools the server exposes

2 participants