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..5f933cab7d5 --- /dev/null +++ b/.changeset/34325-door-aware-no-service-refusal.md @@ -0,0 +1,9 @@ +--- +'@objectstack/runtime': patch +'@objectstack/mcp': patch +--- + +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. 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 729eed6cb05..9056d56b91b 100644 --- a/packages/mcp/src/action-confirmation-elicitation.ts +++ b/packages/mcp/src/action-confirmation-elicitation.ts @@ -95,6 +95,24 @@ export interface McpActionCallDoor { 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 { + /** + * 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; +} + /** * The result shape this door reads: `action` and nothing else. Loose on * purpose, unlike the SDK's own `ElicitResultSchema`, which also parses @@ -212,3 +230,31 @@ export function actionConfirmationElicitorFor( } }; } + +/** + * [#34325] What the action tools hand the bridge for the tool call `extra` + * belongs to: + * + * - 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`: `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`: 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 + * that makes it true. + */ +export function actionCallDoorFor( + server: McpServer, + extra: RequestHandlerExtra | undefined, +): { door?: McpActionCallDoor; facts?: McpActionCallDoorFacts } { + const elicitConfirmation = actionConfirmationElicitorFor(server, extra); + if (elicitConfirmation) return { door: { elicitConfirmation } }; + const readInitialize = server.server.getClientCapabilities() !== 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 ab724ce1b2a..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,7 +273,7 @@ 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) return pendingOf(1); const answer = await door.elicitConfirmation({ @@ -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,11 +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 is called exactly as before 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)); - expect(calls).toEqual([{ tool: 'run_action', door: undefined, argCount: 2 }]); + // [#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 }]); }); }); @@ -527,3 +530,51 @@ 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 (`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 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 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(4); + expect(calls[0].door).toBeUndefined(); + expect(calls[0].facts).toStrictEqual({ elicitsCapableClients: true }); + }); + + 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 () => { + 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).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 4a867dae7a8..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 { actionConfirmationElicitorFor, 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 { @@ -684,6 +684,10 @@ export interface McpActionBridge { * 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. + * [#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. A bridge + * that does not read `facts` answers exactly as before. */ runAction( name: string, @@ -699,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 @@ -727,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. @@ -736,6 +742,7 @@ export interface McpActionBridge { runId: string, input: { values?: Record } & AIActionConfirmation, door?: McpActionCallDoor, + facts?: McpActionCallDoorFacts, ): Promise; } @@ -5097,12 +5104,17 @@ 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 }) - : await bridge.runAction(actionName, request); + // 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 (`facts.elicitsCapableClients`), so a no-service + // refusal names the client route; the per-request HTTP server calls + // the bridge exactly as before. + const { door, facts } = actionCallDoorFor(server, extra); + const result = door + ? await bridge.runAction(actionName, request, door) + : facts + ? await bridge.runAction(actionName, request, undefined, facts) + : await bridge.runAction(actionName, request); return textResult(result); } catch (err) { return landedWriteResultOrError( @@ -5188,10 +5200,13 @@ 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 }) - : await resumeRun(runId, request); + // [#34325] And the same door facts for a no-service refusal. + const { door, facts } = actionCallDoorFor(server, extra); + const result = door + ? await resumeRun(runId, request, door) + : 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 53377f9266d..37c79316ce4 100644 --- a/packages/runtime/src/action-confirmation-handoff-33690.test.ts +++ b/packages/runtime/src/action-confirmation-handoff-33690.test.ts @@ -861,3 +861,71 @@ 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` (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', () => { + 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 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 (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'); + 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' }, 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-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..2aa7db94e87 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 `McpActionCallDoorFacts` (`@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..0a6ac6f447a 100644 --- a/packages/runtime/src/domains/mcp.ts +++ b/packages/runtime/src/domains/mcp.ts @@ -965,6 +965,27 @@ function actionDeclarationReads(deps: DomainHandlerDeps, context: HttpProtocolCo return { getMeta, getProtocol, readMergedObjects, readServedObjects, readServedActions }; } +/** + * [#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 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 } : {}), + ...(facts?.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 +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`). - door?: { elicitConfirmation?: actionExec.ActionConfirmationElicitor }, + 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, - ...(typeof door?.elicitConfirmation === 'function' ? { elicitConfirmation: door.elicitConfirmation } : {}), + ...actionCallDoorWiring(door, facts), }), // [#15705] `resume_run`: continue the caller's own paused screen run. // Admitted by the same gates as `run_action`; see @@ -1584,10 +1609,11 @@ export function buildMcpBridge( resumeRun: async ( runId: string, input: { values?: Record } & AIActionConfirmation, - door?: { elicitConfirmation?: actionExec.ActionConfirmationElicitor }, + door?: McpActionCallDoor, + facts?: McpActionCallDoorFacts, ) => resumeActionRun(deps, context, runId, input ?? {}, { driver, envId, ec, getMeta, readObjects: readServedObjects, readActions: readServedActions, callData, - ...(typeof door?.elicitConfirmation === 'function' ? { elicitConfirmation: door.elicitConfirmation } : {}), + ...actionCallDoorWiring(door, facts), }), // ── Federation surface (McpFederationBridge, #27745) ─────── // The `external-datasource` service Studio's datasource page reaches @@ -2413,6 +2439,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 +2607,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,