From c302aa2dd383563e477271e847a561edd406646f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 22:52:30 +0000 Subject: [PATCH 1/2] fix(runtime,mcp): the no_confirmation_service refusal names the route that works on the door that asked The stdio door, for a client without elicitation, names a client that supports confirmation (step 3); every door says a person performs it in the app and the same change is not made with another tool. Streamable HTTP keeps the in-app route alone. Claude-Session: https://claude.ai/code/session_01QSeKYo86w1wqy2z2fMrryr Co-authored-by: Claude --- .../34325-door-aware-no-service-refusal.md | 9 +++ .../src/action-confirmation-elicitation.ts | 52 ++++++++++++-- ...-action-confirmation-handoff-33690.test.ts | 52 +++++++++++++- packages/mcp/src/mcp-http-tools.ts | 27 +++++--- .../action-confirmation-handoff-33690.test.ts | 67 +++++++++++++++++++ packages/runtime/src/action-dispatch.ts | 8 ++- packages/runtime/src/action-execution.ts | 57 ++++++++++++++-- packages/runtime/src/domains/mcp.ts | 33 +++++++-- 8 files changed, 277 insertions(+), 28 deletions(-) create mode 100644 .changeset/34325-door-aware-no-service-refusal.md diff --git a/.changeset/34325-door-aware-no-service-refusal.md b/.changeset/34325-door-aware-no-service-refusal.md new file mode 100644 index 00000000000..fe964d356c0 --- /dev/null +++ b/.changeset/34325-door-aware-no-service-refusal.md @@ -0,0 +1,9 @@ +--- +'@objectstack/runtime': patch +'@objectstack/mcp': patch +--- + +Clause-②: no +Metadata-protocol: none + +The `no_confirmation_service` refusal (`428 ACTION_CONFIRMATION_REQUIRED`) of the MCP `run_action` and `resume_run` tools now names the route that works on the door that asked. On every door it says that a person performs the action in the app and that the same change must not be made with another tool. On the stdio door, for a client that did not advertise `elicitation`, it also says that a client that supports confirmation is asked in place on that server. The Streamable HTTP door, which asks no client, does not carry that sentence. The code, the status and `details` are unchanged. `McpActionCallDoor.elicitConfirmation` is now optional: the tools pass a door without an elicitor (`elicitsCapableClients: true`) for a stdio client without `elicitation`, so a bridge reads the elicitor before calling it. diff --git a/packages/mcp/src/action-confirmation-elicitation.ts b/packages/mcp/src/action-confirmation-elicitation.ts index 729eed6cb05..c1d8387b73b 100644 --- a/packages/mcp/src/action-confirmation-elicitation.ts +++ b/packages/mcp/src/action-confirmation-elicitation.ts @@ -87,12 +87,27 @@ export type McpActionConfirmationElicitor = (subject: McpActionConfirmationSubje /** * What the action tools hand the bridge beside the request: the door's own - * channel for this call, never anything the caller sent. Passed only when the - * call can be elicited; a bridge reads its absence as "hand off". + * facts about this call, never anything the caller sent + * ({@link actionCallDoorFor}). A bridge reads a missing elicitor as "hand + * off"; with no door at all, nothing is known about the door. */ export interface McpActionCallDoor { - /** Ask the person in their client (step 1); see {@link actionConfirmationElicitorFor}. */ - elicitConfirmation: McpActionConfirmationElicitor; + /** + * Ask the person in their client (step 1); see + * {@link actionConfirmationElicitorFor}. Present only when this call can be + * elicited. + */ + elicitConfirmation?: McpActionConfirmationElicitor; + /** + * [#34325] `true` when this door would ask a client that advertised + * `elicitation` (it read the client's `initialize` and can carry a request + * to it while the call is open) and this call's client did not advertise + * it, so no elicitor rides beside it. The `no_confirmation_service` + * refusal then names the route that works here: a client that supports + * confirmation (step 3). Never set on a door that cannot ask any client, + * where that sentence would be false. + */ + elicitsCapableClients?: true; } /** @@ -212,3 +227,32 @@ export function actionConfirmationElicitorFor( } }; } + +/** + * [#34325] The door the action tools hand the bridge for the tool call `extra` + * belongs to ({@link McpActionCallDoor}), or `undefined` when there is + * nothing to tell it: + * + * - the client can be elicited: its elicitor (step 1); + * - this server read the client's `initialize` and can carry a request to it, + * but the client advertised no form-mode `elicitation`: + * `elicitsCapableClients`, so a `no_confirmation_service` refusal tells the + * caller that a client supporting confirmation is asked in place here. That + * is the long-lived stdio server today; + * - this server never read the client's `initialize`: `undefined`, the bridge + * called as before. That is the per-request Streamable HTTP server, which + * asks no client, so the refusal names only the in-app route there. + * + * Judged on what the server can do, never on a transport name: a door that + * comes to read `initialize` gets the step-3 sentence with the elicitation + * that makes it true. + */ +export function actionCallDoorFor( + server: McpServer, + extra: RequestHandlerExtra | undefined, +): McpActionCallDoor | undefined { + const elicitConfirmation = actionConfirmationElicitorFor(server, extra); + if (elicitConfirmation) return { elicitConfirmation }; + const readInitialize = server.server.getClientCapabilities() !== undefined; + return readInitialize && typeof extra?.sendRequest === 'function' ? { elicitsCapableClients: true } : undefined; +} diff --git a/packages/mcp/src/mcp-action-confirmation-handoff-33690.test.ts b/packages/mcp/src/mcp-action-confirmation-handoff-33690.test.ts index ab724ce1b2a..4885c07f171 100644 --- a/packages/mcp/src/mcp-action-confirmation-handoff-33690.test.ts +++ b/packages/mcp/src/mcp-action-confirmation-handoff-33690.test.ts @@ -274,7 +274,7 @@ async function openStdioClient(server: McpServer, opts: { elicitation: boolean; function elicitingBridge() { const calls: Array<{ tool: string; door: McpActionCallDoor | undefined; argCount: number }> = []; const confirmWith = async (door: McpActionCallDoor | undefined, name: string) => { - if (!door) return pendingOf(1); + if (!door?.elicitConfirmation) return pendingOf(1); const answer = await door.elicitConfirmation({ actionName: name, actionLabel: 'Archive Account', objectName: 'account', recordId: 'a1', recordTitle: 'Acme', }); @@ -356,11 +356,13 @@ describe('[#33712] stdio: a client that advertises elicitation is asked in place expect(JSON.parse(declined.result.content[0].text).error.details.reason).toBe('declined'); }); - it('a client WITHOUT the capability is never asked: the bridge is called exactly as before and hands off', async () => { + it('a client WITHOUT the capability is never asked: the bridge gets no elicitor and hands off', async () => { const { result, calls } = await stdioCall({ elicitation: false }); expect(result.isError).toBeFalsy(); expect(JSON.parse(result.content[0].text)).toEqual(pendingOf(1)); - expect(calls).toEqual([{ tool: 'run_action', door: undefined, argCount: 2 }]); + // [#34325] The door's one fact for this call: it would have asked a + // client that supports confirmation. No elicitor rides beside it. + expect(calls).toEqual([{ tool: 'run_action', door: { elicitsCapableClients: true }, argCount: 3 }]); }); }); @@ -527,3 +529,47 @@ describe('[#35778] run_action names the next step on a no_confirmation_service r ); }); }); + +/** + * [#34325] Which door asked, as the bridge is told it: the runtime words the + * `no_confirmation_service` refusal from it (pinned in + * `packages/runtime/src/action-confirmation-handoff-33690.test.ts`). The + * long-lived stdio server read the client's `initialize`, so for a client + * without `elicitation` it says it would have asked a client that supports + * confirmation (`elicitsCapableClients`), on both tools. The per-request + * Streamable HTTP server asks no client and says nothing: the bridge is + * called exactly as before, even for a client that advertised the capability + * at `initialize`, so the refusal keeps the in-app route alone there. + */ +describe('[#34325] the door the action tools hand the bridge names whether a client that supports confirmation is asked here', () => { + for (const tool of ['run_action', 'resume_run'] as const) { + it(`stdio, a client without elicitation: ${tool} hands the bridge elicitsCapableClients and no elicitor`, async () => { + const { calls, asked } = await stdioCall({ elicitation: false }, tool); + expect(asked).toEqual([]); + expect(calls).toHaveLength(1); + expect(calls[0].argCount).toBe(3); + expect(calls[0].door).toStrictEqual({ elicitsCapableClients: true }); + }); + + it(`CONTROL stdio, a client with elicitation: ${tool} hands the bridge the elicitor and not the flag`, async () => { + const { calls } = await stdioCall({ elicitation: true, answer: { action: 'accept' } }, tool); + expect(Object.keys(calls[0].door ?? {})).toEqual(['elicitConfirmation']); + }); + + it(`Streamable HTTP, after an initialize that advertised elicitation: ${tool} calls the bridge with no door at all`, async () => { + const runtime = new MCPServerRuntime({ name: 'objectstack-test', version: '9.9.9' }); + const bridge = elicitingBridge(); + const init = { + jsonrpc: '2.0', id: 0, method: 'initialize', + params: { protocolVersion: '2025-11-25', capabilities: { elicitation: {} }, clientInfo: { name: 'c', version: '1' } }, + }; + expect((await runtime.handleHttpRequest(mcpRequest(init), { bridge, parsedBody: init })).status).toBe(200); + const args = tool === 'run_action' ? { actionName: GATED, recordId: 'a1' } : { runId: 'run_1', values: { reason: 'x' } }; + const body = toolsCall(1, tool, args); + const req = mcpRequest(body); + req.headers.set('mcp-protocol-version', '2025-11-25'); + await runtime.handleHttpRequest(req, { bridge, parsedBody: body }); + expect(bridge.calls).toEqual([{ tool, door: undefined, argCount: 2 }]); + }); + } +}); diff --git a/packages/mcp/src/mcp-http-tools.ts b/packages/mcp/src/mcp-http-tools.ts index 4a867dae7a8..3e66f4fe7c6 100644 --- a/packages/mcp/src/mcp-http-tools.ts +++ b/packages/mcp/src/mcp-http-tools.ts @@ -137,7 +137,7 @@ import { } from './metadata-completeness.js'; // [#30892] The file seam and what `read_file` renders from it. import { READ_FILE_MAX_BYTES, ReadFileExtractionBusyError, renderReadFile, type McpFileBridge } from './file-content.js'; -import { actionConfirmationElicitorFor, type McpActionCallDoor } from './action-confirmation-elicitation.js'; +import { actionCallDoorFor, type McpActionCallDoor } from './action-confirmation-elicitation.js'; import type { McpLatestPer } from './types.js'; // [#35145] `expand` and `related`: the relation reads, judged before any read. import { @@ -683,7 +683,10 @@ export interface McpActionBridge { * `elicitation` on a door that can carry a request to it), the host asks * the person through `door.elicitConfirmation` first, once every admission * gate has passed: `accept` runs the call, any other answer refuses it, and - * nothing is handed off. Without `door` the call is handed off as above. + * nothing is handed off. Without an elicitor the call is handed off as + * above. [#34325] `door.elicitsCapableClients` (no elicitor beside it) says + * this door would have asked a client that advertised `elicitation`: the + * `no_confirmation_service` refusal then names that route too. */ runAction( name: string, @@ -5097,11 +5100,14 @@ export function registerActionTools( }; // [#33712] Step 1 of the amended confirmation contract: a client that // advertised `elicitation` on a server that read its `initialize` (the - // stdio door) is asked in place. Otherwise the bridge is called - // exactly as before and hands a gated call off. - const elicitConfirmation = actionConfirmationElicitorFor(server, extra); - const result = elicitConfirmation - ? await bridge.runAction(actionName, request, { elicitConfirmation }) + // stdio door) is asked in place. Otherwise the bridge hands a gated + // call off. [#34325] On that door a client without the capability is + // named to the bridge (`elicitsCapableClients`), so a no-service + // refusal names the client route; the per-request HTTP server calls + // the bridge exactly as before. + const door = actionCallDoorFor(server, extra); + const result = door + ? await bridge.runAction(actionName, request, door) : await bridge.runAction(actionName, request); return textResult(result); } catch (err) { @@ -5188,9 +5194,10 @@ export function registerActionTools( // at the closed input, as on `run_action`. const request = { values }; // [#33712] As `run_action`: asked in place where the client can be. - const elicitConfirmation = actionConfirmationElicitorFor(server, extra); - const result = elicitConfirmation - ? await resumeRun(runId, request, { elicitConfirmation }) + // [#34325] And the same door facts for a no-service refusal. + const door = actionCallDoorFor(server, extra); + const result = door + ? await resumeRun(runId, request, door) : await resumeRun(runId, request); return textResult(result); } catch (err) { diff --git a/packages/runtime/src/action-confirmation-handoff-33690.test.ts b/packages/runtime/src/action-confirmation-handoff-33690.test.ts index 53377f9266d..4904b079acd 100644 --- a/packages/runtime/src/action-confirmation-handoff-33690.test.ts +++ b/packages/runtime/src/action-confirmation-handoff-33690.test.ts @@ -861,3 +861,70 @@ describe('[#34515] a resume approval is bound to the screen it was given on', () expect(h.runs.get(runId)?.status).toBe('completed'); }); }); + +/** + * [#34325] The `no_confirmation_service` refusal names the route that works on + * the door that asked. Every door: a person performs it in the app, and the + * caller makes no such change through another tool (an agent that read only + * "in the app" completed the change with a raw record update). The stdio door + * for a client without `elicitation` (`door.elicitsCapableClients`, set by + * `@objectstack/mcp`'s `actionCallDoorFor`) also names a client that supports + * confirmation (step 3); the Streamable HTTP door, which asks no client and + * passes no door, does not, since that sentence would be false there. The + * envelope is unchanged: same code, status and details on both doors. + */ +describe('[#34325] the no_confirmation_service refusal names the route that works on the door that asked', () => { + const IN_APP = 'a person performs it in the app: do not make the same change with another tool.'; + const CLIENT = 'A client that supports confirmation (MCP elicitation) is asked in place on this server'; + const STDIO_NO_ELICITATION = { elicitsCapableClients: true } as const; + + async function pausedRun(h: ReturnType): Promise { + const started: any = await h.automation.execute(GATED_FLOW.target, { userId: 'u1', object: OBJECT, record: { id: 'lead_1' } }); + return started.runId; + } + + /** Each tool's no-service refusal through the real bridge, with the door the tool would pass (or none). */ + async function refusedAt(tool: 'run_action' | 'resume_run', door: Record | undefined) { + const h = makeHarness(); + const bridge = h.bridgeAs(PERSON); + const args: unknown[] = tool === 'run_action' + ? [GATED.name, { recordId: 'lead_1' }] + : [await pausedRun(h), { values: { reason: 'x' } }]; + if (door) args.push(door); + const refused = await refusalOf(tool === 'run_action' ? bridge.runAction(...args) : bridge.resumeRun(...args)); + expect({ code: refused.code, status: refused.status }, tool).toEqual({ code: 'ACTION_CONFIRMATION_REQUIRED', status: 428 }); + expect(refused.details?.reason, tool).toBe('no_confirmation_service'); + expect(h.ql.executeAction).not.toHaveBeenCalled(); + expect(h.automation.resume).not.toHaveBeenCalled(); + return refused; + } + + for (const tool of ['run_action', 'resume_run'] as const) { + it(`stdio, a client without elicitation (${tool}): names a client that supports confirmation, then the app, and no other tool`, async () => { + const refused = await refusedAt(tool, STDIO_NO_ELICITATION); + expect(refused.message).toContain(`${CLIENT}: use one to confirm it here. Otherwise ${IN_APP}`); + }); + + it(`Streamable HTTP, no door (${tool}): the app and no other tool, never the client sentence`, async () => { + const refused = await refusedAt(tool, undefined); + expect(refused.message).toContain(`does not count. A${IN_APP.slice(1)}`); + expect(refused.message).not.toContain('supports confirmation'); + expect(refused.message).not.toContain('elicitation'); + }); + + it(`no new response field (${tool}): both doors answer the same details`, async () => { + const stdio = await refusedAt(tool, STDIO_NO_ELICITATION); + const http = await refusedAt(tool, undefined); + expect(stdio.details).toEqual(http.details); + }); + } + + it('CONTROL: the door fact is never handed to the host\'s service (the hand-off is the contract\'s shape)', async () => { + const service = makeConfirmationService(); + const h = makeHarness({ service }); + await h.bridgeAs(PERSON).runAction(GATED.name, { recordId: 'lead_1' }, STDIO_NO_ELICITATION); + expect((service.submit.mock.calls[0] as any[])[0]).toEqual({ + actionName: GATED.name, objectName: OBJECT, recordId: 'lead_1', params: {}, door: 'mcp', + }); + }); +}); diff --git a/packages/runtime/src/action-dispatch.ts b/packages/runtime/src/action-dispatch.ts index 6baf1f2d15b..26dd2b2f3f5 100644 --- a/packages/runtime/src/action-dispatch.ts +++ b/packages/runtime/src/action-dispatch.ts @@ -172,6 +172,12 @@ export interface ResolvedActionCall { * answer refuses it, and nothing is handed off. */ elicitConfirmation?: actionExec.ActionConfirmationElicitor; + /** + * [#34325] The door would ask a client that supports confirmation, + * and this call's client does not (`actionExec.ActionConfirmationDoor`): + * a `no_confirmation_service` refusal names that route too. + */ + elicitsCapableClients?: boolean; }; /** * [ADR-0106 D1] This door's answer for a name nothing declares, where it @@ -425,7 +431,7 @@ async function confirmAdmittedAction( ...(subjectRecordId !== undefined ? { recordId: subjectRecordId } : {}), params, door: handOff.door, - }, wiring.ec); + }, wiring.ec, { elicitsCapableClients: handOff.elicitsCapableClients === true }); if ('refused' in answer) { const { refused } = answer; return { diff --git a/packages/runtime/src/action-execution.ts b/packages/runtime/src/action-execution.ts index 5a34a39a17d..a436ab72b90 100644 --- a/packages/runtime/src/action-execution.ts +++ b/packages/runtime/src/action-execution.ts @@ -3360,6 +3360,36 @@ export async function resolveActionConfirmationService( } } +/** + * [#34325] What the door that asked knows about its caller's client, passed + * beside the hand-off and never on it (the host's service is not told). + * Structurally the `elicitsCapableClients` half of `McpActionCallDoor` + * (`@objectstack/mcp`), which this package does not depend on. + */ +export interface ActionConfirmationDoor { + /** + * The door would ask a client that advertised `elicitation` (it read the + * client's `initialize` and can carry a request to it), and this call's + * client did not advertise it. Absent: nothing is known, or the door asks + * no client. + */ + elicitsCapableClients?: boolean; +} + +/** + * [#34325] The `no_confirmation_service` refusal's routes. On every door: a + * person performs it in the app, and the caller makes no such change through + * another tool. Before it, only for a door that would ask a client that + * supports confirmation: that client (step 3 of the amended contract). + */ +const NO_SERVICE_IN_APP_ROUTE = 'a person performs it in the app: do not make the same change with another tool.'; +function noServiceRoutes(door: ActionConfirmationDoor): string { + return door.elicitsCapableClients === true + ? 'A client that supports confirmation (MCP elicitation) is asked in place on this server: use one to ' + + `confirm it here. Otherwise ${NO_SERVICE_IN_APP_ROUTE}` + : `${NO_SERVICE_IN_APP_ROUTE.charAt(0).toUpperCase()}${NO_SERVICE_IN_APP_ROUTE.slice(1)}`; +} + /** * [#33690] Hand a declared-gated call off to the person it runs as (step 2 of * the amended contract), or refuse it when the host has no service to hand it @@ -3373,9 +3403,17 @@ export async function resolveActionConfirmationService( * approver with every gate re-checked, a rejection, a lapse — is the * host's (`IActionConfirmationService`). * - None: `428 ACTION_CONFIRMATION_REQUIRED`, `details.reason: - * 'no_confirmation_service'`. The message names the one route that works on - * this server — performing the action in the app — and no retry: no request - * this caller can send runs the action here. + * 'no_confirmation_service'`. The message names the routes that work for + * the door that asked, and no retry of this call: no request this caller + * sends from this client runs the action here. [#34325] On every door a + * person performs it in the app, and the caller is told not to make the + * same change through another tool (an agent that read only "in the app" + * completed it with a raw record update). Where `door.elicitsCapableClients` + * says the door would have asked a client that supports confirmation (the + * stdio door, for a client that advertised no `elicitation`), the message + * also names that route (step 3 of the amended contract). Without it (the + * Streamable HTTP door, which asks no client, or a caller that says + * nothing about its door) that sentence would be false and is left out. * * A service that answers no `pendingId` is a broken host, never a hand-off * that happened: thrown, so the caller is not told a person was asked. @@ -3386,6 +3424,7 @@ export async function handOffActionConfirmation( envId: string | undefined, handOff: ActionConfirmationHandOff, ec: any, + door: ActionConfirmationDoor = {}, ): Promise<{ pending: ActionConfirmationPending } | { refused: ActionConfirmationRefusal }> { const on = confirmationSubjectOn(handOff.objectName); const declared = `Action '${handOff.actionName}'${on} declares ai.requiresConfirmation: true, so a person confirms it`; @@ -3395,7 +3434,7 @@ export async function handOffActionConfirmation( refused: confirmationRefusalOf( handOff.actionName, handOff.objectName, `${declared} — nothing was run. This server has no pending-confirmation service to ask them through, ` - + `and a confirmation sent on the request does not count. Perform the action in the app instead.`, + + `and a confirmation sent on the request does not count. ${noServiceRoutes(door)}`, 'no_confirmation_service', ), }; @@ -5273,9 +5312,16 @@ export async function invokeBusinessAction(deps: ActionExecutionDeps, * handed off; see {@link elicitActionConfirmation}. */ elicitConfirmation?: ActionConfirmationElicitor; + /** + * [#34325] Set by the MCP door, without an elicitor, when it would ask + * a client that supports confirmation and this call's client does not + * ({@link ActionConfirmationDoor}): a `no_confirmation_service` + * refusal then names that route. + */ + elicitsCapableClients?: boolean; }, ): Promise { - const { driver, envId, ec, getMeta, readObjects, readActions, callData, elicitConfirmation } = wiring; + const { driver, envId, ec, getMeta, readObjects, readActions, callData, elicitConfirmation, elicitsCapableClients } = wiring; const meta: any = await getMeta(); const params = input?.params && typeof input.params === 'object' ? input.params : {}; const recordId = typeof input?.recordId === 'string' && input.recordId.length > 0 ? input.recordId : undefined; @@ -5366,6 +5412,7 @@ export async function invokeBusinessAction(deps: ActionExecutionDeps, door: 'mcp', ...(namespace !== undefined ? { namespace } : {}), ...(elicitConfirmation ? { elicitConfirmation } : {}), + ...(elicitsCapableClients === true ? { elicitsCapableClients: true } : {}), }, ql: engine, wiring: { diff --git a/packages/runtime/src/domains/mcp.ts b/packages/runtime/src/domains/mcp.ts index ede5c42baca..b5e45b812d3 100644 --- a/packages/runtime/src/domains/mcp.ts +++ b/packages/runtime/src/domains/mcp.ts @@ -965,6 +965,25 @@ function actionDeclarationReads(deps: DomainHandlerDeps, context: HttpProtocolCo return { getMeta, getProtocol, readMergedObjects, readServedObjects, readServedActions }; } +/** + * [#33712, #34325] What the MCP action tools hand the bridge beside a call + * (`McpActionCallDoor`, `@objectstack/mcp`, which this package does not + * depend on): the person's client as an elicitor, or the fact that the door + * would have asked a client that supports confirmation. + */ +type McpActionCallDoorFacts = { + elicitConfirmation?: actionExec.ActionConfirmationElicitor; + elicitsCapableClients?: boolean; +}; + +/** The door's facts as `invokeBusinessAction` / `resumeActionRun` wiring: each only when the door set it. */ +function actionCallDoorWiring(door: McpActionCallDoorFacts | undefined): McpActionCallDoorFacts { + return { + ...(typeof door?.elicitConfirmation === 'function' ? { elicitConfirmation: door.elicitConfirmation } : {}), + ...(door?.elicitsCapableClients === true ? { elicitsCapableClients: true } : {}), + }; +} + /** * Build a principal-bound {@link McpDataBridge}: every method runs AS the * request's ExecutionContext through {@link callData} (RLS/permissions) and @@ -1573,10 +1592,12 @@ export function buildMcpBridge( input: { objectName?: string; namespace?: string; recordId?: string; params?: Record } & AIActionConfirmation, // [#33712] The door's channel to the person's client, set by the // tool only when the client can be elicited (`McpActionCallDoor`). - door?: { elicitConfirmation?: actionExec.ActionConfirmationElicitor }, + // [#34325] Or, without one, `elicitsCapableClients`: the door + // would have asked a client that supports confirmation. + door?: McpActionCallDoorFacts, ) => actionExec.invokeBusinessAction(deps, context, name, input ?? {}, { driver, envId, ec, getMeta, readObjects: readServedObjects, readActions: readServedActions, callData, - ...(typeof door?.elicitConfirmation === 'function' ? { elicitConfirmation: door.elicitConfirmation } : {}), + ...actionCallDoorWiring(door), }), // [#15705] `resume_run`: continue the caller's own paused screen run. // Admitted by the same gates as `run_action`; see @@ -1584,10 +1605,10 @@ export function buildMcpBridge( resumeRun: async ( runId: string, input: { values?: Record } & AIActionConfirmation, - door?: { elicitConfirmation?: actionExec.ActionConfirmationElicitor }, + door?: McpActionCallDoorFacts, ) => resumeActionRun(deps, context, runId, input ?? {}, { driver, envId, ec, getMeta, readObjects: readServedObjects, readActions: readServedActions, callData, - ...(typeof door?.elicitConfirmation === 'function' ? { elicitConfirmation: door.elicitConfirmation } : {}), + ...actionCallDoorWiring(door), }), // ── Federation surface (McpFederationBridge, #27745) ─────── // The `external-datasource` service Studio's datasource page reaches @@ -2413,6 +2434,8 @@ export async function resumeActionRun( callData: (action: string, params: any, dataDriver?: any, scopeId?: string, ec?: any) => Promise; /** [#33712] As `invokeBusinessAction`'s: the person asked in their client, in place of a hand-off. */ elicitConfirmation?: actionExec.ActionConfirmationElicitor; + /** [#34325] As `invokeBusinessAction`'s: a no-service refusal names the client route too. */ + elicitsCapableClients?: boolean; /** * [#34386] Present exactly when the call comes through the host's * resume door ({@link resumeActionRunRequest}), never at the MCP @@ -2579,7 +2602,7 @@ export async function resumeActionRun( params: {}, door: 'mcp', run: { runId, values: values ?? {}, ...(screenNodeId !== undefined ? { screenNodeId } : {}) }, - }, ec); + }, ec, { elicitsCapableClients: wiring.elicitsCapableClients === true }); if ('refused' in answer) { throw resumeDoorError(deps, answer.refused.message, answer.refused.status, { code: answer.refused.code, From fa794d0d19c9ed1b4f95c961d1ff53a7e295b74a Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 23:40:06 +0000 Subject: [PATCH 2/2] fix(mcp,runtime): carry the stdio door fact on an additive fourth argument, McpActionCallDoor unchanged McpActionCallDoor stays as on main (elicitConfirmation required, passed only when the client can be elicited). The stdio fact rides as a new optional fourth parameter typed by the new McpActionCallDoorFacts export, which a bridge built against main ignores. Claude-Session: https://claude.ai/code/session_01QSeKYo86w1wqy2z2fMrryr Co-authored-by: Claude --- .../34325-door-aware-no-service-refusal.md | 4 +- .../src/action-confirmation-elicitation.ts | 58 ++++++++++--------- packages/mcp/src/index.ts | 1 + ...-action-confirmation-handoff-33690.test.ts | 39 +++++++------ packages/mcp/src/mcp-http-tools.ts | 28 +++++---- .../action-confirmation-handoff-33690.test.ts | 17 +++--- packages/runtime/src/action-execution.ts | 4 +- packages/runtime/src/domains/mcp.ts | 41 +++++++------ 8 files changed, 107 insertions(+), 85 deletions(-) diff --git a/.changeset/34325-door-aware-no-service-refusal.md b/.changeset/34325-door-aware-no-service-refusal.md index fe964d356c0..5f933cab7d5 100644 --- a/.changeset/34325-door-aware-no-service-refusal.md +++ b/.changeset/34325-door-aware-no-service-refusal.md @@ -3,7 +3,7 @@ '@objectstack/mcp': patch --- -Clause-②: no +Clause-②: yes (widening) Metadata-protocol: none -The `no_confirmation_service` refusal (`428 ACTION_CONFIRMATION_REQUIRED`) of the MCP `run_action` and `resume_run` tools now names the route that works on the door that asked. On every door it says that a person performs the action in the app and that the same change must not be made with another tool. On the stdio door, for a client that did not advertise `elicitation`, it also says that a client that supports confirmation is asked in place on that server. The Streamable HTTP door, which asks no client, does not carry that sentence. The code, the status and `details` are unchanged. `McpActionCallDoor.elicitConfirmation` is now optional: the tools pass a door without an elicitor (`elicitsCapableClients: true`) for a stdio client without `elicitation`, so a bridge reads the elicitor before calling it. +The `no_confirmation_service` refusal (`428 ACTION_CONFIRMATION_REQUIRED`) of the MCP `run_action` and `resume_run` tools now names the route that works on the door that asked. On every door it says that a person performs the action in the app and that the same change must not be made with another tool. On the stdio door, for a client that did not advertise `elicitation`, it also says that a client that supports confirmation is asked in place on that server. The Streamable HTTP door, which asks no client, does not carry that sentence. The code, the status and `details` are unchanged. No type is made optional: `McpActionCallDoor` is unchanged, and it is still passed only when the client can be elicited. The added, optional surface is a new exported type `McpActionCallDoorFacts` (`{ elicitsCapableClients?: true }`) and an optional fourth parameter `facts` on `McpActionBridge.runAction` and `resumeRun`. The tools pass it, after an `undefined` door, only for a stdio client without `elicitation`. A bridge that does not read it compiles and answers as before. diff --git a/packages/mcp/src/action-confirmation-elicitation.ts b/packages/mcp/src/action-confirmation-elicitation.ts index c1d8387b73b..9056d56b91b 100644 --- a/packages/mcp/src/action-confirmation-elicitation.ts +++ b/packages/mcp/src/action-confirmation-elicitation.ts @@ -87,25 +87,28 @@ export type McpActionConfirmationElicitor = (subject: McpActionConfirmationSubje /** * What the action tools hand the bridge beside the request: the door's own - * facts about this call, never anything the caller sent - * ({@link actionCallDoorFor}). A bridge reads a missing elicitor as "hand - * off"; with no door at all, nothing is known about the door. + * channel for this call, never anything the caller sent. Passed only when the + * call can be elicited; a bridge reads its absence as "hand off". */ export interface McpActionCallDoor { + /** Ask the person in their client (step 1); see {@link actionConfirmationElicitorFor}. */ + elicitConfirmation: McpActionConfirmationElicitor; +} + +/** + * [#34325] What the action tools tell the bridge about the door when no + * elicitor rides beside the call, passed as the bridge method's fourth + * argument (after an `undefined` door). Additive: a bridge that does not read + * it hands the call off exactly as before. + */ +export interface McpActionCallDoorFacts { /** - * Ask the person in their client (step 1); see - * {@link actionConfirmationElicitorFor}. Present only when this call can be - * elicited. - */ - elicitConfirmation?: McpActionConfirmationElicitor; - /** - * [#34325] `true` when this door would ask a client that advertised - * `elicitation` (it read the client's `initialize` and can carry a request - * to it while the call is open) and this call's client did not advertise - * it, so no elicitor rides beside it. The `no_confirmation_service` - * refusal then names the route that works here: a client that supports - * confirmation (step 3). Never set on a door that cannot ask any client, - * where that sentence would be false. + * This door would ask a client that advertised `elicitation` (it read the + * client's `initialize` and can carry a request to it while the call is + * open), and this call's client did not advertise it. The + * `no_confirmation_service` refusal then names the route that works here: a + * client that supports confirmation (step 3). Never set on a door that + * cannot ask any client, where that sentence would be false. */ elicitsCapableClients?: true; } @@ -229,19 +232,18 @@ export function actionConfirmationElicitorFor( } /** - * [#34325] The door the action tools hand the bridge for the tool call `extra` - * belongs to ({@link McpActionCallDoor}), or `undefined` when there is - * nothing to tell it: + * [#34325] What the action tools hand the bridge for the tool call `extra` + * belongs to: * - * - the client can be elicited: its elicitor (step 1); + * - the client can be elicited: `door`, its elicitor (step 1); * - this server read the client's `initialize` and can carry a request to it, - * but the client advertised no form-mode `elicitation`: - * `elicitsCapableClients`, so a `no_confirmation_service` refusal tells the + * but the client advertised no form-mode `elicitation`: `facts` + * (`elicitsCapableClients`), so a `no_confirmation_service` refusal tells the * caller that a client supporting confirmation is asked in place here. That * is the long-lived stdio server today; - * - this server never read the client's `initialize`: `undefined`, the bridge - * called as before. That is the per-request Streamable HTTP server, which - * asks no client, so the refusal names only the in-app route there. + * - this server never read the client's `initialize`: neither, and the bridge + * is called as before. That is the per-request Streamable HTTP server, + * which asks no client, so the refusal names only the in-app route there. * * Judged on what the server can do, never on a transport name: a door that * comes to read `initialize` gets the step-3 sentence with the elicitation @@ -250,9 +252,9 @@ export function actionConfirmationElicitorFor( export function actionCallDoorFor( server: McpServer, extra: RequestHandlerExtra | undefined, -): McpActionCallDoor | undefined { +): { door?: McpActionCallDoor; facts?: McpActionCallDoorFacts } { const elicitConfirmation = actionConfirmationElicitorFor(server, extra); - if (elicitConfirmation) return { elicitConfirmation }; + if (elicitConfirmation) return { door: { elicitConfirmation } }; const readInitialize = server.server.getClientCapabilities() !== undefined; - return readInitialize && typeof extra?.sendRequest === 'function' ? { elicitsCapableClients: true } : undefined; + return readInitialize && typeof extra?.sendRequest === 'function' ? { facts: { elicitsCapableClients: true } } : {}; } diff --git a/packages/mcp/src/index.ts b/packages/mcp/src/index.ts index 6d13f958024..2f6996290d6 100644 --- a/packages/mcp/src/index.ts +++ b/packages/mcp/src/index.ts @@ -79,6 +79,7 @@ export { } from './action-confirmation-elicitation.js'; export type { McpActionCallDoor, + McpActionCallDoorFacts, McpActionConfirmationAnswer, McpActionConfirmationElicitor, McpActionConfirmationSubject, diff --git a/packages/mcp/src/mcp-action-confirmation-handoff-33690.test.ts b/packages/mcp/src/mcp-action-confirmation-handoff-33690.test.ts index 4885c07f171..429c16e6213 100644 --- a/packages/mcp/src/mcp-action-confirmation-handoff-33690.test.ts +++ b/packages/mcp/src/mcp-action-confirmation-handoff-33690.test.ts @@ -43,6 +43,7 @@ import { actionConfirmationElicitorFor, actionConfirmationQuestion, type McpActionCallDoor, + type McpActionCallDoorFacts, } from './action-confirmation-elicitation.js'; const GATED = 'archive_account'; @@ -272,9 +273,9 @@ async function openStdioClient(server: McpServer, opts: { elicitation: boolean; /** A bridge double for the stdio door: runs the step-1 half the runtime owns, through whatever `door` the tool handed it. */ function elicitingBridge() { - const calls: Array<{ tool: string; door: McpActionCallDoor | undefined; argCount: number }> = []; + const calls: Array<{ tool: string; door: McpActionCallDoor | undefined; facts?: McpActionCallDoorFacts; argCount: number }> = []; const confirmWith = async (door: McpActionCallDoor | undefined, name: string) => { - if (!door?.elicitConfirmation) return pendingOf(1); + if (!door) return pendingOf(1); const answer = await door.elicitConfirmation({ actionName: name, actionLabel: 'Archive Account', objectName: 'account', recordId: 'a1', recordTitle: 'Acme', }); @@ -288,12 +289,12 @@ function elicitingBridge() { const bridge = { ...makeBridge('service'), calls, - async runAction(name: string, _input: any, door?: McpActionCallDoor) { - calls.push({ tool: 'run_action', door, argCount: arguments.length }); + async runAction(name: string, _input: any, door?: McpActionCallDoor, facts?: McpActionCallDoorFacts) { + calls.push({ tool: 'run_action', door, ...(facts !== undefined ? { facts } : {}), argCount: arguments.length }); return confirmWith(door, name); }, - async resumeRun(_runId: string, _input: any, door?: McpActionCallDoor) { - calls.push({ tool: 'resume_run', door, argCount: arguments.length }); + async resumeRun(_runId: string, _input: any, door?: McpActionCallDoor, facts?: McpActionCallDoorFacts) { + calls.push({ tool: 'resume_run', door, ...(facts !== undefined ? { facts } : {}), argCount: arguments.length }); return confirmWith(door, GATED); }, }; @@ -356,13 +357,13 @@ describe('[#33712] stdio: a client that advertises elicitation is asked in place expect(JSON.parse(declined.result.content[0].text).error.details.reason).toBe('declined'); }); - it('a client WITHOUT the capability is never asked: the bridge gets no elicitor and hands off', async () => { + it('a client WITHOUT the capability is never asked: the bridge gets no door and hands off', async () => { const { result, calls } = await stdioCall({ elicitation: false }); expect(result.isError).toBeFalsy(); expect(JSON.parse(result.content[0].text)).toEqual(pendingOf(1)); - // [#34325] The door's one fact for this call: it would have asked a - // client that supports confirmation. No elicitor rides beside it. - expect(calls).toEqual([{ tool: 'run_action', door: { elicitsCapableClients: true }, argCount: 3 }]); + // [#34325] No door, as before; the door's facts ride as a fourth, + // additive argument a bridge may ignore. + expect(calls).toEqual([{ tool: 'run_action', door: undefined, facts: { elicitsCapableClients: true }, argCount: 4 }]); }); }); @@ -536,24 +537,28 @@ describe('[#35778] run_action names the next step on a no_confirmation_service r * `packages/runtime/src/action-confirmation-handoff-33690.test.ts`). The * long-lived stdio server read the client's `initialize`, so for a client * without `elicitation` it says it would have asked a client that supports - * confirmation (`elicitsCapableClients`), on both tools. The per-request + * confirmation (`facts.elicitsCapableClients`, the fourth argument; the door + * argument stays as on main), on both tools. The per-request * Streamable HTTP server asks no client and says nothing: the bridge is * called exactly as before, even for a client that advertised the capability * at `initialize`, so the refusal keeps the in-app route alone there. */ -describe('[#34325] the door the action tools hand the bridge names whether a client that supports confirmation is asked here', () => { +describe('[#34325] the door facts the action tools hand the bridge name whether a client that supports confirmation is asked here', () => { for (const tool of ['run_action', 'resume_run'] as const) { - it(`stdio, a client without elicitation: ${tool} hands the bridge elicitsCapableClients and no elicitor`, async () => { + it(`stdio, a client without elicitation: ${tool} hands the bridge no door and the facts { elicitsCapableClients: true }`, async () => { const { calls, asked } = await stdioCall({ elicitation: false }, tool); expect(asked).toEqual([]); expect(calls).toHaveLength(1); - expect(calls[0].argCount).toBe(3); - expect(calls[0].door).toStrictEqual({ elicitsCapableClients: true }); + expect(calls[0].argCount).toBe(4); + expect(calls[0].door).toBeUndefined(); + expect(calls[0].facts).toStrictEqual({ elicitsCapableClients: true }); }); - it(`CONTROL stdio, a client with elicitation: ${tool} hands the bridge the elicitor and not the flag`, async () => { + it(`CONTROL stdio, a client with elicitation: ${tool} hands the bridge main's door (the elicitor alone) and no facts`, async () => { const { calls } = await stdioCall({ elicitation: true, answer: { action: 'accept' } }, tool); expect(Object.keys(calls[0].door ?? {})).toEqual(['elicitConfirmation']); + expect(calls[0].argCount).toBe(3); + expect(calls[0]).not.toHaveProperty('facts'); }); it(`Streamable HTTP, after an initialize that advertised elicitation: ${tool} calls the bridge with no door at all`, async () => { @@ -569,7 +574,7 @@ describe('[#34325] the door the action tools hand the bridge names whether a cli const req = mcpRequest(body); req.headers.set('mcp-protocol-version', '2025-11-25'); await runtime.handleHttpRequest(req, { bridge, parsedBody: body }); - expect(bridge.calls).toEqual([{ tool, door: undefined, argCount: 2 }]); + expect(bridge.calls).toStrictEqual([{ tool, door: undefined, argCount: 2 }]); }); } }); diff --git a/packages/mcp/src/mcp-http-tools.ts b/packages/mcp/src/mcp-http-tools.ts index 3e66f4fe7c6..890a9265114 100644 --- a/packages/mcp/src/mcp-http-tools.ts +++ b/packages/mcp/src/mcp-http-tools.ts @@ -137,7 +137,7 @@ import { } from './metadata-completeness.js'; // [#30892] The file seam and what `read_file` renders from it. import { READ_FILE_MAX_BYTES, ReadFileExtractionBusyError, renderReadFile, type McpFileBridge } from './file-content.js'; -import { actionCallDoorFor, type McpActionCallDoor } from './action-confirmation-elicitation.js'; +import { actionCallDoorFor, type McpActionCallDoor, type McpActionCallDoorFacts } from './action-confirmation-elicitation.js'; import type { McpLatestPer } from './types.js'; // [#35145] `expand` and `related`: the relation reads, judged before any read. import { @@ -683,10 +683,11 @@ export interface McpActionBridge { * `elicitation` on a door that can carry a request to it), the host asks * the person through `door.elicitConfirmation` first, once every admission * gate has passed: `accept` runs the call, any other answer refuses it, and - * nothing is handed off. Without an elicitor the call is handed off as - * above. [#34325] `door.elicitsCapableClients` (no elicitor beside it) says + * nothing is handed off. Without `door` the call is handed off as above. + * [#34325] `facts.elicitsCapableClients`, passed only without `door`, says * this door would have asked a client that advertised `elicitation`: the - * `no_confirmation_service` refusal then names that route too. + * `no_confirmation_service` refusal then names that route too. A bridge + * that does not read `facts` answers exactly as before. */ runAction( name: string, @@ -702,6 +703,7 @@ export interface McpActionBridge { params?: Record; } & AIActionConfirmation, door?: McpActionCallDoor, + facts?: McpActionCallDoorFacts, ): Promise; /** * [#30771] The capability refusal `runAction` would throw for an action on @@ -730,7 +732,8 @@ export interface McpActionBridge { * gated action resolves to `ActionConfirmationPending` instead, as * {@link runAction} does, and the run stays parked. [#33712] `door` as on * {@link runAction}: an elicited `accept` resumes the run, any other - * answer refuses it and the run stays parked. + * answer refuses it and the run stays parked. [#34325] `facts` as on + * {@link runAction}. * * OPTIONAL, like {@link McpDataBridge.aggregate}. A host that cannot resume * runs omits it, and `resume_run` is then not registered. @@ -739,6 +742,7 @@ export interface McpActionBridge { runId: string, input: { values?: Record } & AIActionConfirmation, door?: McpActionCallDoor, + facts?: McpActionCallDoorFacts, ): Promise; } @@ -5102,13 +5106,15 @@ export function registerActionTools( // advertised `elicitation` on a server that read its `initialize` (the // stdio door) is asked in place. Otherwise the bridge hands a gated // call off. [#34325] On that door a client without the capability is - // named to the bridge (`elicitsCapableClients`), so a no-service + // named to the bridge (`facts.elicitsCapableClients`), so a no-service // refusal names the client route; the per-request HTTP server calls // the bridge exactly as before. - const door = actionCallDoorFor(server, extra); + const { door, facts } = actionCallDoorFor(server, extra); const result = door ? await bridge.runAction(actionName, request, door) - : await bridge.runAction(actionName, request); + : facts + ? await bridge.runAction(actionName, request, undefined, facts) + : await bridge.runAction(actionName, request); return textResult(result); } catch (err) { return landedWriteResultOrError( @@ -5195,10 +5201,12 @@ export function registerActionTools( const request = { values }; // [#33712] As `run_action`: asked in place where the client can be. // [#34325] And the same door facts for a no-service refusal. - const door = actionCallDoorFor(server, extra); + const { door, facts } = actionCallDoorFor(server, extra); const result = door ? await resumeRun(runId, request, door) - : await resumeRun(runId, request); + : facts + ? await resumeRun(runId, request, undefined, facts) + : await resumeRun(runId, request); return textResult(result); } catch (err) { return errorResultFromThrown(err, `resume_run ${runId}`); diff --git a/packages/runtime/src/action-confirmation-handoff-33690.test.ts b/packages/runtime/src/action-confirmation-handoff-33690.test.ts index 4904b079acd..37c79316ce4 100644 --- a/packages/runtime/src/action-confirmation-handoff-33690.test.ts +++ b/packages/runtime/src/action-confirmation-handoff-33690.test.ts @@ -867,10 +867,11 @@ describe('[#34515] a resume approval is bound to the screen it was given on', () * the door that asked. Every door: a person performs it in the app, and the * caller makes no such change through another tool (an agent that read only * "in the app" completed the change with a raw record update). The stdio door - * for a client without `elicitation` (`door.elicitsCapableClients`, set by - * `@objectstack/mcp`'s `actionCallDoorFor`) also names a client that supports - * confirmation (step 3); the Streamable HTTP door, which asks no client and - * passes no door, does not, since that sentence would be false there. The + * for a client without `elicitation` (no door, and the fourth argument + * `facts.elicitsCapableClients`, set by `@objectstack/mcp`'s + * `actionCallDoorFor`) also names a client that supports confirmation + * (step 3); the Streamable HTTP door, which asks no client and passes + * neither, does not, since that sentence would be false there. The * envelope is unchanged: same code, status and details on both doors. */ describe('[#34325] the no_confirmation_service refusal names the route that works on the door that asked', () => { @@ -883,14 +884,14 @@ describe('[#34325] the no_confirmation_service refusal names the route that work return started.runId; } - /** Each tool's no-service refusal through the real bridge, with the door the tool would pass (or none). */ - async function refusedAt(tool: 'run_action' | 'resume_run', door: Record | undefined) { + /** Each tool's no-service refusal through the real bridge, with the facts the tool would pass after an undefined door (or neither). */ + async function refusedAt(tool: 'run_action' | 'resume_run', facts: Record | undefined) { const h = makeHarness(); const bridge = h.bridgeAs(PERSON); const args: unknown[] = tool === 'run_action' ? [GATED.name, { recordId: 'lead_1' }] : [await pausedRun(h), { values: { reason: 'x' } }]; - if (door) args.push(door); + if (facts) args.push(undefined, facts); const refused = await refusalOf(tool === 'run_action' ? bridge.runAction(...args) : bridge.resumeRun(...args)); expect({ code: refused.code, status: refused.status }, tool).toEqual({ code: 'ACTION_CONFIRMATION_REQUIRED', status: 428 }); expect(refused.details?.reason, tool).toBe('no_confirmation_service'); @@ -922,7 +923,7 @@ describe('[#34325] the no_confirmation_service refusal names the route that work it('CONTROL: the door fact is never handed to the host\'s service (the hand-off is the contract\'s shape)', async () => { const service = makeConfirmationService(); const h = makeHarness({ service }); - await h.bridgeAs(PERSON).runAction(GATED.name, { recordId: 'lead_1' }, STDIO_NO_ELICITATION); + await h.bridgeAs(PERSON).runAction(GATED.name, { recordId: 'lead_1' }, undefined, STDIO_NO_ELICITATION); expect((service.submit.mock.calls[0] as any[])[0]).toEqual({ actionName: GATED.name, objectName: OBJECT, recordId: 'lead_1', params: {}, door: 'mcp', }); diff --git a/packages/runtime/src/action-execution.ts b/packages/runtime/src/action-execution.ts index a436ab72b90..2aa7db94e87 100644 --- a/packages/runtime/src/action-execution.ts +++ b/packages/runtime/src/action-execution.ts @@ -3363,8 +3363,8 @@ export async function resolveActionConfirmationService( /** * [#34325] What the door that asked knows about its caller's client, passed * beside the hand-off and never on it (the host's service is not told). - * Structurally the `elicitsCapableClients` half of `McpActionCallDoor` - * (`@objectstack/mcp`), which this package does not depend on. + * Structurally `McpActionCallDoorFacts` (`@objectstack/mcp`), which this + * package does not depend on. */ export interface ActionConfirmationDoor { /** diff --git a/packages/runtime/src/domains/mcp.ts b/packages/runtime/src/domains/mcp.ts index b5e45b812d3..0a6ac6f447a 100644 --- a/packages/runtime/src/domains/mcp.ts +++ b/packages/runtime/src/domains/mcp.ts @@ -966,21 +966,23 @@ function actionDeclarationReads(deps: DomainHandlerDeps, context: HttpProtocolCo } /** - * [#33712, #34325] What the MCP action tools hand the bridge beside a call - * (`McpActionCallDoor`, `@objectstack/mcp`, which this package does not - * depend on): the person's client as an elicitor, or the fact that the door - * would have asked a client that supports confirmation. + * [#33712] The door the MCP action tools hand the bridge when the client can be + * elicited (`McpActionCallDoor`, `@objectstack/mcp`, which this package does + * not depend on). [#34325] And, without one, the door's facts + * (`McpActionCallDoorFacts`), the fourth argument: the door would have asked a + * client that supports confirmation. */ -type McpActionCallDoorFacts = { - elicitConfirmation?: actionExec.ActionConfirmationElicitor; - elicitsCapableClients?: boolean; -}; - -/** The door's facts as `invokeBusinessAction` / `resumeActionRun` wiring: each only when the door set it. */ -function actionCallDoorWiring(door: McpActionCallDoorFacts | undefined): McpActionCallDoorFacts { +type McpActionCallDoor = { elicitConfirmation?: actionExec.ActionConfirmationElicitor }; +type McpActionCallDoorFacts = { elicitsCapableClients?: boolean }; + +/** The door and its facts as `invokeBusinessAction` / `resumeActionRun` wiring: each only when the tool set it. */ +function actionCallDoorWiring( + door: McpActionCallDoor | undefined, + facts: McpActionCallDoorFacts | undefined, +): { elicitConfirmation?: actionExec.ActionConfirmationElicitor; elicitsCapableClients?: boolean } { return { ...(typeof door?.elicitConfirmation === 'function' ? { elicitConfirmation: door.elicitConfirmation } : {}), - ...(door?.elicitsCapableClients === true ? { elicitsCapableClients: true } : {}), + ...(facts?.elicitsCapableClients === true ? { elicitsCapableClients: true } : {}), }; } @@ -1592,12 +1594,14 @@ export function buildMcpBridge( input: { objectName?: string; namespace?: string; recordId?: string; params?: Record } & AIActionConfirmation, // [#33712] The door's channel to the person's client, set by the // tool only when the client can be elicited (`McpActionCallDoor`). - // [#34325] Or, without one, `elicitsCapableClients`: the door - // would have asked a client that supports confirmation. - door?: McpActionCallDoorFacts, + door?: McpActionCallDoor, + // [#34325] Set by the tool only without `door`: the door would + // have asked a client that supports confirmation + // (`McpActionCallDoorFacts`). + facts?: McpActionCallDoorFacts, ) => actionExec.invokeBusinessAction(deps, context, name, input ?? {}, { driver, envId, ec, getMeta, readObjects: readServedObjects, readActions: readServedActions, callData, - ...actionCallDoorWiring(door), + ...actionCallDoorWiring(door, facts), }), // [#15705] `resume_run`: continue the caller's own paused screen run. // Admitted by the same gates as `run_action`; see @@ -1605,10 +1609,11 @@ export function buildMcpBridge( resumeRun: async ( runId: string, input: { values?: Record } & AIActionConfirmation, - door?: McpActionCallDoorFacts, + door?: McpActionCallDoor, + facts?: McpActionCallDoorFacts, ) => resumeActionRun(deps, context, runId, input ?? {}, { driver, envId, ec, getMeta, readObjects: readServedObjects, readActions: readServedActions, callData, - ...actionCallDoorWiring(door), + ...actionCallDoorWiring(door, facts), }), // ── Federation surface (McpFederationBridge, #27745) ─────── // The `external-datasource` service Studio's datasource page reaches