Repository navigation
feat(mcp): add operator tool selection - #1669
pompiliodonatoapp wants to merge 3 commits into
Conversation
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]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
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. |
|
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. TestsAll exit codes were 0.
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 Real stdio clientNode 24.18.0, with the tree's own MCP client 2.3.1.
Three things the PR text does not say:
Size and timeNode 24.18.0, 5 runs each, median.
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
Tool counts per setting
CommandsTest setup🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
@greptileai review |
|
| const effects = TOOL_EFFECTS[name]; | ||
| if (effects === undefined) return false; | ||
| if (deniedEffects.value.some((effect) => effects[effect])) return false; |
There was a problem hiding this 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.
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.|
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. |
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]>
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]>
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]>
Summary
Operators can now narrow the MCP tool inventory at startup with
REA_MCP_TOOLSETS,REA_MCP_DENY_EFFECTSandREA_MCP_DENY_TOOLS. With noneset, behavior is unchanged:
tools/liststill returns the complete canonicalinventory (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_blockedfailure describedin
docs/installation.md) and least-privilege setups where a workspace shouldnot 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.tspartitions the public inventory into tentoolsets:
core,process,native,artifacts,evm,managed,android,firmware,web,javascript.processtoolset;
inspect_analysis_viewand reconstruction accounting go incore.coreis always retained.src/config/mcpToolSelection.tsparses the three settings into onepredicate.
REA_MCP_DENY_TOOLSare rejected, so a typo neverleaves a tool registered.
EvidenceMcpServer.registerToolremoves a deselected tool right afterregistration, before any client connects. The SDK guards the list-change
notification while disconnected.
parseConfigvalidates the selection at startup, so an invalid value exitswith a message naming the setting. Previously an error raised inside the
stdio factory would surface as a lost connection.
binary_sessiontool_availabilityomits deselected tools, andrea mcp doctorcompares 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
(
createServer→EvidenceMcpServer); configuration parsing.tools/listadvertises a subset, andtools/callon a removed tool returnsJSON-RPC
-32602(unknown tool). The catalog digest still identifies thecanonical catalog.
reduces the offered surface only; documented as not a sandbox.
(
npm run docs:checkpasses).Evidence and regression coverage
Tests added or updated:
tests/conformance/contracts/mcpToolSelection.test.ts(20 tests): thepartition covers every public tool exactly once; grouping; parsing; fail
closed; the documented example.
tests/boundary/mcp/toolSelectionMcp.test.ts(4 tests):tools/listsubset;
-32602without reaching the handler; production composition;binary_sessioninventory equals the advertised tools.src/config.test.ts: startup rejection naming each setting.Base reproduction or other evidence: not applicable (feature).
User-visible output:
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 moduleboundaries).
npm run verify:test-discovery: discovered all 797 test files exactly once.npm run docs:check: passed.Focused tests, 79 in all, passed:
src/config.test.ts;CapabilityInventory.test.ts;Built stdio server:
rea mcp doctor --jsonwithREA_MCP_TOOLSETS=web,javascript,artifactsandREA_MCP_DENY_TOOLS=capture_electron_scenarioreported healthy, 56/56tools. One cold first run after the build exceeded the doctor deadline in
binary_session; the next runs were healthy.REA_MCP_TOOLSETSvalue exits 1 with the message above.Timing with the same client, two runs per mode:
tools/listbinary_sessionOn the previous base
ac9677bd, with the same commit content:npm run test:fast: 3,869 passed, 59 failed. The failing files were re-runon a clean worktree of
ac9677bd:?/#filenames on NTFS, macOS-only providers);
ProcessHarnesscase, which fails about 1 in 4runs on both revisions.
npx vitest run --project mcp-boundary: 326 passed, 10 failed.serverIdentity,serverWorkflowMcp,sessionMcp,toolErrorSchemaDelivery,dylibResolutionMcpandelectronMcpcases (Windows timeouts and symlinks).contractPresentationandtoolSchemaValiditypass afternpm run test:prepare.npm run verify:architecture-guards: passed.npm run knip: reported onlylint-staged(package.jsonand.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
not run locally.
documented that selection limits which tools a model can request and does
not sandbox the remaining ones.
🤖 Generated with Claude Code