Repository navigation
Fix: mcp development mode policy - #994
will-lamerton merged 5 commits into
Conversation
MCP tools hand-rolled their own approval predicate instead of using the
central mode system, which failed in both directions from one root cause:
const isAutoApproved = this.isToolAutoApproved(toolName, serverName);
const approval: ToolApprovalPolicy = isAutoApproved
? false
: (_args, mode) => mode !== 'auto-accept';
An alwaysAllow-ed tool collapsed to `approval: false`, which resolver rule
Nano-Collective#3 reads as "no approval" in every mode - so plan mode executed mutating
MCP tools with no prompt, breaking its "show tool calls but don't execute"
contract. Anything else evaluated 'headless' !== 'auto-accept' to true and
required approval in headless, where no approval handler exists, so
daemon-triggered runs were denied with "Tool execution was denied by the
user" when no user was present.
Two supporting gaps let this reach the user: MODE_EXCLUDED_TOOLS.plan can
only ever list built-in names, and the plan/headless filter consulted only
customTools, so `if (!meta) return true` waved MCP tools straight through.
Replace the predicate with one that takes the same posture as built-in
tools, and carry the server's annotations.readOnlyHint onto the tool entry
so plan mode can tell a reader from a mutator. Plan mode now gates MCP
tools on that annotation instead of an enumeration it can never hold; an
absent hint fails safe to "may mutate". A server's alwaysAllow list no
longer short-circuits ahead of every other rule - it applies in normal
mode only, and can no longer override plan.
Headless is left to run MCP tools unattended, matching execute_bash and
createFileToolApproval in @/utils/tool-approval.
Fixes Nano-Collective#989
Plan mode now hides MCP tools that their server has not annotated read-only, which is user-visible: an MCP tool that used to appear while planning no longer will unless the server sets readOnlyHint. Record that in the plan-mode tool list, and point at the alwaysAllow docs, which already said the list applies in normal mode only.
ebd396d to
1744975
Compare
will-lamerton
left a comment
There was a problem hiding this comment.
Thanks for this - the diagnosis is right and the direction is correct. MCP shouldn't own a private copy of the approval policy. Two things to address before merge.
1. readOnlyHint now skips approval in normal mode
if (readOnly) return false; is the first branch, so it applies in normal mode too. Any tool whose server sets readOnlyHint: true now executes silently where it previously prompted. That contradicts docs/configuration/mcp-configuration.md:220 ("Tools not listed still require approval"), the same doc the PR cites for the alwaysAllow change, and it trusts a server-supplied hint to gate the server itself. The MCP spec treats annotations as untrusted hints for exactly that reason.
None of the bugs being fixed need it. Scoping the short-circuit keeps every fix and leaves normal mode alone:
const approval: ToolApprovalPolicy = (_args, mode) => {
if (mode === 'auto-accept' || mode === 'headless') return false;
if (mode === 'plan') return !readOnly;
return !isAutoApproved; // normal: alwaysAllow only, as documented
};2. The annotation plumbing has no coverage
MCPClient: readOnlyHint is read from server annotations re-implements the mapping inside the test and writes the result straight into serverTools, so production code never runs. I replaced mcp-client.ts:172 with readOnly: undefined and all 136 tests across both touched specs still passed. The one line that makes the feature work is untested. Could you drive it through connectToServer with a stub listTools returning annotations: {readOnlyHint: true}, or extract the mapping so a test can call it directly?
Smaller items:
tool-manager.ts:207can use the existingthis.isReadOnly(n)instead of reaching intothis.registry.getEntry(n)?.readOnly.getToolMapping()rebuilds a Map on everygetAvailableToolNamescall in plan mode, which runs on both prompt building and per-turn runtime. Worth caching on the client.docs/configuration/mcp-configuration.mdisn't touched, but its "Auto-Approve Tools" bullets are now wrong in two ways:alwaysAllowno longer applies in plan, and it doesn't apply in headless either. Worth a line there alongside thedevelopment-modes.mdupdate.- Headless now runs every MCP tool unattended with no per-server opt-out, while custom tools in the same filter still need
approval === 'never'. That matchesexecute_bashand is what #989 asked for, but the asymmetry deserves a mention in the MCP docs.
Verified locally: both touched specs pass (51 + 85), tsc --noEmit clean, biome clean on the production files.
…-mode-policy Conflict in docs/features/development-modes.md: upstream reworded the plan mode exclusion list (adding write_tasks / write_walkthrough) and renamed the heading to "The Plan -> Review -> Execute Workflow" in the same place this branch inserted its MCP paragraph. Kept both: upstream's exclusion list and heading, with the MCP read-only gating note between them.
Review follow-ups on the development-mode policy fix.
readOnlyHint no longer skips approval in normal mode. `if (readOnly)
return false` was the first branch of the approval predicate, so any tool
whose server annotated it read-only executed silently where it previously
prompted. That contradicted mcp-configuration.md ("Tools not listed still
require approval") and let a server's own hint gate the server itself —
the MCP spec treats annotations as untrusted for exactly that reason.
None of the bugs being fixed needed it. The short-circuit is now scoped:
if (mode === 'auto-accept' || mode === 'headless') return false;
if (mode === 'plan') return !readOnly;
return !isAutoApproved; // normal: alwaysAllow only, as documented
readOnlyHint decides plan-mode availability; the user's alwaysAllow list
stays the only way to skip a normal-mode prompt.
The annotation plumbing is now actually covered. The previous test
re-implemented the mapping in its own body and wrote the result straight
into serverTools, so mcp-client.ts never ran — replacing the mapping with
`readOnly: undefined` left every test passing. It is replaced by a test
driven through connectToServer() with a stubbed listTools(), asserting the
flag lands on both the discovered MCPTool records and the registry entries
plan mode filters on, and that it decides plan mode end to end. Covers the
fail-safe cases too: absent annotations, annotations without the hint, and
a truthy-but-not-`true` hint. Gutting the mapping line now fails it.
Also:
- tool-manager uses the existing this.isReadOnly(n) rather than reaching
into this.registry.getEntry(n)?.readOnly.
- getToolMapping() memoises its Map instead of rebuilding it on every
getAvailableToolNames() call in plan mode (prompt building plus per
turn at runtime). Invalidated on connect and disconnect; the returned
Map is shared, and all three callers are read-only.
- mcp-configuration.md gains a per-mode table for alwaysAllow: it applies
in normal mode only, cannot override plan, and is irrelevant in
headless. Records that headless runs every MCP tool unattended with no
per-server opt-out — deliberately more permissive than custom tools,
which need approval: never — and points at "enabled": false as the
server-level gate.
…-mode-policy Catches the branch up to main to clear three CI failures, all caused by the branch being 20 commits behind rather than by anything in the diff: - "VS Code Extension" ran plugins/vscode/scripts/verify-theme-css.js, added by 01cabab (Tailwind v4 migration). That job checks out pull_request.head.sha, not the merge ref, so it ran main's workflow against a tree without the script. - "label" read .github/labeler.yml at pull_request.base.sha; the file arrived in c673eff, after this branch's merge base. - "Unit Tests & Coverage Analysis" compared coverage against main's badge (92.17%) while measuring a tree missing main's newer, covered code, so it reported a 92.03% drop. No conflicts. Merged clean.
|
Thanks @will-lamerton, 1. if (mode === 'auto-accept' || mode === 'headless') return false;
if (mode === 'plan') return !readOnly;
return !isAutoApproved; // normal: alwaysAllow only, as documentedThat's the whole fix, not half of one: the entry still carries 2. Annotation coverage. You were right that the old test proved nothing. Replaced with Smaller items. CI. The three failures were the branch sitting 20 commits behind |
|
Nice work again @addyCooks :) |
Follow-up to #994. The server-supplied `readOnlyHint` was copied onto each registered MCP tool entry, where `ToolManager.isReadOnly()` also decides whether ACP captures a checkpoint before the call (acp-timeline.ts) and whether the tool joins a parallel execution batch (tool-executor.tsx). A server annotating itself read-only could therefore talk its way out of a restore point — the same untrusted-hint problem the PR fixed for approval. The hint now travels on getToolMapping(), which only plan-mode filtering reads, so it decides availability and nothing else, exactly as the docs describe. `enabled: false` was loaded by the config loader and then ignored: every configured server connected regardless. It is the server-level gate the MCP docs point users at, and the only opt-out for headless runs where MCP tools execute unattended. Disabled servers are now skipped before any connection is attempted. Also covers the connect-side invalidation of the tool-mapping cache, which was untested — a mapping taken before the servers came up would have gone stale and made plan mode stop recognising MCP tools entirely.
|
Thanks @will-lamerton !! : ) |
Fixes #989
Description
MCP tools never participated in the development-mode policy that governs every other
tool.
mcp-client.tshand-rolled its own approval predicate:This failed in both directions from one root cause. An
alwaysAllow-ed tool collapsedto
approval: false, whichresolveToolApprovalrule3(boolean short-circuit) readsas "no approval" in every mode so plan mode executed mutating MCP tools with no prompt.
Anything else evaluated
'headless' !== 'auto-accept'totrueand demanded approval inheadless, where no approval handler exists (
tool-approval-queue.tsdefaults to() => false), so daemon-triggered runs were denied with a message blaming a user whowas never asked.
Two supporting gaps let it reach users:
MODE_EXCLUDED_TOOLS.plancan only ever holdbuilt-in names, and the plan/headless filter consulted only
customTools, soif (!meta) return truewaved MCP tools straight through.The fix
mcp-client.tsthe predicate now takes the same posture as built-in tools:Auto-accept and headless run unattended, matching
createFileToolApproval. Plan isgated on the server's annotation. Normal is unchanged from documented behaviour.
types/mcp.ts+mcp-client.tscarry the server'sannotations.readOnlyHintonto the tool entry. An absent hint fails safe to "may mutate". This decides plan-mode
availability only:
readOnlyHintis supplied by the very server being gated, so itnever skips a confirmation prompt in normal mode the user's
alwaysAllowlist staysthe only thing that does.
tool-manager.tsplan mode gates MCP tools on that annotation instead of anenumeration it can never hold. Headless deliberately untouched.
A server's
alwaysAllowno longer short-circuits ahead of every other rule it appliesin normal mode only, which is what
docs/configuration/mcp-configuration.mdalreadysaid. The code was violating its own documentation.
Docs
mcp-configuration.mdgains a per-mode table foralwaysAllow, and recordsthat headless runs every MCP tool unattended with no per-server opt-out (more permissive
than custom tools, which need
approval: never), with"enabled": falseas theserver-level gate.
development-modes.mdnotes the plan-mode rule.getToolMapping()is memoised plan mode called it on everygetAvailableToolNames(),both for prompt building and per turn at runtime.
Type of Change
Changeset
pnpm changeset) describing this change for the changelogTesting
Automated Tests
.spec.ts/tsxfilesRegression tests cover both directions of #989 (plan must not run an
alwaysAllow-edmutation; headless must not prompt), the normal-mode boundary (a server's
readOnlyHintmust not silence its own prompt, while
alwaysAllowstill does), and the annotation pathend to end driven through
connectToServer()with a stubbedlistTools()so themapping in
mcp-client.tsactually executes, including absent annotations, annotationswithout the hint, and a truthy-but-not-
truehint.Manual Testing
Checklist