Skip to content

Fix: mcp development mode policy - #994

Merged
will-lamerton merged 5 commits into
Nano-Collective:mainfrom
addyCooks:fix/mcp-development-mode-policy
Sep 6, 2026
Merged

will-lamerton merged 5 commits into
Nano-Collective:mainfrom
addyCooks:fix/mcp-development-mode-policy

Conversation

@addyCooks

@addyCooks addyCooks commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #989

Description

MCP tools never participated in the development-mode policy that governs every other
tool. mcp-client.ts hand-rolled its own approval predicate:

const isAutoApproved = this.isToolAutoApproved(toolName, serverName);
const approval: ToolApprovalPolicy = isAutoApproved
    ? false
    : (_args, mode) => mode !== 'auto-accept';

This failed in both directions from one root cause. An alwaysAllow-ed tool collapsed
to approval: false, which resolveToolApproval rule 3 (boolean short-circuit) reads
as "no approval" in every mode so plan mode executed mutating MCP tools with no prompt.
Anything else evaluated 'headless' !== 'auto-accept' to true and demanded approval in
headless, where no approval handler exists (tool-approval-queue.ts defaults to
() => false), so daemon-triggered runs were denied with a message blaming a user who
was never asked.

Two supporting gaps let it reach users: MODE_EXCLUDED_TOOLS.plan can only ever hold
built-in names, and the plan/headless filter consulted only customTools, so
if (!meta) return true waved MCP tools straight through.

The fix

  • mcp-client.ts the predicate now takes the same posture as built-in tools:

    if (mode === 'auto-accept' || mode === 'headless') return false;
    if (mode === 'plan') return !readOnly;
    return !isAutoApproved; // normal: alwaysAllow only, as documented

    Auto-accept and headless run unattended, matching createFileToolApproval. Plan is
    gated on the server's annotation. Normal is unchanged from documented behaviour.

  • types/mcp.ts + mcp-client.ts carry the server's annotations.readOnlyHint
    onto the tool entry. An absent hint fails safe to "may mutate". This decides plan-mode
    availability only: readOnlyHint is supplied by the very server being gated, so it
    never skips a confirmation prompt in normal mode the user's alwaysAllow list stays
    the only thing that does.

  • tool-manager.ts plan mode gates MCP tools on that annotation instead of an
    enumeration it can never hold. Headless deliberately untouched.

  • A server's alwaysAllow no longer short-circuits ahead of every other rule it applies
    in normal mode only, which is what docs/configuration/mcp-configuration.md already
    said. The code was violating its own documentation.

  • Docs mcp-configuration.md gains a per-mode table for alwaysAllow, and records
    that headless runs every MCP tool unattended with no per-server opt-out (more permissive
    than custom tools, which need approval: never), with "enabled": false as the
    server-level gate. development-modes.md notes the plan-mode rule.

  • getToolMapping() is memoised plan mode called it on every getAvailableToolNames(),
    both for prompt building and per turn at runtime.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass
  • Tests cover both success and error scenarios

Regression tests cover both directions of #989 (plan must not run an alwaysAllow-ed
mutation; headless must not prompt), the normal-mode boundary (a server's readOnlyHint
must not silence its own prompt, while alwaysAllow still does), and the annotation path
end to end driven through connectToServer() with a stubbed listTools() so the
mapping in mcp-client.ts actually executes, including absent annotations, annotations
without the hint, and a truthy-but-not-true hint.

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging

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.
@addyCooks
addyCooks force-pushed the fix/mcp-development-mode-policy branch from ebd396d to 1744975 Compare August 28, 2026 12:30

@will-lamerton will-lamerton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:207 can use the existing this.isReadOnly(n) instead of reaching into this.registry.getEntry(n)?.readOnly.
  • getToolMapping() rebuilds a Map on every getAvailableToolNames call in plan mode, which runs on both prompt building and per-turn runtime. Worth caching on the client.
  • docs/configuration/mcp-configuration.md isn't touched, but its "Auto-Approve Tools" bullets are now wrong in two ways: alwaysAllow no longer applies in plan, and it doesn't apply in headless either. Worth a line there alongside the development-modes.md update.
  • 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 matches execute_bash and 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.
@github-actions github-actions Bot added area:tools Tool implementations and tool-calling area:docs Documentation labels Sep 1, 2026
@addyCooks

Copy link
Copy Markdown
Collaborator Author

Thanks @will-lamerton,
all addressed in 0eec51d.

1. readOnlyHint in normal mode. Took your predicate as written:

if (mode === 'auto-accept' || mode === 'headless') return false;
if (mode === 'plan') return !readOnly;
return !isAutoApproved; // normal: alwaysAllow only, as documented

That's the whole fix, not half of one: the entry still carries readOnly, but rule #4
(function policy) resolves ahead of #5, and MCP always supplies a function so #5 never
fired for MCP in the first place. The PR description was wrong to claim it did; corrected.
A comment now records why the order matters.

2. Annotation coverage. You were right that the old test proved nothing. Replaced with
one driven through connectToServer() and a stubbed listTools(), asserting the flag lands
on the discovered records and the registry entries plan mode filters on. Absent
annotations, annotations without the hint, and a truthy-but-not-true hint are covered too.
Your probe now fails it:

# readOnly: tool.annotations?.readOnlyHint === true  ->  readOnly: undefined
not ok 51 - MCPClient.connectToServer: carries annotations.readOnlyHint onto discovered tools

Smaller items. isReadOnly(n) done. getToolMapping() memoised, invalidated on
connect/disconnect; the Map is now shared by reference and documented read-only (all three
callers only get/has). mcp-configuration.md gains a per-mode table alwaysAllow is
normal-mode only and can't override plan plus the headless asymmetry, with "enabled": false
as the server-level gate.

CI. The three failures were the branch sitting 20 commits behind main, not the diff
(the VS Code job checks out head.sha; the labeler reads labeler.yml at base.sha; coverage
compared against a newer baseline). Merged main, no conflicts all 14 checks green, coverage
92.2% vs the 92.17% baseline.

@will-lamerton

Copy link
Copy Markdown
Member

Nice work again @addyCooks :)

@will-lamerton
will-lamerton merged commit dae98bf into Nano-Collective:main Sep 6, 2026
14 checks passed
will-lamerton added a commit that referenced this pull request Sep 6, 2026
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.
@addyCooks

Copy link
Copy Markdown
Collaborator Author

Thanks @will-lamerton !! : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Documentation area:tools Tool implementations and tool-calling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] MCP tools bypass development-mode policy: execute in plan mode, auto-denied in headless

2 participants