Skip to content

mcpx: operator-declared readOnlyTools + typed gate refusals (#6116) - #6265

Merged
dezren39 merged 1 commit into
mainfrom
fix/mcpx-6116-readonly-tools
Nov 5, 2026
Merged

dezren39 merged 1 commit into
mainfrom
fix/mcpx-6116-readonly-tools

Conversation

@dezren39

@dezren39 dezren39 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Fixes #6116.

Where the gate lives

The gate is in the mcpx daemon (pkgs/mcpx, this repo) -- not OpenCode, not an OpenCode session permission or form. Two layers in internal/daemon/consumer.go:

  • applyWritePolicy: policy.write defaults to ask (internal/defaults/defaults.json). A call is a write unless its tool is annotated readOnlyHint: true, read with the specification's defaults.
  • confirmDestructive: the elicit.confirmDestructive floor (off by default).

fff-mcp publishes no annotations at all (verified live: find_files/grep/multi_grep all annotations: null), so every fff call classifies as a possibly-destructive write and is gated under the default ask policy. Interactive callers can answer the broker question; headless/API sessions cannot, so every projected call returned … may be destructive and was not confirmed: nobody answered within 45s -- as a 502, indistinguishable from an upstream tool failure.

Policy implemented

  • Operator-declared read-only tools execute without a gate. New per-server mcpx.readOnlyTools (exact tool names, no patterns). The declaration is the operator's own word in local config -- trusted outright, the same trust mcpx conformance: annotation trust — untrusted upstream annotations must not decide the destructive-confirmation gate (split of #1957) #2191 gives a locally declared stdio server's annotations. A server cannot declare its own tools read-only; remote annotations still clear nothing. A declared tool is classified read-only by the write-policy gate in every mode (ask/allow/deny), clears the destructive floor, and is exempt from the unknown-outcome write ledger.
  • Everything not declared keeps the gate, exactly as before. Unannotated/undeclared tools are still possibly-destructive writes under the defaults; destructive tools still require a confirmation with a real answerer. The declaration never widens: a tool a server adds later, under a new name, is gated until the operator lists it.
  • A gated call in a headless session returns a clear, typed refusal -- never a fake result. ErrNotConfirmed now maps to HTTP 403 (was 502) and call error bodies carry a machine-readable code: confirmation_required (unconfirmed) / write_policy_denied (policy denial). Ordinary tool failures keep 502 + upstream, no code.
  • Fleet config: fff, fff-nix, fff-worktree declare find_files, grep, multi_grep read-only in home/common/mcpx-settings.nix (the production daemon config) and the project .mcpx.json.

⚠️ Deployment note for the coordinator: mcpx strictly validates mcpx block keys (an older binary refuses a config containing readOnlyTools), so the config change and the mcpx binary from this PR must land in the same switch -- which they do if the switch is built from merged main. Do not deploy the config ahead of the binary.

Proof (headless, scratch daemon, real fff-mcp)

Scratch daemon (own state dir/socket/port; production untouched), default policy.write=ask, elicit.confirmDestructive=true, askTimeout=3s, nobody answering questions:

call result
fff.find_files {"query":"zz6116proof"} (CLI) genuine result: sub/zz6116proof-target.txt
POST /v1/call fff.grep (HTTP 200) {"result":{"content":[{"type":"text","text":"→ Read sub/zz6116proof-target.txt (only match)\nsub/zz6116proof-target.txt\n 1: unique-6116-proof-content"}],"isError":false}}
POST /v1/call demo.wipe (destructiveHint:true, undeclared) HTTP 403 {"error":"demo.wipe may be destructive and was not confirmed: the answer was cancel","code":"confirmation_required"}
POST /v1/call fff.multi_grep (unannotated, undeclared in that config) HTTP 403 {"error":"fff.multi_grep may be destructive and was not confirmed: nobody answered within 3s","code":"confirmation_required"}

Control: the unmodified origin/main binary against the same setup (no declaration) returns the audit's error verbatim: mcpx: fff.find_files may be destructive and was not confirmed: nobody answered within 3s.

Tests

New: TestWritePolicyDeclaredReadOnlyPassesWithNoAnswerer, TestWritePolicyDeclarationDoesNotWidenToUnlistedTools, TestDeclaredReadOnlyClearsTheDestructiveFloor, TestGateRefusalsAreTyped (daemon), TestResolveCarriesReadOnlyTools, TestReadOnlyToolsFromJSONConfig (config), TestDeclaredReadOnlyToolRunsHeadless, TestUndeclaredUnannotatedToolStaysGatedHeadless (e2e, real daemon + fakemcp).

  • internal/daemon full suite: PASS
  • internal/policy, internal/refdoc: PASS
  • e2e policy set incl. pre-existing TestADestructiveCallIsRefusedWhenNobodyConfirms / …ProceedsWhenSomebodyConfirms: PASS
  • Pre-existing failures, identical on clean origin/main (verified by diffing failure sets): TestPluginOpsAreGenerated, TestServerKeysAnotherHostWritesAreRecordedNotRefused, TestTargetBearerTokenResolvesTheTargetDaemon, TestNoUndeclaredEnvRead, TestEverySettingHasAnEffectProbeOrAnExemption, TestTheScriptEnvironmentIsWhatTheCodeSets, TestTheEnvironmentDocIsCurrent.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

The write-policy gate (policy.write, default ask) classified tools
from their annotations with the specification defaults: an
unannotated tool is a possibly destructive write. fff-mcp publishes
no annotations, so every projected fff call -- all searches -- was
confirmation-gated, and in headless/API sessions the question has no
answerer, so every call returned the gate error as its result.

- config: new per-server mcpx.readOnlyTools (exact names). The
  operator's declaration in local config is trusted outright, as a
  locally declared stdio server's annotations are (#2191); a server
  cannot declare its own tools read-only this way.
- daemon: a declared tool is classified read-only by the write
  policy gate in every mode, clears the elicit.confirmDestructive
  floor, and is exempt from the unknown-outcome ledger like an
  annotated read-only tool. Unlisted tools keep the defaults
  exactly, so the gate still fires for everything else.
- daemon: gate refusals are typed (#6116 second ask): ErrNotConfirmed
  now answers HTTP 403 (was 502, indistinguishable from an upstream
  failure) and call error bodies carry a machine-readable code --
  confirmation_required / write_policy_denied.
- fleet config: declare fff/fff-nix/fff-worktree find_files, grep
  and multi_grep read-only in home/common/mcpx-settings.nix (the
  production daemon config) and the project .mcpx.json.
- docs: configuration.md gains the readOnlyTools section; consumer.md
  notes the pre-authorization.

Proof (scratch daemon, real fff-mcp, default ask policy +
confirmDestructive on, nobody answering): fff.find_files and
fff.grep return genuine results over the CLI and /v1/call;
demo.wipe and undeclared fff.multi_grep return HTTP 403
{code: confirmation_required}. The unmodified origin/main binary
against the same setup returns the audit's error verbatim:
'fff.find_files may be destructive and was not confirmed: nobody
answered within 3s'.
@dezren39
dezren39 requested a review from a team as a code owner November 5, 2026 15:34
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 25 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e98135b2-c2c2-439d-a1e0-872c8edf76a6
Commits

Reviewing files that changed from the base of the PR and between 6a06a92 and 3f3b33d.

Files selected for processing: 11

  • .mcpx.json
  • home/common/mcpx-settings.nix
  • pkgs/mcpx/docs/configuration.md
  • pkgs/mcpx/docs/consumer.md
  • pkgs/mcpx/internal/config/config.go
  • pkgs/mcpx/internal/config/config_test.go
  • pkgs/mcpx/internal/daemon/callerr.go
  • pkgs/mcpx/internal/daemon/consumer.go
  • pkgs/mcpx/internal/daemon/registry.go
  • pkgs/mcpx/internal/daemon/write_policy_test.go
  • pkgs/mcpx/internal/e2e/readonly_tools_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T15:38:29.128871Z 3f3b33d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f3b33dccc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"args" = [ ];
"command" = "/home/user/.local/bin/fff-mcp";
"mcpx" = {
"readOnlyTools" = [ "find_files" "grep" "multi_grep" ];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update the cascade binary alongside the new configuration

On the configured fleet deployment, services.mcpx.package deliberately uses the cascade's package rather than this checkout's build (home/common/default.nix:1163–1168). However, flake.lock still pins that cascade's mcpx-src to 031cde20f71c2fafa068c47b69e68175b72994a5, whose parser lacks ReadOnlyTools and rejects unknown mcpx keys using DisallowUnknownFields. A fleet switch therefore feeds this new configuration to an incompatible daemon, preventing it from starting. Update the cascade source pin alongside this configuration so the selected service binary includes the new parser support.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed by the cascade pin bump tracked in #6492: developing-today-forks/opencode#1911 bumped the fork mcpx-src pin 031cde2 → bcc0901 (the first code rev line whose parser carries ReadOnlyTools, via your finding PR #6265 merge 4e6cdb9), and #6750 bumped code's opencode pin to the fork merge rev, moving the transitive mcpx-src node to bcc0901. Verified on the laptop: the cascade build at the new pin parses the live rendered mcpx config, while the old-parser binary refuses the same file with server "fff": its "mcpx" block has no key "readOnlyTools". Full evidence on #6492.

// destructive write and which is what gated manifestly
// read-only search tools (fff.find_files) in headless
// sessions, where the gate's question has no answerer.
class = policy.Classification{ReadOnly: true}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor read-only declarations when recording unknown outcomes

When an operator-declared read-only tool without readOnlyHint times out or loses its connection after dispatch, callWithLedger in registry.go still classifies it using only the annotation-based toolReadOnly helper. Consequently, a declared search such as fff.grep returns ErrUnknownOutcome and persists a server-wide block on subsequent non-read-only calls until manually cleared, despite the new declaration classifying it as read-only here. Apply the requested server's declaration to the post-dispatch ledger classification as well, not just the gate and existing-block exemption.

Useful? React with 👍 / 👎.

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.

mcpx confirmation gate makes projected tools unusable in headless/API sessions — including read-only tools

1 participant