Skip to content

fix: CLI --list-tools must honor BRAINCTL_ALLOWED_TOOLS (red-team)#139

Merged
TSchonleber merged 1 commit into
mainfrom
fix/redteam-cli-allowlist
May 20, 2026
Merged

fix: CLI --list-tools must honor BRAINCTL_ALLOWED_TOOLS (red-team)#139
TSchonleber merged 1 commit into
mainfrom
fix/redteam-cli-allowlist

Conversation

@TSchonleber
Copy link
Copy Markdown
Owner

Summary

Red-team of the freshly merged v2.8.0 surfaced two related bugs in the inspection path:

  1. brainctl-mcp --list-tools ignored BRAINCTL_ALLOWED_TOOLS. The allowlist was applied only in the async list_tools() handler (used by MCP clients), not in the CLI branch. An operator inspecting their config could think the server was locked down while clients saw a broader surface.
  2. --list-tools --all also bypassed the allowlist, not just the v2 visibility filter. --all is meant to show the full v1+v2 registered surface for debugging, but the operator's explicit security allowlist should never be silently dropped.

Repro (before fix)

$ BRAINCTL_ALLOWED_TOOLS=memory_add brainctl-mcp --list-tools | wc -l
100      # expected 1
$ BRAINCTL_ALLOWED_TOOLS=memory_add brainctl-mcp --list-tools --all | wc -l
370      # expected 1

After: both return 1.

Verification

  • pytest tests/test_mcp_allowed_tools.py -q20 passed (4 new tests in TestCLIListToolsConsistency)

Test plan

  • Allowlist + no flag → only allowlisted tools
  • Allowlist + --all → still only allowlisted tools
  • No allowlist + no flag → all visible v2 tools
  • No allowlist + --all → full registered surface

Red-team of v2.8.0 surfaced two related bugs in the inspection path:

  1. `BRAINCTL_ALLOWED_TOOLS=memory_add brainctl-mcp --list-tools`
     printed all 100 visible tools, not just `memory_add`. The
     allowlist was applied in the async `list_tools()` handler
     (used by MCP clients) but not in the CLI inspection path.
     Result: an operator could think their server was locked down
     while clients saw a different (broader) surface.

  2. `--list-tools --all` was meant to bypass only the v2
     visibility filter (so debuggers can see the full v1+v2
     surface), but it also silently bypassed the operator's
     allowlist. An admin using `--all` to inspect would see tools
     that the server would actually refuse to call.

The fix applies _ALLOWED_TOOLS in the CLI branch as well, with
`--all` only bypassing _VISIBLE_TOOL_NAMES (the v2 filter), never
the operator's explicit allowlist.

Regression coverage added in TestCLIListToolsConsistency with four
cases: allowlist+no-flag, allowlist+--all, no-allowlist+no-flag,
no-allowlist+--all.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@TSchonleber TSchonleber merged commit f9d8dc6 into main May 20, 2026
8 checks passed
@TSchonleber TSchonleber deleted the fix/redteam-cli-allowlist branch May 20, 2026 14:56
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.

1 participant