Skip to content

fix(cli): treat action POSTs as possibly destructive and quarantine MCP learn text - #5209

Merged
mergify[bot] merged 2 commits into
mainfrom
tmchow/mcp-post-hint-learn-untrusted-9b01
Oct 23, 2026
Merged

mergify[bot] merged 2 commits into
mainfrom
tmchow/mcp-post-hint-learn-untrusted-9b01

Conversation

@tmchow

@tmchow tmchow commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Intent

Endpoint-mirror POST tools advertised destructiveHint: false, which MCP defines as additive-only, so hosts could auto-approve actions such as retire, cancel, and revoke. Learn-store writers (teach, teach-playbook, playbook amend, learnings confirm, and the other mcp:local-write commands) did the same, and recall returned stored playbook text as a trusted next action.

Closes #5184
Closes #5185

The <PREFIX>_MCP_READ_ONLY=1 half of #5185 is already on main via #5191. This PR fixes the remaining halves: host prompts for learn-store writes, MCP provenance, and an untrusted recall envelope.

Approach

Non-read endpoint mirrors and intents omit destructiveHint unless the method is DELETE or the spec sets x-pp-destructive. Omitting the hint leaves the MCP library default, which is possibly destructive. x-pp-destructive: false is the explicit additive opt-in and does not make the command read-only. Reads, including x-pp-mutation: false, keep readOnlyHint: true and destructiveHint: false even when x-pp-destructive: true is also set. A non-boolean value is ignored.

context, sql, search, and the code-orchestration read tools still advertise destructiveHint: false.

Learn-store mirrors set openWorldHint: true and do not emit destructiveHint: false. User text stored through teach, teach-playbook, playbook amend, and learnings confirm records learning_playbooks.ingress_surface. Only mcp is stored as mcp; anything else stores cli. A later CLI write does not clear mcp. Embedded playbook seed does not read the MCP surface env, so a child process does not quarantine trusted seed rows. Schema version 14 adds the column with DEFAULT 'cli'. Recall on a pre-v14 store falls back to the old SELECT and treats those rows as CLI-authored. MCP rows come back under untrusted_data, with a warning, and playbook-candidate next actions tell the agent not to run the stored steps.

Endpoint writes and learn-store writes use separate hint paths. One helper would hide that local-store writes must prompt while genuine reads stay additive.

Scope

Primary area: generator templates, OpenAPI parser, printed MCP annotations, learn store.

Why this belongs in this repo: both defects are in the machine that prints every CLI. A printed-CLI-only patch would leave the next regen wrong.

Risk

Fresh prints advertise action POSTs and learn-store writes as possibly destructive and open-world, so MCP hosts that auto-approved destructiveHint: false will prompt. Specs that want an additive POST set x-pp-destructive: false.

Existing learn stores gain ingress_surface defaulting to cli on open. Recall still returns CLI-authored playbooks on the trusted playbook and notes fields. MCP-authored text moves to untrusted_data.

teach --notes and search_learnings audit notes are unchanged and stay outside this envelope.

Output Contract

TestGenerateMCPPostDestructiveHints generates a module from testdata/device-safety-destructive.yaml, asserts emitted tools, intents, walker, recall, and store schema, compiles the module, and checks live RegisterTools annotations plus learn and store tests inside that module.

scripts/golden.sh verify passed all 43 cases after the fixture update. POST create tools no longer emit WithDestructiveHintAnnotation(false). PUT and PATCH stay omitted. Reads stay read-only. Learn-enabled goldens carry schema v14, ingress_surface, and the untrusted_data recall envelope.

Verification

Self-review gate, run before opening this PR:

  • Comments that only restated code were removed; remaining comments say why (additive-only auto-approve, sticky mcp, seed must not read the MCP env, pre-v14 column fallback).
  • Changed generator templates are compiled by TestGenerateMCPPostDestructiveHints and by the golden fixtures.
  • Goldens were regenerated with scripts/golden.sh update and verified with scripts/golden.sh verify (43 cases). Three dogfood-verdict JSON files that had captured a local Go 1.24 toolchain download failure were restored; the full verify then passed with Go 1.26.10 on PATH.
  • GOOS=linux|darwin|windows CGO_ENABLED=0 go vet on ./internal/openapi/, ./internal/spec/, and ./internal/generator/. Generated learn-loop-example and device-safety modules: go vet ./... and go build of the CLI and MCP mains for the same three GOOS. No Linux-only paths, permissions, or signals in the new code.
  • New branches have tests, including negatives: string and numeric x-pp-destructive ignored, read wins over x-pp-destructive: true, subresource POST, intent mix and unresolved steps, surface case and encodings (bWNw, mcp%20, embedded NUL), missing-column fallback versus other SQL errors, flag-alias next action left in place, ambient LEARN_SURFACE does not taint seed, CLI recall stays trusted.
  • <api>_execute preview/confirm was left as-is.

Commands:

  • go test ./... -count=1 -timeout 60m

  • bash scripts/golden.sh verify (43 cases, pass)

  • Cross-OS vet and build above

  • 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
Open in Web Open in Cursor 

Non-read endpoint POSTs no longer advertise destructiveHint false unless
the spec marks the write additive. Learn-store writes over MCP stay
possibly destructive and open-world, record surface=mcp, and recall
returns that text under untrusted_data.

Closes #5184
Closes #5185

Co-authored-by: Trevin Chow <tmchow@users.noreply.github.com>
@mergify

mergify Bot commented Oct 23, 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$)
    • author = tmchow
    • approved-reviews-by = mvanhorn
    • approved-reviews-by = tmchow
    • author = mvanhorn
  • 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 23, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The changes since the previous review appear safe to merge.

Summary

The PR makes MCP write tools ask for permission more conservatively and separates MCP-authored playbook text from trusted recall guidance.

  • MCP action tools leave ordinary writes possibly destructive unless a spec marks them additive.
  • Local learn-store tools prompt before MCP can run their writes.
  • MCP-saved playbook text stays marked as untrusted when agents recall it.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Playbook write] --> B{Text supplied through MCP?}
  B -->|Yes| C[Store ingress_surface as mcp]
  B -->|No| D[Store as cli unless already mcp]
  C --> E[Recall]
  D --> E
  E --> F{Stored surface is mcp?}
  F -->|Yes| G[Return untrusted_data and warning]
  F -->|No| H[Return trusted playbook and notes]
Loading

Reviews (2) · Last reviewed commit: "style(cli): clear modernize and QF1001 o..." · Reviewed by Greptile

Replace the boolPtr helper with new, use max for the tool-block window,
and rewrite the additive-hint check with De Morgan's law. Generated
output is unchanged.

Co-authored-by: Trevin Chow <tmchow@users.noreply.github.com>
@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 7b6e627 into main Oct 23, 2026
35 checks passed
@mergify

mergify Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 25 minutes 49 seconds in the queue, including 24 minutes 44 seconds running CI.

Required conditions to merge

@mergify
mergify Bot deleted the tmchow/mcp-post-hint-learn-untrusted-9b01 branch October 23, 2026 15:48
@mergify mergify Bot removed the queued PR is in the Mergify merge queue label Oct 23, 2026
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

2 participants