Repository navigation
mcp: add per-server tool allow and deny lists - #2020
Conversation
netzenbot-reviewer
left a comment
There was a problem hiding this comment.
Recommendation: request changes
What this pull request does
This adds per-server tool allow (tools) and deny (exclude_tools) lists to MCP server declarations, for both stdio and HTTP servers. Names may be bare (get_forecast) or alias-qualified (weather:get_forecast), are validated, deduplicated, accepted in the declarations JSON file, and set with new --tools and --exclude-tools flags on bravebot mcp add (comma-separated, space-separated or =-joined). After the handshake, Listing::filtered drops any tool matching a deny entry, and any tool not matching an allow entry when the allow list is non-empty, so deny wins; removed tools are counted separately from tools refused for format reasons. The filters are folded into the declaration digest only when non-empty, so existing digests are unchanged and editing a filter requires re-approval. The count is carried through the TUI card, the plain prompt, the ui-bridge wire/ACP payloads and both locale files as a 'tool(s) withheld' line, and the add prompt and inspect output show tools: and exclude tools: lines. A new spec clause, SERVERS-17, documents this.
Trying it by hand
The description does not say how to try this change. These steps would:
- Build the CLI from the PR branch (e.g.
BRAVEBOT_ALLOW_UNCONFIGURED_BUILD=1 cargo build -p bravebot-cli) and use a scratch HOME or project so no real declarations are touched. - Run
bravebot mcp add srv --tools fetch,search --exclude-tools delete -- /opt/srvand answernat the question. Expect linestools: fetch, searchandexclude tools: deleteabove the digest line. - Check the flag forms:
--tools=fetch,search,--tools fetch searchand an--http https://mcp.example.com/mcpdeclaration with the same flags should each be accepted. - Run
bravebot mcp add srv --tools -- /opt/srv, then with--tools=and with--tools ''. Each should be refused with 'needs a tool name or a comma-separated list'. Repeat with--exclude-tools. - Run
bravebot mcp add srv --tools 'not a valid tool name' -- /opt/srv. Expect a refusal saying the name is not a tool name. - Point an MCP server that advertises several tools (e.g. the weather server from docs/specs/mcp-servers.md) at a declaration with
--exclude-tools get_forecast, start a session and approve it. The tool-list card should omit that tool and show 'one tool was withheld by the server's allow or deny list'. - Declare the same server with
--tools get_alerts --exclude-tools get_alerts. Expect no tools offered and every tool counted as withheld, because deny wins. - Edit the filter on an already approved server (for example in the declarations JSON file). Expect the server to be asked about again, with
toolsorexclude_toolsnamed as changed. Check this step against the real UI, since I did not confirm the exact wording.
How this review reached its recommendation
The review read 20 changed files.
What it checked:
- Written best practices. The changes were compared with 16 rules from this project's best-practice documents (compatibility, dependencies, paths, portability, shared-implementation, specs, tests, writing).
- Bugs. The changes were read for mistakes that would make the code misbehave or stop it building.
- This project's own criteria. The changes were checked against these questions:
- Whether the change agrees with the project's specs, and whether a change to behaviour a spec describes also updates that spec and its tests.
- Whether untrusted content (text from the web, files or tools) can influence a decision, or be given a better trust label than it came with, anywhere other than the places built for that.
- Whether the tests would fail if the behaviour broke, rather than covering only the allowed case or passing with the bug put back.
- Whether the change does what its title says and nothing more, with no unrelated refactor and no new dependency, permission or network destination the title does not explain.
The checks flagged 8 possible problems. 4 of them went to a second reader, who checked each against the full source code rather than only the diff, and kept 2.
48571da to
4fe825b
Compare
|
new changes
Thank you! @bbondy |
A declaration may declare an allow list (tools) and a deny list (exclude_tools) of tool names. When exclude_tools names a tool, it is denied; when tools is non-empty and does not name a tool, it is denied. Tool names must be valid identifiers, optionally prefixed with an alias. Both stdio and http declarations support filtering. When tool filters are specified, they are included in the declaration digest so changes to filtering require approval. Declarations with no tool filters produce the exact same digest as before. Signed-off-by: winshaurya <[email protected]>
Servers list their tools during handshake. When a server declaration specifies an allow list (tools) or deny list (exclude_tools), the tools are filtered before they are stored or offered to the model. Deny lists take precedence over allow lists. Tools withheld by filters are counted under withheld, kept distinct from tools refused by protocol or validation rules. The number of withheld tools is presented to the user in confirmation prompts across TUI, plain text, and wire interfaces. Signed-off-by: winshaurya <[email protected]>
Signed-off-by: winshaurya <[email protected]>
Signed-off-by: winshaurya <[email protected]>
- Drive integration test through real servers::reach with declarations on disk - Assert withheld tools are omitted from model request payload - Assert that attempting to call a withheld tool is refused - Add unit test verifying Problem::Tools and Problem::Tool on Declarations::parse - Add unit test verifying handshake_local filters tools by allow and deny lists - Link new tests to SERVERS-17 in docs/specs/mcp-servers.md Signed-off-by: winshaurya <[email protected]>
4fe825b to
40d0829
Compare
netzenbot-reviewer
left a comment
There was a problem hiding this comment.
Recommendation: approve
1 earlier comment was addressed and resolved.
What this pull request does
This adds optional tools (allow) and exclude_tools (deny) lists to stdio and HTTP MCP server declarations, with matching --tools and --exclude-tools flags on bravebot mcp add. After the handshake, Listing::filtered drops any tool named in the deny list, and any tool not in a non-empty allow list, so deny wins. Names may be bare (get_forecast) or alias-qualified (weather:get_forecast), and are validated when parsed from mcp.json or from the flags. The two lists enter the declaration digest only when non-empty, so existing digests are unchanged, and editing a filter on an approved server triggers a fresh approval that names tools or exclude_tools as changed. Withheld tools are counted separately from refused ones, and the count is shown in the tool-list confirmation in the TUI, the plain prompt and the wire/ACP payload, with en-US and fr strings and a new SERVERS-17 spec clause. The description and diff agree. One detail the description does not mention: the declaration prompt and inspect view print tools: and exclude tools: lines.
How this review reached its recommendation
The review read 5 of the 20 changed files: only those that changed since the bot last reviewed this pull request.
What it checked:
- Written best practices. The changes were compared with 16 rules from this project's best-practice documents (compatibility, dependencies, paths, portability, shared-implementation, specs, tests, writing).
- Bugs. The changes were read for mistakes that would make the code misbehave or stop it building.
- This project's own criteria. The changes were checked against these questions:
- Whether the change agrees with the project's specs, and whether a change to behaviour a spec describes also updates that spec and its tests.
- Whether untrusted content (text from the web, files or tools) can influence a decision, or be given a better trust label than it came with, anywhere other than the places built for that.
- Whether the tests would fail if the behaviour broke, rather than covering only the allowed case or passing with the bug put back.
- Whether the change does what its title says and nothing more, with no unrelated refactor and no new dependency, permission or network destination the title does not explain.
The checks flagged 2 possible problems. 2 of them went to a second reader, who checked each against the full source code rather than only the diff, and found none of them to be a real problem introduced by this change.
netzenbot-reviewer
left a comment
There was a problem hiding this comment.
Recommendation: approve
What this pull request does
This adds per-server tool filters to MCP declarations: an allow list (tools) and a deny list (exclude_tools), each entry either a bare tool name or alias:tool. bravebot mcp add gains --tools and --exclude-tools (comma-separated, space-separated or = forms, for stdio and HTTP servers), and the same keys are read from and written to the declarations file with validation. After the handshake, Listing::filtered drops any tool that matches a deny entry, or that misses a non-empty allow list, so deny wins. It counts those tools as withheld, separately from tools refused for format reasons, so the model is never offered them and calls to them are refused. The filters are folded into the declaration digest only when non-empty, so existing approvals keep their digests, and editing a filter triggers a new approval that names the changed field. The approval card (TUI, plain CLI, wire and ACP) shows a 'tools withheld' line, the mcp add question prints tools: and exclude tools: lines, and a new spec clause SERVERS-17 and en-US and fr strings are added. The diff matches the description.
How this review reached its recommendation
The review read 0 of the 20 changed files: only those that changed since the bot last reviewed this pull request.
None of these checks flagged anything, so there was nothing to double-check.
User impact: Users can now filter tools exposed by MCP servers using allow lists (
--tools) and deny lists (--exclude-tools), preventing unwanted or noisy tools from entering the model's context while maintaining clear UI visibility over withheld tools.Hi @bbondy and reviewers,
This PR implements per-server tool allow lists (
tools) and deny lists (exclude_tools) for MCP servers, resolves #1399.The problem
General-purpose MCP servers often provide dozens of tools, many of which may be irrelevant, noisy, or undesirable in a given project. Previously, all tools reported by an MCP server during its handshake were either accepted into the tool list offered to the model or caused the entire server's tools to be declined. There was no way to allow a subset of tools or exclude specific unwanted tools on a per-server basis.
Reproduce
weatheradvertisingget_alerts,get_forecast,get_radar).get_forecastor to excludeget_radar.The fix
We implement tool filtering across five modular, signed commits:
Declarations and Digest Compatibility (
crates/config/src/mcp.rs):tools: Vec<String>andexclude_tools: Vec<String>toDeclaration::StdioandDeclaration::Http.is_tool_filter_name(), accepting both bare identifiers (get_forecast) and alias-qualified identifiers (weather:get_forecast).Declaration::digest()only when non-empty, guaranteeing that existing declarations without filters retain their exact existing SHA-256 digests.Field::ToolsandField::ExcludeTools.Problem::Toolsfor invalid types andProblem::Toolfor invalid identifiers.Tool Filtering, Protocol Handling, and UI Visibility (
crates/agent,crates/mcp,crates/approval,crates/tui,crates/ui-bridge):exclude_tools) always take precedence over allow lists (tools). If a tool matches any entry inexclude_tools, it is withheld; iftoolsis non-empty and the tool is not intools, it is withheld.withheld: usize, keeping them distinct from tools refused by format or protocol violations.crates/tui/src/confirm.rs), plain CLI (crates/approval/src/lib.rs), and wire protocol (crates/ui-bridge/src/wire.rs,acp.rs) to report withheld tools in the confirmation card when non-zero (e.g., "(1 tool withheld by filter)").mcp-tools-withheld) inen-US.ftlandfr.ftl.CLI Options and Validation (
crates/cli/src/mcp.rs,crates/agent/src/servers.rs):--tools <list>and--exclude-tools <list>flags tobravebot mcp addfor both stdio and HTTP servers.--tools foo,bar) and space-separated argument formats as well as flag-joined formats (--tools=foo,bar).mcp-tools-needs-a-list,mcp-exclude-tools-needs-a-list).tools: ...andexclude tools: ...) and in server inspect views.Specifications and Formal Verification (
docs/specs):SERVERS-17todocs/specs/mcp-servers.md, specifying precedence, qualification matching, withheld counting, and digest requirements.SERVERSclause count indocs/specs/README.mdfrom 16 to 17.Labelled::newcall site count indocs/specs/labels.mdto account for the filtered listing constructor.check-spec.py --mechanical-only) with 0 errors across 1037 clauses.Review Feedback Resolutions (
crates/agent,crates/config,docs/specs):servers::reachwith declarations on disk rather than a synthetic helper.bravebot-configassertingDeclarations::parseproducesProblem::ToolsandProblem::Toolfor invalid declarations.bravebot-agentassertinghandshake_localfilters tools by allow and deny lists.Trying it by hand
BRAVEBOT_ALLOW_UNCONFIGURED_BUILD=1 cargo build -p bravebot-cli) and use a scratch directory or project so real declarations are untouched.bravebot mcp add srv --tools fetch,search --exclude-tools delete -- /opt/srvand answernat the question. Observe linestools: fetch, searchandexclude tools: deleteabove the digest line.--tools=fetch,search,--tools fetch search, and an--http https://mcp.example.com/mcpdeclaration with the same flags are each accepted.bravebot mcp add srv --tools -- /opt/srv, then with--tools=and with--tools ''. Each is refused with "needs a tool name or a comma-separated list". The same holds for--exclude-tools.bravebot mcp add srv --tools 'not a valid tool name' -- /opt/srv. Observe refusal saying the name is not a tool name.--exclude-tools get_forecast, start a session and approve it. The tool confirmation card omits that tool and reports "one tool was withheld by the server's allow or deny list".--tools get_alerts --exclude-tools get_alerts. Observe that no tools are offered and all tools are counted as withheld because deny wins.mcp.json. Observe that the server is asked about again on next session start, withtoolsorexclude_toolsnamed as changed.Test plan
python3 agents/skills/check-spec/check-spec.py --mechanical-only(passes with 0 errors across 80 specs and 1037 clauses).python3 contrib/check-locales.py(passes with 0 new gaps).cargo fmt --all -- --check(passes cleanly).BRAVEBOT_ALLOW_UNCONFIGURED_BUILD=1 cargo clippy -p bravebot-cli -p bravebot-agent -p bravebot-config -p bravebot-mcp -p bravebot-approval -p bravebot-tui -p bravebot-ui-bridge --all-targets --all-features -- -D warnings(passes with 0 warnings).BRAVEBOT_ALLOW_UNCONFIGURED_BUILD=1 cargo test -p bravebot-config(554 tests pass).BRAVEBOT_ALLOW_UNCONFIGURED_BUILD=1 cargo test -p bravebot-mcp(20 tests pass).BRAVEBOT_ALLOW_UNCONFIGURED_BUILD=1 cargo test -p bravebot-approval(8 tests pass).BRAVEBOT_ALLOW_UNCONFIGURED_BUILD=1 cargo test -p bravebot-agent(tests pass, includinghandshake_local_filters_tools_by_allow_and_deny_listsandwithheld_mcp_tools_are_not_offered_and_reported_in_confirmation).BRAVEBOT_ALLOW_UNCONFIGURED_BUILD=1 cargo test -p bravebot-cli --bin bravebot mcp(45 tests pass).Thank you very much!