Repository navigation
Commit d6b1c2e
feat(runtime,mcp): ask the person in their MCP client before a confirmation-gated action runs (#34318)
domain:server#5 · zhuangjianguo · session_01QsR2jTEivi2wogPpeo3xd5
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbTGhxJSYAmQXU7efVdNqrpw)_
Part of #33712
Clause-②: no
Metadata-protocol: semantic (at the MCP door, an author's
`ai.requiresConfirmation: true` is confirmed in place for a client that
advertises `elicitation`. The dev confirms the level against the diff
and, if it holds, adds the PR body's `Skills-docs:` line.)
Skills-docs: follow-up #34210 (widened to cover the in-client question
and the `declined` / `cancelled` / `timed_out` refusals)
## 维护者速读
1. **改了什么**:本地(stdio)连接的 MCP
客户端若支持「征询」,执行需确认的动作时直接在客户端弹框问用户:同意就执行一次,拒绝、关闭或超时(5 分钟)就拒绝,不再走邮件挂起。
2. **为什么改**:落实确认契约第 1 步(征询优先);不支持征询的客户端仍走 #34202 的挂起审批,行为不变。
3. **风险与回滚**:只影响声明了 `ai.requiresConfirmation: true` 且客户端声明了征询能力的 stdio
调用;远程 HTTP 接口行为与字节均未变。回滚即还原本 PR。
4.
**先看**:`packages/runtime/src/action-dispatch.ts`(`confirmAdmittedAction`
的征询分支)、`packages/mcp/src/action-confirmation-elicitation.ts`(超时与取消的判读)、`packages/runtime/src/domains/mcp.ts`(`resume_run`
分支)。
5. **两分钟验证**:`pnpm --filter @objectstack/mcp exec vitest run
src/mcp-action-confirmation-handoff-33690.test.ts`,应见 18 个用例全绿,其中 stdio
同意/拒绝/取消与 HTTP 仍挂起各有专用例。
6. **需要你做的**:无。两个问题已由你裁定(#33712 评论 6909391261):远程 HTTP 接口暂不征询,继续走邮件审批,直到
#34321;用户取消或超时时直接拒绝,不发邮件。本 PR 与两项裁决一致。
## What changes
Step 1 of the amended confirmation contract
(`AI_ACTION_CONFIRMATION_CAPABILITY`,
`packages/spec/src/contracts/ai-service.ts`) at the MCP `run_action` and
`resume_run` doors, on the server that can carry it.
- `@objectstack/mcp`, new `action-confirmation-elicitation.ts`:
`actionConfirmationElicitorFor(server, extra)` answers an elicitor for
the open tool call, or `undefined` when the client did not advertise
form-mode `elicitation` on this server's `initialize` (the SDK reads an
empty `elicitation: {}` as form mode). The elicitor sends ONE
`elicitation/create` (form mode, empty `requestedSchema`) through
`extra.sendRequest`, related to the tool call, bounded by
`ACTION_CONFIRMATION_ELICITATION_TIMEOUT_MS` (five minutes, the door's
bound the contract asks the door to name; a door constant, no authorable
key), abandoned on the call's abort signal. It reads the result's
`action` only (a loose schema, so a form payload the SDK's own
`ElicitResultSchema` would reject cannot turn an `accept` into a
failure). A timeout reads as `timed_out`; an error answer, an aborted
call and a closed connection read as `cancel` (the abort check comes
first because the SDK rejects an aborted request with a `RequestTimeout`
error too).
- `mcp-http-tools.ts`: both tools pass `{ elicitConfirmation }` as a
third bridge argument only when the elicitor exists; otherwise the
bridge is called with exactly the two arguments it got before.
`McpActionBridge.runAction` / `resumeRun` gain the optional `door?:
McpActionCallDoor`. Both tool descriptions gain one sentence on the
in-client question.
- `@objectstack/runtime`: `action-dispatch.ts` `confirmAdmittedAction`
(was `handOffAdmittedAction`) asks the elicitor after the same
caller-scope subject verdict the hand-off asks, so the contract's step
order holds (every admission gate, the subject load and its verdict,
then the person). `accept` returns to `runResolvedAction`, which
dispatches as any admitted call (the `action_invocation` row is written
as for any run). `decline` / `cancel` / `timed_out` are refused `428
ACTION_CONFIRMATION_REQUIRED` with `reason` `declined` / `cancelled` /
`timed_out`, through the existing `confirmationRefusalOf`. An elicitor
that throws reads as `cancelled`. Nothing is handed off on any answer.
`action-execution.ts` gains `elicitActionConfirmation` and
`actionConfirmationElicitSubject` (the action, its label, the object,
the record id, and the record's title via `resolveRecordTitle`, left out
rather than replaced by the id). `domains/mcp.ts` forwards the door from
the bridge and gives `resumeActionRun` the same branch: `accept` resumes
the parked run, any other answer refuses and the run stays paused.
- An AI service account is refused at the confirmation step before the
subject load, so it is never elicited. A non-capable client takes the
hand-off unchanged.
## Tests
- `packages/runtime/src/action-confirmation-handoff-33690.test.ts`, two
new top-level `describe`s on the existing harness (the real
`buildMcpBridge` over a kernel double; `nameField: 'name'` added to its
object so the question can carry a title): run_action accept runs once
and hands nothing off, the elicitor gets `{ actionName, actionLabel,
objectName, recordId, recordTitle: 'Ada' }`; an accept covers one call;
decline / cancel / timed_out refused with their reasons, nothing runs,
nothing submitted; a failing elicitor reads `cancelled`; an account and
an unreadable record are refused before the elicitor is called; an
ungated action is never asked; resume_run accept resumes with the call's
values, decline keeps the run paused, an account is refused before
asking.
- `packages/mcp/src/mcp-action-confirmation-handoff-33690.test.ts`,
three new top-level `describe`s: a real SDK `Client` on the long-lived
server's `StdioServerTransport` (newline framing over two pipes)
advertising `elicitation: {}`: accept (one form-mode request naming
action, object, record title and id), accept with an unread payload,
decline, cancel, an error answer, and resume_run accept / decline; a
client without the capability is never asked and the bridge gets two
arguments. Streamable HTTP: a client that advertised `elicitation` at
`initialize` is handed off on the next POST, answered
`application/json`; a non-gated call answers plain JSON.
`actionConfirmationElicitorFor` against a real `Client` over the SDK's
in-memory pair: accept / decline / cancel, `timed_out` at a 50 ms bound,
`cancel` when the client closes the connection mid-question, `cancel` on
an error answer.
## Acceptance notes
- **The Streamable HTTP door does not elicit in this PR, so this is
`Part of`.** Measured on `@modelcontextprotocol/sdk` 1.32.1
(LATEST_PROTOCOL_VERSION `2025-11-25`): the door builds a fresh `Server`
per POST (`handleHttpRequest`, stateless, no session id), so the server
that answers `tools/call` never ran `_oninitialize` and holds no client
capabilities; and a client's answer to a server request arrives as a
separate POST, which in stateless mode reaches another fresh server with
no pending request (server request ids are per-instance counters, so
they cannot even be routed by id). Streaming the `tools/call` response
alone carries the question out but nothing can carry the answer back.
Eliciting there needs Streamable HTTP sessions (`Mcp-Session-Id`), which
is an architecture decision; the options are in the report on the card.
Until then the contract's own rule holds there: a door that cannot
elicit hands off and is never refused for that alone.
- **Cancel and timeout are refused, as the spec contract says, not
handed off.** The card body (written before the contract landed) and the
dispatch read "cancel or a timeout, fall back to the hold-and-email
path"; the contract on `main` (step 4, and
`ACTION_CONFIRMATION_REFUSAL_REASONS`) refuses them with `cancelled` /
`timed_out`. This PR follows the spec text and does not edit
`packages/spec`; the conflict is raised for a ruling on the card.
Flipping it is two branches in `elicitActionConfirmation`.
- **The no-service message keeps leaving out "use a client that supports
confirmation".** It is one message for both doors, and on Streamable
HTTP no client can be elicited yet, so the sentence would still be false
for most callers. It is restored with the HTTP half.
- The served skill's confirmation prose (`skill-md.ts`) is untouched; it
stays with #34209.
- Ablations (each through `scripts/ablation-replace.mjs`, restore
verified `git diff HEAD` empty): elicit branch in
`confirmAdmittedAction` removed: 6 run_action pins red; elicit branch in
`resumeActionRun` removed: resume accept / decline red; the tool's
elicitor forced `undefined`: 5 stdio pins red ("expected [] to have a
length of 1 but got +0"); the account refusal in `aiDoorConfirmation`
removed: both account-before-asking pins red; the capability check in
`actionConfirmationElicitorFor` removed: the non-capable stdio pin and
the HTTP pin red.
## Verification
Readings at head `3557594b65` unless named (merge of `origin/main` at
`0f74af49d5`; the only commit after it drops two inert lint comments in
a test file).
<details><summary>Package tests (each under the shared verify lock, exit
captured per part)</summary>
- `@objectstack/mcp` test: 66 files / 1204 tests passed (exit 0).
- `@objectstack/runtime` test (full): 607 files passed, 11101 tests
passed / 19 skipped (exit 0), at `c09b8aa557`, before the `origin/main`
merge, which moved no runtime source (two unrelated runtime test files).
At the final head, the five confirmation files
(`action-confirmation-handoff-33690`, `mcp-resume-run`,
`action-confirmation-gate`, `action-dispatch`,
`mcp-system-object-action-exposure`): 149 tests passed.
- Direct dependents of `@objectstack/mcp` (its public exports grew):
`@objectstack/verify` 52 files / 439 passed;
`@objectstack/http-conformance` 20 / 292; `@objectstack/example-todo` 9
/ 249; `@objectstack/cli` unit layer 423 / 6010 (integration layer
declared to CI). `@objectstack/dogfood` is the battery: not run (no `!`,
no `(narrowing)` arm). The runtime's dependents are not re-run: its
package exports did not move.
- `pnpm --filter @objectstack/mcp typecheck` and `pnpm --filter
@objectstack/runtime typecheck`: exit 0, test layers within their
ledgers.
- eslint (`--no-inline-config`) on the eight touched source and test
files: exit 0. The repo-wide `pnpm lint` is left to CI.
</details>
<details><summary>Derived gates</summary>
`node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`: 70 commands. 68 ran in one loop, each with
its exit captured before any pipe: all exit 0. `check:type-check-debt`
(re-measure, 0 entries, OK) and `check:dual-build-cjs-loads` (123
entries load) ran afterwards under the lock: exit 0. `--ran`: 70
derived, 70 run, 0 NOT-MEASURED, 0 UNRUN.
`git merge-tree --write-tree` against PR #34236's head `c53ea9d147` and
against `origin/main`: both clean.
</details>
Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent f59a4aa commit d6b1c2e
9 files changed
Lines changed: 1055 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
58 | 73 | | |
59 | 74 | | |
60 | 75 | | |
| |||
0 commit comments