Skip to content

fix(cli): MCP read-only switch drops every tool not annotated read-only - #5191

Merged
mergify[bot] merged 1 commit into
mvanhorn:mainfrom
DamienStevens:fix/mcp-read-only-all-tools
Oct 23, 2026
Merged

mergify[bot] merged 1 commit into
mvanhorn:mainfrom
DamienStevens:fix/mcp-read-only-all-tools

Conversation

@DamienStevens

Copy link
Copy Markdown
Contributor

Intent

<PREFIX>_MCP_READ_ONLY=1 is documented as the operator kill switch, but typed endpoint tools, intent tools, <api>_execute, and mcp:local-write mirrors (teach, teach_playbook, playbook_amend, learnings_confirm, ...) stayed registered with it on.

Issue: Closes #5175

Approach

After every registration, RegisterTools removes each tool whose readOnlyHint is not true (ListTools + DeleteTools). One rule covers typed, intent, mirror and code-orchestration tools, and an unannotated tool fails closed. The mirror's own filter and the call-time refusals are unchanged and stay as a second layer. Device CLIs are not touched: their RegisterTools registers only the read-only context tool plus the mirror, and they emit no learn writers.

Scope

Primary area: generator templates, MCP surface (mcp_tools.go.tmpl).

Why this belongs in this repo: the switch is emitted into every printed CLI. Downstream (Servosity msp-skills) we carry the same rule as a hand-fix in two connectors.

Risk

Switch on: <api>_execute and the learn writers are no longer offered; <api>_read, _search, _get, sql, search, context and read-only mirrors remain. A GET that already fails closed as not read-only (RPC-over-GET without a read signal) is also dropped, which matches its existing annotation. Recipe-intent tools carry no readOnlyHint today, so with the switch on they are dropped too, even when they wrap a read-only command (fail closed; annotating them is a separate change). The mirror's own filter still admits mcp:local-write commands before this pass removes them; left as is to keep this change to one rule. Switch off: no change.

Output Contract

internal/mcp/tools.go gains the post-registration drop and dropNonReadOnlyTools; goldens updated for the six cases that render mcp_tools.go.tmpl. TestGenerateMCPReadOnlySwitchDropsEveryNonReadOnlyTool generates and compiles two CLIs (endpoint mirror and code orchestration, learn loop on) and runs an emitted runtime test: switch off, the write tools are registered; switch on, every registered tool has readOnlyHint: true and no read-only tool was dropped. AGENTS.md and phase 11 skill text describe the new scope.

Verification

  • go build ./...

  • go test -timeout 90m ./internal/generator/...: all pass except four that fail identically on unmodified main (c601087) on this macOS host: TestGeneratedTLSTrustStock, TestGeneratedTLSTrustHTTP1Only, TestGeneratedTLSTrustBrowser (x509 trust of the test leaf certificate) and TestGeneratedDefaultDBPathStableOAuthScope. A first run under heavy machine load also hit timing and shared-GOCACHE flakes, all of which pass on rerun

  • scripts/golden.sh update (6 tools.go fixtures changed, all the same 19-line addition), then scripts/golden.sh verify: pass (43 cases)

  • scripts/verify-generator-output.sh (default cases): pass (15 cases)

  • Negative control: with the drop disabled, the new runtime test fails listing items_create, items_remove and six learn writers as registered under the switch.

  • golangci-lint and lefthook are not installed on this machine; gofmt -l and go vet ./internal/generator/ are clean.

  • Generator/template change: verified generated output, including emitted-code assertions or compiled generated CLI output

  • Generator/template change: covered the affected fallback or variant shape, not only happy-path fixtures

  • Generator/template change: checked emitted definitions and call sites for matching gates

AI / Automation Disclosure

  • No AI or automation was used
  • Human-reviewed: AI or automation was used, and a human reviewed the work for intent, fit, and obvious issues before submission
  • AI-reviewed only: an AI agent reviewed the work, but no human reviewed it before submission
  • Fully automated: generated and submitted without human review for this specific change

🤖 Generated with Claude Code

<PREFIX>_MCP_READ_ONLY=1 was consulted only by the cobratree mirror and
<api>_execute, so typed endpoint tools, intents, the execute tool and
mcp:local-write mirrors stayed registered. RegisterTools now removes each
tool whose readOnlyHint is not true after every registration; an
unannotated tool fails closed. Call-time refusals stay as a second layer.

Closes mvanhorn#5175

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 2 merge protections satisfied — ready to merge.

Show 2 satisfied protections

🟢 require-ready-label-and-ci

  • #changes-requested-reviews-by = 0
  • #review-threads-unresolved = 0
  • check-success = build-and-test
  • check-success = generated-test
  • check-success = go-lint
  • check-success = golden
  • check-success = pr-title
  • check-success = test
  • any of:
    • label = ready-to-merge
    • all of:
      • head = release-please--branches--main
      • title ~= ^chore\(main\): release
  • any of:
    • -files ~= ^(\.github/workflows/|\.github/scripts/|scripts/|\.github/CODEOWNERS$)
    • approved-reviews-by = mvanhorn
    • approved-reviews-by = tmchow
    • author = mvanhorn
    • author = tmchow
  • any of:
    • check-success = Greptile Review
    • label = queued
    • check-neutral = Greptile Review
    • check-skipped = Greptile Review
    • head ~= ^mergify/merge-queue/
    • all of:
      • head = release-please--branches--main
      • title ~= ^chore\(main\): release

🟢 🚦 Auto-queue

When all merge protections are satisfied and these conditions match, this pull request will be queued automatically.

  • label = ready-to-merge

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defects were found.

Summary

Makes the generated MCP read-only switch remove every tool without readOnlyHint: true after registration.

  • The MCP read-only switch leaves only tools marked read-only.

No actionable issues found. Tests were not run during this review.

DamienStevens explicitly described dropping unannotated recipe intents and ambiguous RPC-over-GET tools as intentional. DamienStevens also explicitly excluded device CLIs from this change.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Register typed tools, intents, built-ins, and mirrors] --> B{Read-only switch enabled?}
  B -->|No| C[Keep registered tools]
  B -->|Yes| D{readOnlyHint is true?}
  D -->|Yes| E[Keep tool]
  D -->|No or unset| F[Delete tool]
Loading

Reviews (1) · Last reviewed commit: "fix(cli): MCP read-only switch drops eve..." · Reviewed by Greptile

@tmchow tmchow added the ready-to-merge Queue when Mergify passes; scripts/.github PRs also need Approve from tmchow/mvanhorn. label Oct 23, 2026
@mergify mergify Bot added the queued PR is in the Mergify merge queue label Oct 23, 2026
@mergify
mergify Bot merged commit 0983519 into mvanhorn:main Oct 23, 2026
32 checks passed
@mergify

mergify Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 58 minutes 31 seconds in the queue, including 22 minutes 26 seconds running CI.

Required conditions to merge

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

Labels

ready-to-merge Queue when Mergify passes; scripts/.github PRs also need Approve from tmchow/mvanhorn.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP read-only switch leaves typed endpoint tools, intents and local-write mirror tools callable

2 participants