Repository navigation
fix(cli): treat action POSTs as possibly destructive and quarantine MCP learn text - #5209
Merged
Merged
Conversation
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>
Contributor
Merge Protections🟢 All 2 merge protections satisfied — ready to merge. Show 2 satisfied protections🟢 require-ready-label-and-ci
🟢 🚦 Auto-queueWhen all merge protections are satisfied and these conditions match, this pull request will be queued automatically.
|
Contributor
[Medium impact] The changes since the previous review appear safe to merge. SummaryThe PR makes MCP write tools ask for permission more conservatively and separates MCP-authored playbook text from trusted recall guidance.
|
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>
59 of 96 tasks
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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 othermcp:local-writecommands) did the same, andrecallreturned stored playbook text as a trusted next action.Closes #5184
Closes #5185
The
<PREFIX>_MCP_READ_ONLY=1half 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
destructiveHintunless the method is DELETE or the spec setsx-pp-destructive. Omitting the hint leaves the MCP library default, which is possibly destructive.x-pp-destructive: falseis the explicit additive opt-in and does not make the command read-only. Reads, includingx-pp-mutation: false, keepreadOnlyHint: trueanddestructiveHint: falseeven whenx-pp-destructive: trueis also set. A non-boolean value is ignored.context,sql,search, and the code-orchestration read tools still advertisedestructiveHint: false.Learn-store mirrors set
openWorldHint: trueand do not emitdestructiveHint: false. User text stored through teach, teach-playbook, playbook amend, and learnings confirm recordslearning_playbooks.ingress_surface. Onlymcpis stored as mcp; anything else storescli. A later CLI write does not clearmcp. 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 withDEFAULT 'cli'. Recall on a pre-v14 store falls back to the old SELECT and treats those rows as CLI-authored. MCP rows come back underuntrusted_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: falsewill prompt. Specs that want an additive POST setx-pp-destructive: false.Existing learn stores gain
ingress_surfacedefaulting toclion open. Recall still returns CLI-authored playbooks on the trustedplaybookandnotesfields. MCP-authored text moves tountrusted_data.teach --notesandsearch_learningsaudit notes are unchanged and stay outside this envelope.Output Contract
TestGenerateMCPPostDestructiveHintsgenerates a module fromtestdata/device-safety-destructive.yaml, asserts emitted tools, intents, walker, recall, and store schema, compiles the module, and checks liveRegisterToolsannotations plus learn and store tests inside that module.scripts/golden.sh verifypassed all 43 cases after the fixture update. POST create tools no longer emitWithDestructiveHintAnnotation(false). PUT and PATCH stay omitted. Reads stay read-only. Learn-enabled goldens carry schema v14,ingress_surface, and theuntrusted_datarecall envelope.Verification
Self-review gate, run before opening this PR:
TestGenerateMCPPostDestructiveHintsand by the golden fixtures.scripts/golden.sh updateand verified withscripts/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 onPATH.GOOS=linux|darwin|windows CGO_ENABLED=0 go veton./internal/openapi/,./internal/spec/, and./internal/generator/. Generatedlearn-loop-exampleanddevice-safetymodules:go vet ./...andgo buildof the CLI and MCP mains for the same three GOOS. No Linux-only paths, permissions, or signals in the new code.x-pp-destructiveignored, read wins overx-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, ambientLEARN_SURFACEdoes not taint seed, CLI recall stays trusted.<api>_executepreview/confirm was left as-is.Commands:
go test ./... -count=1 -timeout 60mbash 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