Skip to content

feat(mcp): add write confirmation and redaction infrastructure - #506

Merged
alosec merged 2 commits into
mainfrom
alex/dev-14372-write-safety-foundation
Nov 6, 2026
Merged

alosec merged 2 commits into
mainfrom
alex/dev-14372-write-safety-foundation

Conversation

@alosec

@alosec alosec commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Extract the shared confirmation infrastructure from #451: signed five-minute approvals bound to the tool, arguments, account, credential, channel and record state; token/elicitation flows; refusal/replay handling; and redaction across logs, Sentry and PostHog. SDK 429 errors retain Retry-After for write-tool responses.

This prerequisite does not change which tools are exposed or require confirmation. The next PR activates confirmations for the two existing batch writes; lifecycle tools and publishing docs follow separately. Original author: Akshay Dodeja. Tracks DEV-14372.

Validation: full npm run agent-verify passes on Node 24, including 874 MCP tests, SDK/CLI tests and builds, lint/type checks, generated-contract checks, and a legacy-protocol initialize/tools-list smoke (30 tools). SDK reference regenerated with npm run sdk:docs.

Approval consumption is process-local; the original multi-instance limitation is retained. The lifecycle follow-up remains opt-in.


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

Review order: #506 → #507 → #508 → #509. Each diff is against its predecessor; #509 is the combined QA target.

RetriggerView in GreptileConfidence Score: 4/5

The PR appears safe to merge, with non-blocking feedback to test approval reuse and failure retries.

Fix All in CodexFindings

  1. P2 Approval reuse lacks tests ▶
Fix with agent prompt
### Issue 1
packages/mcp/src/tools/write-flow.test.ts:316-319
The new tests never reuse a consumed approval or exercise `refused`. This test throws a plain `Error`, so it misses the rule that a 4xx releases an approval while a 5xx or lost response keeps it spent.

Add tests for concurrent use, replay after restoring the original record state, retry after a 4xx, and replay after a 5xx or network failure. This is non-blocking, but those tests would catch changes that allow duplicate writes or reject valid retries.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds shared write-confirmation helpers without activating them for exposed tools.

  • MCP write helpers can preview a change and wait for confirmation before writing.
  • MCP write calls can send a checked audit record to three monitoring destinations.
  • MCP logs and monitoring scrub confirmation tokens as well as signed URLs.
  • TypeScript SDK callers can read the API’s requested wait from rate-limit errors.

Acknowledged scope: alosec defers activation to the next PR and retains process-local approval consumption.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read record] --> B{Needs approval?}
  B -->|No| C[Write]
  B -->|Yes| D{Approval supplied?}
  D -->|No| E[Return preview or ask user]
  D -->|Yes| F[Check signature, expiry, identity, and state]
  F -->|Invalid| G[Refuse or refresh preview]
  F -->|Valid| H[Reserve approval]
  H --> C
  C -->|Success| I[Keep approval spent]
  C -->|4xx refusal| J[Release approval]
  C -->|Other failure| I
Loading

Reviews (1) · Last reviewed commit: "fix(mcp): use a keyed credential tag for..." · Reviewed by Greptile

@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
api Ready Ready Preview Nov 6, 2026 8:01pm UTC

Request Review

@mintlify

mintlify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
terminal49 🟢 Ready View Preview Nov 6, 2026, 7:50 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@linear-code

linear-code Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

DEV-14372

@github-actions github-actions Bot added the risk-shadow:high Shadow-only risk signal: high label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Shadow risk calibration

Signal Result Authority
Path classifier risk:high Deterministic advisory policy
heuristic fallback risk-shadow:high Shadow only

Calibration result: agreement.

Shadow risk never blocks or enables merge. Keep it in observation mode until roughly 50 pull requests have human-reviewed labels, then calibrate before considering any policy use.

@github-actions github-actions Bot added risk:high Advisory path risk; current-head human review needed and removed risk:unknown Advisory evidence unavailable or changed; no merge permission labels Nov 6, 2026
@github-actions github-actions Bot added risk:unknown Advisory evidence unavailable or changed; no merge permission and removed risk:high Advisory path risk; current-head human review needed labels Nov 6, 2026
@github-actions github-actions Bot added risk:high Advisory path risk; current-head human review needed and removed risk:unknown Advisory evidence unavailable or changed; no merge permission labels Nov 6, 2026
@alosec
alosec marked this pull request as ready for review November 6, 2026 20:52
@alosec
alosec merged commit 7153097 into main Nov 6, 2026
33 checks passed
@alosec
alosec deleted the alex/dev-14372-write-safety-foundation branch November 6, 2026 20:52
@github-actions github-actions Bot added risk:unknown Advisory evidence unavailable or changed; no merge permission and removed risk:high Advisory path risk; current-head human review needed labels Nov 6, 2026
Comment on lines +316 to +319
it('audits a write that throws and rethrows it', async () => {
const target = record();
const ctx = context();
target.write.mockRejectedValueOnce(new Error('upstream failed'));

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 Approval reuse lacks tests

The new tests never reuse a consumed approval or exercise refused. This test throws a plain Error, so it misses the rule that a 4xx releases an approval while a 5xx or lost response keeps it spent.

Add tests for concurrent use, replay after restoring the original record state, retry after a 4xx, and replay after a 5xx or network failure. This is non-blocking, but those tests would catch changes that allow duplicate writes or reject valid retries.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/mcp/src/tools/write-flow.test.ts
Line: 316-319

Comment:
**Approval reuse lacks tests**

The new tests never reuse a consumed approval or exercise `refused`. This test throws a plain `Error`, so it misses the rule that a 4xx releases an approval while a 5xx or lost response keeps it spent.

Add tests for concurrent use, replay after restoring the original record state, retry after a 4xx, and replay after a 5xx or network failure. This is non-blocking, but those tests would catch changes that allow duplicate writes or reject valid retries.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Codex Fix in Claude Code

alosec added a commit that referenced this pull request Nov 6, 2026
* feat(mcp): add opt-in reference number tools

add_reference_numbers (tier A) and remove_reference_numbers (tier C) in a
new opt-in reference_numbers toolset, ported from #452 onto the write kit
that landed in #506-#509.

Drops the set_party_role party_id hint from the server instructions: it
repeats the tool's own description, and with every toolset served the
instructions otherwise exceed Claude Code's 2 KB limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore(mcp): list the reference number tools in the agent trust feature map

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

2 active (1 outdated) deployments
Preview — ed72cc03 Deployed Nov 6, 2026 by vercel[bot]
staging - docs — 0ec69395 Deployed Nov 6, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:unknown Advisory evidence unavailable or changed; no merge permission risk-shadow:high Shadow-only risk signal: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants