Skip to content

Commit d6b1c2e

Browse files
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
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/runtime': minor
3+
'@objectstack/mcp': minor
4+
---
5+
6+
feat(runtime,mcp): the MCP `run_action` and `resume_run` tools ask the person in their client when it advertises `elicitation`
7+
8+
Clause-②: no
9+
Metadata-protocol: semantic (at the stdio MCP door, an author's `ai.requiresConfirmation: true` is confirmed in place for a client that advertises `elicitation`)
10+
Skills-docs: follow-up owed — skills/objectstack-ai/SKILL.md (the `run_action` row of the MCP tool table; the same row the hand-off follow-up #34210 rewrites)
11+
12+
This release implements step 1 of the amended confirmation contract (`AI_ACTION_CONFIRMATION_CAPABILITY`, `@objectstack/spec/contracts`) on the long-lived MCP server, the one behind the stdio transport.
13+
14+
- When the client advertised `elicitation` at `initialize` (an empty `elicitation: {}` reads as form mode), a call on an action whose author declared `ai.requiresConfirmation: true` is asked in place: after every admission gate, the subject load and the caller-scope subject verdict included, the server sends one `elicitation/create` request in form mode, related to the open tool call, naming the action, the object and the record (its id, and the title the caller-scope read served, bounded to one line). Only the result's `action` is read.
15+
- `accept` runs the call exactly once, as any admitted call, under the caller's permissions, on the gates and the subject read again after the answer; the next call is asked again. `decline` is refused `428 ACTION_CONFIRMATION_REQUIRED` with `details.reason: 'declined'`. `cancel`, an error answer, a tool call cancelled by the client and a connection that closes first are refused with `reason: 'cancelled'`. No answer within the door's bound, `ACTION_CONFIRMATION_ELICITATION_TIMEOUT_MS` (five minutes, exported by `@objectstack/mcp`), is refused with `reason: 'timed_out'`, and a later answer runs nothing. Nothing is handed off on any of these answers.
16+
- `resume_run` is asked the same way for the run's action: `accept` resumes the parked run with the call's values; any other answer refuses the call and the run stays paused.
17+
- An AI service account is refused before anyone is asked, as before (`reason: 'service_account'`).
18+
- Unchanged: a client that does not advertise `elicitation` takes the hand-off (or the `no_confirmation_service` refusal) exactly as before, and is never refused for that alone. The Streamable HTTP door builds a fresh server per request that never read the client's `initialize`, so it cannot elicit, and every caller there is handed off as before; its answers stay plain JSON.
19+
- `McpActionBridge.runAction` and `resumeRun` take an optional third argument, `door: { elicitConfirmation }` (`McpActionCallDoor`), which the tools pass only when the call can be elicited. `@objectstack/mcp` also exports `actionConfirmationElicitorFor`, `actionConfirmationQuestion`, `confirmationQuestionText`, the bounds `ACTION_CONFIRMATION_QUESTION_TEXT_MAX` and `ACTION_CONFIRMATION_QUESTION_ID_MAX`, and the types `McpActionConfirmationSubject`, `McpActionConfirmationAnswer` and `McpActionConfirmationElicitor`.
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* # Asking the person in their client (step 1 of the amended confirmation contract)
5+
*
6+
* The MCP `run_action` and `resume_run` doors confirm an action whose author
7+
* declared `ai.requiresConfirmation: true` with the person, never with the
8+
* caller's own `confirm` (`AI_ACTION_CONFIRMATION_CAPABILITY`,
9+
* `@objectstack/spec/contracts`). Step 1 of that contract asks the person in
10+
* place: when the client advertised `elicitation` at `initialize` for the
11+
* session the call rides on, and the door can carry a request to it while the
12+
* call is open, the server sends ONE `elicitation/create` request in form mode
13+
* naming the action, the object and the record. This module is that request.
14+
*
15+
* The runtime owns WHEN it is asked (after every admission gate, the subject
16+
* load and its verdict included, and never for an AI service account); this
17+
* door owns HOW: {@link actionConfirmationElicitorFor} answers a function the
18+
* bridge calls with the subject, or `undefined` when this call cannot be
19+
* elicited, and the runtime then hands the call off (step 2) exactly as
20+
* before.
21+
*
22+
* ## Which doors can elicit
23+
*
24+
* Only a server that read the client's `initialize`. The long-lived server
25+
* behind the stdio transport keeps the client's capabilities for the session
26+
* and carries a request to the client while a call is open, so it elicits. The
27+
* Streamable HTTP door (`handleHttpRequest`) builds a fresh server for every
28+
* POST: the server that answers a `tools/call` never saw the client's
29+
* `initialize`, so it holds no capabilities and this function answers
30+
* `undefined` there. Its callers are handed off, as the contract's step 2
31+
* says a door that cannot elicit does, and are never refused for that alone.
32+
*
33+
* ## The answers
34+
*
35+
* Only the result's `action` is read; any `content` is not (the contract,
36+
* step 3.1), so a client's form payload can neither satisfy nor break it.
37+
*
38+
* - `accept`, `decline`, `cancel`: the client's own answer.
39+
* - `timed_out`: no answer within {@link ACTION_CONFIRMATION_ELICITATION_TIMEOUT_MS}.
40+
* The SDK drops the pending request at that moment, so an answer that
41+
* arrives later is never delivered and runs nothing.
42+
* - `cancel` also stands for an error answer to the request, a result the
43+
* door cannot read, the tool call being cancelled while the question is
44+
* open, and a connection that closes before an answer (the contract reads
45+
* each the same way as a dismissal).
46+
*/
47+
48+
import { z } from 'zod';
49+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
50+
import { ErrorCode, McpError, type ServerNotification, type ServerRequest } from '@modelcontextprotocol/sdk/types.js';
51+
import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
52+
import { AI_ACTION_CONFIRMATION_CAPABILITY } from '@objectstack/spec/contracts';
53+
54+
/**
55+
* The door's bound on an elicited confirmation: how long the server waits for
56+
* the person's answer before it reads the question as unanswered (`timed_out`,
57+
* the contract's step 4, "within the door's bound, which the implementing door
58+
* names"). Five minutes: long enough for a person to read an action and its
59+
* record and decide, short enough that an abandoned question does not hold a
60+
* tool call open for the rest of a session. A door constant, not an
61+
* authorable key: no metadata author or caller sets it.
62+
*/
63+
export const ACTION_CONFIRMATION_ELICITATION_TIMEOUT_MS = 5 * 60_000;
64+
65+
/** What the person is asked to confirm: the action, the object and the record it runs on. */
66+
export interface McpActionConfirmationSubject {
67+
/** The declarative action name. */
68+
actionName: string;
69+
/** The action's label, when its author gave one. */
70+
actionLabel?: string;
71+
/** The object the action operates on; omitted for object-less actions. */
72+
objectName?: string;
73+
/** The record the action runs on, when it takes one. */
74+
recordId?: string;
75+
/** The record's title, when the subject load read one. Never the id restated. */
76+
recordTitle?: string;
77+
}
78+
79+
/** The person's answer to an elicited confirmation, as the door read it. */
80+
export type McpActionConfirmationAnswer = 'accept' | 'decline' | 'cancel' | 'timed_out';
81+
82+
/**
83+
* Ask the person, in their client, to confirm one call. Resolves to the
84+
* answer; never rejects (a failure to ask is a `cancel`).
85+
*/
86+
export type McpActionConfirmationElicitor = (subject: McpActionConfirmationSubject) => Promise<McpActionConfirmationAnswer>;
87+
88+
/**
89+
* What the action tools hand the bridge beside the request: the door's own
90+
* channel for this call, never anything the caller sent. Passed only when the
91+
* call can be elicited; a bridge reads its absence as "hand off".
92+
*/
93+
export interface McpActionCallDoor {
94+
/** Ask the person in their client (step 1); see {@link actionConfirmationElicitorFor}. */
95+
elicitConfirmation: McpActionConfirmationElicitor;
96+
}
97+
98+
/**
99+
* The result shape this door reads: `action` and nothing else. Loose on
100+
* purpose, unlike the SDK's own `ElicitResultSchema`, which also parses
101+
* `content` — a client's form payload is not read (step 3.1), so a payload the
102+
* SDK would refuse must not turn a person's `accept` into a failure.
103+
*/
104+
const ElicitedActionSchema = z.looseObject({ action: z.enum(['accept', 'decline', 'cancel']) });
105+
106+
/** A confirmation asks for nothing but the answer: an empty form. */
107+
const EMPTY_FORM = { type: 'object', properties: {} } as const;
108+
109+
/** The longest free text (a label, a record title) the question carries, in characters. */
110+
export const ACTION_CONFIRMATION_QUESTION_TEXT_MAX = 80;
111+
/** The longest machine name or record id the question carries, in characters. */
112+
export const ACTION_CONFIRMATION_QUESTION_ID_MAX = 200;
113+
114+
/**
115+
* Characters that never reach the person's prompt as themselves: C0 and C1
116+
* controls (line breaks and tabs included), the Unicode line and paragraph
117+
* separators, and the invisible format characters that reorder or hide text
118+
* (bidirectional controls, zero-width characters, the byte-order mark).
119+
*/
120+
const UNSHOWN = /[\u0000-\u001f\u007f-\u009f\u2028\u2029\u200b-\u200f\u202a-\u202e\u2060-\u2069\ufeff]/gu;
121+
/** Markup and quoting characters a client might render or a reader might take as structure. */
122+
const MARKUP = /[<>`*_[\]{}|#"\\]/gu;
123+
124+
/** At most `max` characters (code points), with a visible mark when it was cut. */
125+
function bounded(text: string, max: number): string {
126+
const chars = Array.from(text);
127+
return chars.length <= max ? text : `${chars.slice(0, max - 1).join('')}…`;
128+
}
129+
130+
/**
131+
* Free text written by an author or stored on a record (an action label, a
132+
* record title), made safe for one labelled line of the question: every
133+
* unshown character becomes a space, markup characters and double quotes are
134+
* dropped, a single quote becomes a typographic apostrophe, runs of spaces collapse, and the result is bounded. `undefined`
135+
* when nothing readable is left.
136+
*/
137+
export function confirmationQuestionText(text: string | undefined): string | undefined {
138+
if (typeof text !== 'string') return undefined;
139+
const plain = text.replace(UNSHOWN, ' ').replace(MARKUP, '').replace(/'/gu, '\u2019').replace(/\s+/gu, ' ').trim();
140+
return plain === '' ? undefined : bounded(plain, ACTION_CONFIRMATION_QUESTION_TEXT_MAX);
141+
}
142+
143+
/**
144+
* A machine name or record id for its own labelled line: kept character for
145+
* character so it still names exactly one record, except that an unshown
146+
* character is shown as U+FFFD, and bounded.
147+
*/
148+
function confirmationQuestionId(id: string): string {
149+
return bounded(id.replace(UNSHOWN, '\ufffd'), ACTION_CONFIRMATION_QUESTION_ID_MAX);
150+
}
151+
152+
/**
153+
* The question the person reads: the action, the object and the record it
154+
* runs on (its id, and its title when the subject load read one), and what
155+
* each answer does.
156+
*
157+
* One fact per labelled line, in a fixed order, the record id BEFORE the
158+
* title: every value is reduced to a single line first (no value can start a
159+
* line of its own), so the id line is always the one this door wrote, and a
160+
* title cannot pose as another record's id or as the end of the question.
161+
*/
162+
export function actionConfirmationQuestion(subject: McpActionConfirmationSubject): string {
163+
const name = confirmationQuestionId(subject.actionName);
164+
const label = confirmationQuestionText(subject.actionLabel);
165+
const title = subject.recordId !== undefined ? confirmationQuestionText(subject.recordTitle) : undefined;
166+
const lines = [
167+
'Your AI assistant asks to run an action whose author requires your confirmation. Nothing has run yet.',
168+
`Action: ${label && label !== name ? `${label} (${name})` : name}`,
169+
...(subject.objectName ? [`Object: ${confirmationQuestionId(subject.objectName)}`] : []),
170+
...(subject.recordId !== undefined ? [`Record id: ${confirmationQuestionId(subject.recordId)}`] : []),
171+
...(title !== undefined ? [`Record title: ${title}`] : []),
172+
'Accept runs it once, as you. Decline refuses it.',
173+
];
174+
return lines.join('\n');
175+
}
176+
177+
/**
178+
* The elicitor for the tool call `extra` belongs to, or `undefined` when this
179+
* call cannot be elicited: the client did not advertise form-mode
180+
* `elicitation` at `initialize` on this server (an empty `elicitation: {}`
181+
* reads as form mode, MCP 2025-11-25, normalised by the SDK), which is always
182+
* the case on the per-request Streamable HTTP server.
183+
*
184+
* The request rides the tool call (`extra.sendRequest` relates it to the open
185+
* call), is bounded by `timeoutMs`, and is abandoned when the tool call is
186+
* cancelled (`extra.signal`).
187+
*/
188+
export function actionConfirmationElicitorFor(
189+
server: McpServer,
190+
extra: RequestHandlerExtra<ServerRequest, ServerNotification> | undefined,
191+
timeoutMs: number = ACTION_CONFIRMATION_ELICITATION_TIMEOUT_MS,
192+
): McpActionConfirmationElicitor | undefined {
193+
const capability = server.server.getClientCapabilities()?.[AI_ACTION_CONFIRMATION_CAPABILITY];
194+
if (!capability?.form || typeof extra?.sendRequest !== 'function') return undefined;
195+
return async (subject) => {
196+
try {
197+
const result = await extra.sendRequest(
198+
{
199+
method: 'elicitation/create',
200+
params: { mode: 'form', message: actionConfirmationQuestion(subject), requestedSchema: EMPTY_FORM },
201+
},
202+
ElicitedActionSchema,
203+
{ timeout: timeoutMs, signal: extra.signal },
204+
);
205+
return result.action;
206+
} catch (error) {
207+
// Asked first: the SDK rejects an ABORTED request with a
208+
// `RequestTimeout` error too, and the call's signal aborts both when
209+
// the client cancels the tool call and when the connection closes.
210+
if (extra.signal?.aborted) return 'cancel';
211+
return error instanceof McpError && error.code === ErrorCode.RequestTimeout ? 'timed_out' : 'cancel';
212+
}
213+
};
214+
}

‎packages/mcp/src/index.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ export type {
5555
RegisterActionToolsOptions,
5656
McpFederationBridge,
5757
} from './mcp-http-tools.js';
58+
// [#33712] Step 1 of the amended confirmation contract: the person asked in their client.
59+
export {
60+
ACTION_CONFIRMATION_ELICITATION_TIMEOUT_MS,
61+
ACTION_CONFIRMATION_QUESTION_ID_MAX,
62+
ACTION_CONFIRMATION_QUESTION_TEXT_MAX,
63+
actionConfirmationElicitorFor,
64+
actionConfirmationQuestion,
65+
confirmationQuestionText,
66+
} from './action-confirmation-elicitation.js';
67+
export type {
68+
McpActionCallDoor,
69+
McpActionConfirmationAnswer,
70+
McpActionConfirmationElicitor,
71+
McpActionConfirmationSubject,
72+
} from './action-confirmation-elicitation.js';
5873
// The portable `SKILL.md` distributable (ADR-0036 Amendment C) — NOT the
5974
// `skill` metadata type; that one is projected onto MCP prompts just below.
6075
export {

0 commit comments

Comments
 (0)