Skip to content

feat(mcp): add operator tool selection - #1669

Closed
pompiliodonatoapp wants to merge 3 commits into
morluto:mainfrom
pompiliodonatoapp:feat/operator-tool-selection
Closed

pompiliodonatoapp wants to merge 3 commits into
morluto:mainfrom
pompiliodonatoapp:feat/operator-tool-selection

Conversation

@pompiliodonatoapp

Copy link
Copy Markdown
Contributor

Summary

Operators can now narrow the MCP tool inventory at startup with
REA_MCP_TOOLSETS, REA_MCP_DENY_EFFECTS and REA_MCP_DENY_TOOLS. With none
set, behavior is unchanged: tools/list still returns the complete canonical
inventory (170 tools at this base).

No existing issue is linked. This is proposed as an enhancement. The
motivation is the documented static-context cost of the full inventory (for
example the Copilot CLI compaction_static_context_blocked failure described
in docs/installation.md) and least-privilege setups where a workspace should
not offer tools that run caller commands or control devices.

Problem and expected behavior

A workspace that only studies web and JavaScript artifacts currently advertises
native, Android device, firmware and process-capture tools as well. Expected:
an operator can register only the toolsets a workspace needs, and a removed
tool can be neither listed nor invoked.

Change and scope

  • src/contracts/toolsets.ts partitions the public inventory into ten
    toolsets: core, process, native, artifacts, evm, managed,
    android, firmware, web, javascript.
    • The partition follows the contract families, with purpose-based exceptions:
      • process capture, which runs caller commands, gets its own process
        toolset;
      • the Android and Apple graph projections go with their package toolsets;
      • inspect_analysis_view and reconstruction accounting go in core.
    • core is always retained.
  • src/config/mcpToolSelection.ts parses the three settings into one
    predicate.
    • Toolsets apply first, then denied effects, then denied tools.
    • Denied effects fail closed for tools without declared effects.
    • Unknown tool names in REA_MCP_DENY_TOOLS are rejected, so a typo never
      leaves a tool registered.
  • EvidenceMcpServer.registerTool removes a deselected tool right after
    registration, before any client connects. The SDK guards the list-change
    notification while disconnected.
  • parseConfig validates the selection at startup, so an invalid value exits
    with a message naming the setting. Previously an error raised inside the
    stdio factory would surface as a lost connection.
  • binary_session tool_availability omits deselected tools, and
    rea mcp doctor compares against the selected inventory.

Intentionally not included: per-call authorization, runtime toggling, and
filtering guided prompts (prompts that name a removed tool remain listed, as
documented).

Contract and boundary impact

  • Semantic owner and earliest changed stage: server composition
    (createServer → EvidenceMcpServer); configuration parsing.
  • CLI and MCP/tool-catalog contract: unchanged when unset. When set,
    tools/list advertises a subset, and tools/call on a removed tool returns
    JSON-RPC -32602 (unknown tool). The catalog digest still identifies the
    canonical catalog.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Process execution, authorization, cleanup, or containment impact:
    reduces the offered surface only; documented as not a sandbox.
  • Generated metadata, package, or installation impact: none
    (npm run docs:check passes).

Evidence and regression coverage

  • Tests added or updated:

    • tests/conformance/contracts/mcpToolSelection.test.ts (20 tests): the
      partition covers every public tool exactly once; grouping; parsing; fail
      closed; the documented example.
    • tests/boundary/mcp/toolSelectionMcp.test.ts (4 tests): tools/list
      subset; -32602 without reaching the handler; production composition;
      binary_session inventory equals the advertised tools.
    • src/config.test.ts: startup rejection naming each setting.
  • Base reproduction or other evidence: not applicable (feature).

  • User-visible output:

    $ REA_MCP_TOOLSETS=browser rea mcp
    REA configuration is invalid: REA_MCP_TOOLSETS must be a comma-separated list of toolsets: core, process, native, artifacts, evm, managed, android, firmware, web, javascript. The core toolset is always retained.
    (exit 1)
    
    $ REA_MCP_TOOLSETS=web,javascript,artifacts REA_MCP_DENY_TOOLS=capture_electron_scenario rea mcp doctor --json
    healthy: true; inventory:tools expected=56 observed=56 missing=none unexpected=none duplicates=none
    
  • Remaining proof gaps: the Linux CI lanes and real-browser/provider lanes
    were not run (see below).

Validation performed

All runs below were on Windows 11 x64 with Node 22.22.3.

On this branch (base 31bfff6f):

  • npm ci, npm run typecheck: passed.

  • npm run check:fast: passed (typecheck and lint, including module
    boundaries).

  • npm run verify:test-discovery: discovered all 797 test files exactly once.

  • npm run docs:check: passed.

  • Focused tests, 79 in all, passed:

    • the selection conformance and boundary tests;
    • src/config.test.ts;
    • CapabilityInventory.test.ts;
    • the compact input schema profile tests.
  • Built stdio server:

    • rea mcp doctor --json with
      REA_MCP_TOOLSETS=web,javascript,artifacts and
      REA_MCP_DENY_TOOLS=capture_electron_scenario reported healthy, 56/56
      tools. One cold first run after the build exceeded the doctor deadline in
      binary_session; the next runs were healthy.
    • An invalid REA_MCP_TOOLSETS value exits 1 with the message above.
  • Timing with the same client, two runs per mode:

    Mode Tools tools/list First binary_session Connect
    Full 170 2.8–3.2 s 21–24 s about 15–17 s
    Selected 56 1.4–1.7 s 15–16 s about 15–17 s

On the previous base ac9677bd, with the same commit content:

  • npm run test:fast: 3,869 passed, 59 failed. The failing files were re-run
    on a clean worktree of ac9677bd:
    • all fail identically there (missing Windows native manifest, ?/#
      filenames on NTFS, macOS-only providers);
    • except a timing-sensitive ProcessHarness case, which fails about 1 in 4
      runs on both revisions.
  • npx vitest run --project mcp-boundary: 326 passed, 10 failed.
    • The base fails the same serverIdentity, serverWorkflowMcp,
      sessionMcp, toolErrorSchemaDelivery, dylibResolutionMcp and
      electronMcp cases (Windows timeouts and symlinks).
    • contractPresentation and toolSchemaValidity pass after
      npm run test:prepare.
  • npm run verify:architecture-guards: passed.
  • npm run knip: reported only lint-staged (package.json and
    .husky/pre-commit), which this change does not touch.

The Linux CI lanes and the real browser/provider lanes were not run locally.

Compatibility, safety, and release

  • Breaking changes or migration steps: none; all settings are opt-in.
  • Real Hopper/Ghidra, browser, or OS coverage: Windows 11 only; Linux CI
    not run locally.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: narrowing only;
    documented that selection limits which tools a model can request and does
    not sandbox the remaining ones.

🤖 Generated with Claude Code

Add three startup settings that narrow the registered MCP inventory:

- REA_MCP_TOOLSETS selects toolsets (core, process, native, artifacts,
  evm, managed, android, firmware, web, javascript); core is always
  retained. Process capture, which runs caller commands, is its own
  toolset; package graph projections live with their package toolsets
  and reconstruction accounting lives in core.
- REA_MCP_DENY_EFFECTS removes tools whose declared effects include a
  denied effect, failing closed for tools without declared effects.
- REA_MCP_DENY_TOOLS removes named tools and rejects unknown names so a
  misspelled denial never leaves a tool registered.

A deselected tool is removed before any client connects: tools/list does
not advertise it, tools/call rejects it as unknown (-32602) without
reaching its handler, binary_session omits it from tool_availability, and
`rea mcp doctor` expects the selected inventory. Invalid values fail
configuration parsing at startup with a message naming the setting.
With none set, the complete inventory is unchanged.

Validation: typecheck; conformance and mcp-boundary selection tests;
end-to-end stdio check against the built server on Windows 11 (web,
javascript, artifacts selection advertises 56 of 170 tools; doctor
healthy). Real browser and provider lanes were not run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

We previously had a search + execute system but most clients now have some form of lazy loading so the number of tools doesn't really affect things.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: On Linux, the three settings narrow the tool list as the PR describes. With nothing set, the list is byte for byte the same as the parent commit. A hidden tool is refused when called by name, and the smallest toolset cuts the list from 1.9 MB to 0.2 MB.

Thanks, pompiliodonatoapp, for the PR and its tests. The branch sits on 31bfff6, ten commits behind f88c990. I tested head 017a5cb against 31bfff6. I also applied the patch on f88c990 and tested that.

Tests

All exit codes were 0.

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
src/config.test.ts and mcpToolSelection.test.ts (2 files) 51 passed 51 passed 51 passed
toolSelectionMcp.test.ts (1 file) 4 passed 4 passed 4 passed

On Node 24.18.0 with the patch on f88c990, the same two commands passed 51 and 4. With nothing set, that tree lists 170 tools, byte for byte the same as f88c990 alone. The patch applied with one line of fuzz in parseConfig.ts. GitHub reports the PR as mergeable, with merge state BLOCKED. It shows no review decision and no checks.

Real stdio client

Node 24.18.0, with the tree's own MCP client 2.3.1.

Check Result
Nothing set 170 tools. Same names, same order and same definitions as the base 31bfff6.
Each toolset alone 10 tried, from 22 to 87 tools. Counts are in the fold below.
Each effect denied alone 7 tried, from 6 to 165 tools. Counts are in the fold below.
All configurations 32 tried: nothing set, 10 toolsets, 7 effects, 4 tool lists, 10 mixes and variants.
Listed tools Each count matched a list I rebuilt from the docs and the PR's own tables.
Hidden tool called by name 30 configurations hide tools. Every hidden tool got -32602 "Tool NAME not found". None returned a result. A made-up name gets the same message.
Listed tool, empty arguments None came back as unknown. Most stopped at input checks or "No app is open". Seven ran.
Bad values 20 of 23 stopped at startup with exit 1. The message names the setting.
Refused values Empty, spaces only, empty item, WEB, idempotent, __proto__.
binary_session tool_availability lists exactly the listed tools (170, 56 and 22 tried).
rea mcp doctor Healthy with 170/170, 56/56 and 22/22.
JavaScript flow With only javascript (35 tools), analyze_javascript_application ran on a four-file folder. The result matched the full inventory on 31bfff6 byte for byte. inspect_analysis_view then worked. With only web, the same call gets -32602.

Three things the PR text does not say:

  • An unknown name in REA_MCP_DENY_TOOLS is refused, but the startup message does not name it. It says "must be a comma-separated list of public tool names". The PR builds an "Unknown tools" tail. The message printer in src/domain/analysisErrorPresentation.ts prints only each setting's constraint, so the tail is dropped.
  • REA_MCP_DENY_TOOLS=binary_session is accepted. The server then has no session status tool (169 tools).
  • Duplicates in all three lists are accepted. So is space around a name.

Size and time

Node 24.18.0, 5 runs each, median.

Mode Tools List size (bytes) Server start (ms) tools/list (ms) Spawn to first list (ms)
Nothing set, 31bfff6 170 1,944,945 1233 259 1487
Nothing set, 017a5cb 170 1,944,945 1277 268 1549
web 37 533,560 1254 88 1343
PR example, 3 toolsets and 1 tool denied 56 880,743 1251 137 1383
core 22 235,711 1238 46 1285

Server start is the time to finish the MCP handshake. It stays near 1.2 to 1.3 seconds. The list itself gets smaller and quicker. The byte counts come from the JSON text of the list, not the wire. I don't know how this maps to model tokens.

Not run

  • Any real MCP client. The lazy-loading point on this PR is not tested here.
  • Windows, macOS, and the Linux CI lanes.
  • The full test suites, typecheck, lint and docs:check.
  • Real inputs for listed tools, other than the JavaScript flow.
  • Real Hopper, Ghidra, browser and device runs.
  • A tool with no declared effects under REA_MCP_DENY_EFFECTS. All 170 tools declare effects at this head, so that branch has no case.
  • A merge onto the current main tip.
Tool counts per setting
Setting Tools listed
Toolset core 22
Toolset process 24
Toolset native 87
Toolset artifacts 29
Toolset evm 23
Toolset managed 29
Toolset android 58
Toolset firmware 24
Toolset web 37
Toolset javascript 35
Deny mutatesTarget 153
Deny mutatesSession 6
Deny writesFilesystem 138
Deny launchesProcess 114
Deny accessesNetwork 125
Deny changesUiState 165
Deny mayDiscardData 163
Commands
npm ci; npm run build; npm run test:prepare          (Node 24.18.0, each tree)
npm run test:local -- src/config.test.ts tests/conformance/contracts/mcpToolSelection.test.ts
npm run test:focused -- tests/boundary/mcp/toolSelectionMcp.test.ts
REA_MCP_TOOLSETS=web node scripts/rea.mjs mcp          (driven by the tree's MCP client over stdio)
REA_MCP_TOOLSETS=web,javascript,artifacts REA_MCP_DENY_TOOLS=capture_electron_scenario node scripts/rea.mjs mcp doctor --json
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head / base: 017a5cb / f88c990 (the PR head, then the base)

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

[High impact] Adds operator control over which tools the server registers.

The PR should not merge until JavaScript analysis honors the operator's denied effects.

Findings

  1. P1 Security JavaScript analysis bypasses effect denials ▶
Fix with agent prompt
### Issue 1
src/config/mcpToolSelection.ts:106-108
`REA_MCP_DENY_EFFECTS=launchesProcess` or `writesFilesystem` still retains `analyze_javascript_application`. Its `TOOL_EFFECTS` entry uses `evidence`, which declares neither effect. But analyzing a directory containing JavaScript starts a Node worker and writes temporary source files. The new filter therefore offers a tool that performs the operator's denied actions.

Declare both effects and add a regression check against the actual worker behavior.

**How this was verified:** The registered handler reaches `JavaScriptAnalysisWorker`, which launches `process.execPath` and writes the supplied source into a temporary directory.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds startup tool selection through REA_MCP_TOOLSETS, REA_MCP_DENY_EFFECTS, and REA_MCP_DENY_TOOLS.

  • Operators can choose which MCP tool groups REA offers.
  • MCP clients only see and can call the tools an operator selected.
  • rea mcp doctor checks the tool inventory selected for startup.

Source checks only; automated tests were not run during this review. Whether another PR supersedes this one could not be checked because GitHub access was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Startup environment] --> B[Parse tool selection]
  B --> C[Select toolsets plus core]
  C --> D[Remove tools with denied effects]
  D --> E[Remove explicitly denied tools]
  E --> F[Registered MCP tools]
  F --> G[tools/list and tools/call]
  E --> H[binary_session availability]
  E --> I[Doctor expected inventory]
Loading

Reviews (3) · Last reviewed commit: "fix(mcp): decouple effect algebra fixtur..." · Reviewed by Greptile

Comment thread src/config/mcpToolSelection.ts Resolved
Comment thread src/mcpDoctor.ts Resolved
Comment on lines +106 to +108
const effects = TOOL_EFFECTS[name];
if (effects === undefined) return false;
if (deniedEffects.value.some((effect) => effects[effect])) return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 security JavaScript analysis bypasses effect denials

REA_MCP_DENY_EFFECTS=launchesProcess or writesFilesystem still retains analyze_javascript_application. Its TOOL_EFFECTS entry uses evidence, which declares neither effect. But analyzing a directory containing JavaScript starts a Node worker and writes temporary source files. The new filter therefore offers a tool that performs the operator's denied actions.

Declare both effects and add a regression check against the actual worker behavior.

How this was verified: The registered handler reaches JavaScriptAnalysisWorker, which launches process.execPath and writes the supplied source into a temporary directory.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/config/mcpToolSelection.ts
Line: 106-108

Comment:
**JavaScript analysis bypasses effect denials**

`REA_MCP_DENY_EFFECTS=launchesProcess` or `writesFilesystem` still retains `analyze_javascript_application`. Its `TOOL_EFFECTS` entry uses `evidence`, which declares neither effect. But analyzing a directory containing JavaScript starts a Node worker and writes temporary source files. The new filter therefore offers a tool that performs the operator's denied actions.

Declare both effects and add a regression check against the actual worker behavior.

**How this was verified:** The registered handler reaches `JavaScriptAnalysisWorker`, which launches `process.execPath` and writes the supplied source into a temporary directory.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment thread src/contracts/toolEffects.ts Resolved
@cursor

cursor Bot commented Oct 13, 2026

Copy link
Copy Markdown

Closing this. Clients lazy-load tools, so a separate operator tool-selection layer does not change what an agent can reach. We previously had a search-and-execute system and dropped it for the same reason.

@morluto morluto closed this Oct 13, 2026
morluto added a commit that referenced this pull request Oct 13, 2026
Recover the isolated effect metadata correction identified in #1669. Keep the generic annotation-algebra fixture independent of operation-specific effects.

Co-authored-by: Pompilio Donato <[email protected]>
morluto added a commit that referenced this pull request Oct 13, 2026
Recover the isolated effect metadata correction identified in #1669. Keep the generic annotation-algebra fixture independent of operation-specific effects.

Co-authored-by: Pompilio Donato <[email protected]>
morluto added a commit that referenced this pull request Oct 13, 2026
Recover the isolated effect metadata correction identified in #1669. Keep the generic annotation-algebra fixture independent of operation-specific effects.

Co-authored-by: Pompilio Donato <[email protected]>
@morluto morluto added enhancement New feature or request area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added the area: mcp MCP server, transport, and tool registration label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants