Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/34325-door-aware-no-service-refusal.md
Original file line number Diff line number Diff line change
@@ -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.
46 changes: 46 additions & 0 deletions packages/mcp/src/action-confirmation-elicitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ServerRequest, ServerNotification> | 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 } } : {};
}
1 change: 1 addition & 0 deletions packages/mcp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export {
} from './action-confirmation-elicitation.js';
export type {
McpActionCallDoor,
McpActionCallDoorFacts,
McpActionConfirmationAnswer,
McpActionConfirmationElicitor,
McpActionConfirmationSubject,
Expand Down
65 changes: 58 additions & 7 deletions packages/mcp/src/mcp-action-confirmation-handoff-33690.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
actionConfirmationElicitorFor,
actionConfirmationQuestion,
type McpActionCallDoor,
type McpActionCallDoorFacts,
} from './action-confirmation-elicitation.js';

const GATED = 'archive_account';
Expand Down Expand Up @@ -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({
Expand All @@ -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);
},
};
Expand Down Expand Up @@ -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 }]);
});
});

Expand Down Expand Up @@ -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 }]);
});
}
});
39 changes: 27 additions & 12 deletions packages/mcp/src/mcp-http-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -699,6 +703,7 @@ export interface McpActionBridge {
params?: Record<string, unknown>;
} & AIActionConfirmation,
door?: McpActionCallDoor,
facts?: McpActionCallDoorFacts,
): Promise<unknown>;
/**
* [#30771] The capability refusal `runAction` would throw for an action on
Expand Down Expand Up @@ -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.
Expand All @@ -736,6 +742,7 @@ export interface McpActionBridge {
runId: string,
input: { values?: Record<string, unknown> } & AIActionConfirmation,
door?: McpActionCallDoor,
facts?: McpActionCallDoorFacts,
): Promise<unknown>;
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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}`);
Expand Down
68 changes: 68 additions & 0 deletions packages/runtime/src/action-confirmation-handoff-33690.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof makeHarness>): Promise<string> {
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<string, unknown> | 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',
});
});
});
8 changes: 7 additions & 1 deletion packages/runtime/src/action-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Loading
Loading