@devries-cameron20 / t3code-1 / commits / ff55c19baa
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): show Claude MCP elicitations on the approval card (#21903)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Christopher Gómez committed Oct 30, 2026 at 16:29 UTC ff55c19baa7d9e3746cd6f2ea123233b5f04a11e
3 files changed +475 -5
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+267
@@ -8,6 +8,7 @@ import * as ClaudeSdk from "@anthropic-ai/claude-agent-sdk";
8 import { beforeEach, vi } from "vite-plus/test";
9
10 import type {
11 + ElicitationRequest,
12 Query as ClaudeQuery,
13 SDKMessage,
14 SDKResultMessage,
@@ -1187,6 +1188,82 @@ describe("ClaudeAdapterV2 approval cancellation", () => {
1188 );
1189 });
1190
1191 +describe("ClaudeAdapterV2 MCP elicitation acceptance", () => {
1192 + const form = (
1193 + properties: Record<string, unknown>,
1194 + required?: ReadonlyArray<string>,
1195 + ): ElicitationRequest => ({
1196 + serverName: "deploys",
1197 + message: "Deploy web?",
1198 + mode: "form",
1199 + requestedSchema: { type: "object", properties, ...(required ? { required } : {}) },
1200 + });
1201 +
1202 + it("answers an empty-properties form with empty content", () => {
1203 + assert.deepEqual(ClaudeAdapterV2.claudeMcpElicitationAcceptance(form({})), {
1204 + action: "accept",
1205 + content: {},
1206 + });
1207 + });
1208 +
1209 + it("picks the one-time choice however the server spells it", () => {
1210 + for (const choice of [
1211 + "allow_once",
1212 + "Allow",
1213 + "accept_once",
1214 + "Approve once",
1215 + "allow_this_time",
1216 + "allow_once_only",
1217 + ]) {
1218 + assert.deepEqual(
1219 + ClaudeAdapterV2.claudeMcpElicitationAcceptance(
1220 + form({ decision: { type: "string", enum: ["disallow", choice, "always"] } }, [
1221 + "decision",
1222 + ]),
1223 + ),
1224 + { action: "accept", content: { decision: choice } },
1225 + );
1226 + }
1227 + });
1228 +
1229 + it("answers a persistence toggle with false", () => {
1230 + assert.deepEqual(
1231 + ClaudeAdapterV2.claudeMcpElicitationAcceptance(
1232 + form({ remember: { type: "boolean", title: "Always allow" } }, ["remember"]),
1233 + ),
1234 + { action: "accept", content: { remember: false } },
1235 + );
1236 + });
1237 +
1238 + it("leaves out optional fields the card does not show", () => {
1239 + assert.deepEqual(
1240 + ClaudeAdapterV2.claudeMcpElicitationAcceptance(
1241 + form({ scope: { type: "string", enum: ["once", "always"], default: "always" } }),
1242 + ),
1243 + { action: "accept", content: { scope: "once" } },
1244 + );
1245 + assert.deepEqual(
1246 + ClaudeAdapterV2.claudeMcpElicitationAcceptance(
1247 + form({ limit: { type: "number", default: 500 } }),
1248 + ),
1249 + { action: "accept", content: {} },
1250 + );
1251 + });
1252 +
1253 + it("has no answer for URL mode or a form asking for a value", () => {
1254 + for (const request of [
1255 + { serverName: "deploys", message: "Sign in", mode: "url", url: "https://example.com" },
1256 + form({ reason: { type: "string" } }, ["reason"]),
1257 + form({ grant: { type: "string", enum: ["always", "session"] } }, ["grant"]),
1258 + form({ grant: { type: "string", enum: ["deny", "always"], default: "always" } }, ["grant"]),
1259 + form({ limit: { type: "number", default: 500 } }, ["limit"]),
1260 + { serverName: "deploys", message: "Deploy web?", mode: "form" },
1261 + ] satisfies ReadonlyArray<ElicitationRequest>) {
1262 + assert.isUndefined(ClaudeAdapterV2.claudeMcpElicitationAcceptance(request));
1263 + }
1264 + });
1265 +});
1266 +
1267 const captureSdkExecutablePaths = Effect.fn("captureSdkExecutablePaths")(function* (
1268 binaryPath: string,
1269 environment: ResolvedProviderInstanceEnvironment = [],
@@ -4403,6 +4480,196 @@ describe("ClaudeAdapterV2 background wake turns", () => {
4480 ),
4481 );
4482
4483 + describe("MCP elicitations", () => {
4484 + const testLayer = Layer.mergeAll(
4485 + IdAllocator.layer,
4486 + McpProviderSessions.layer,
4487 + NodeServices.layer,
4488 + );
4489 + const approvalOnly: ElicitationRequest = {
4490 + serverName: "deploys",
4491 + message: "Deploy web to production?",
4492 + mode: "form",
4493 + requestedSchema: { type: "object", properties: {} },
4494 + title: "Deploy",
4495 + };
4496 +
4497 + const startElicitationTurn = Effect.fnUntraced(function* (
4498 + options?: Parameters<typeof makeWakeHarnessWithOptions>[0],
4499 + ) {
4500 + const harness = yield* makeWakeHarnessWithOptions(options);
4501 + yield* harness.runtime.startTurn(
4502 + makeClaudeTestTurnInput({
4503 + threadId: harness.threadId,
4504 + providerThread: harness.providerThread,
4505 + now: yield* DateTime.now,
4506 + attemptId: RunAttemptId.make("attempt-claude-elicitation"),
4507 + text: "Deploy web.",
4508 + attachments: [],
4509 + }),
4510 + );
4511 + const onElicitation = harness.getOpenedOptions()?.onElicitation;
4512 + if (onElicitation === undefined) throw new Error("The Claude query has no onElicitation.");
4513 + const runtimeRequests = () =>
4514 + harness.events.flatMap((event) =>
4515 + event.type === "runtime_request.updated" ? [event.runtimeRequest] : [],
4516 + );
4517 + let requestNumber = 0;
4518 + const elicit = (request: ElicitationRequest, signal = new AbortController().signal) =>
4519 + Effect.promise(() =>
4520 + onElicitation(request, { signal, requestId: `sdk-${requestNumber++}` }),
4521 + ).pipe(Effect.forkScoped);
4522 + const awaitCard = Effect.fnUntraced(function* (count: number) {
4523 + const event = yield* Queue.take(harness.runtimeRequestReceipts);
4524 + assert.equal(runtimeRequests().length, count);
4525 + return event.runtimeRequest;
4526 + });
4527 + return { harness, elicit, awaitCard, runtimeRequests };
4528 + });
4529 +
4530 + it.effect("shows an approval-only form and accepts only after Approve", () =>
4531 + Effect.gen(function* () {
4532 + const { harness, elicit, awaitCard } = yield* startElicitationTurn();
4533 + const answer = yield* elicit(approvalOnly);
4534 + const request = yield* awaitCard(1);
4535 + assert.equal(request.kind, "mcp-elicitation");
4536 + assert.isTrue(request.responseCapability.type === "live");
4537 + if (request.responseCapability.type === "live") {
4538 + assert.isUndefined(request.responseCapability.supportsFeedback);
4539 + }
4540 + const card = harness.events.findLast(
4541 + (event) =>
4542 + event.type === "turn_item.updated" && event.turnItem.type === "approval_request",
4543 + );
4544 + assert.deepInclude(card?.type === "turn_item.updated" ? card.turnItem : undefined, {
4545 + prompt: "Deploy web to production?",
4546 + appName: "Deploy",
4547 + options: [
4548 + { decision: "cancel", label: "Cancel" },
4549 + { decision: "decline", label: "Decline" },
4550 + { decision: "accept", label: "Approve" },
4551 + ],
4552 + });
4553 + assert.isUndefined(answer.pollUnsafe());
4554 +
4555 + yield* harness.runtime.respondToRuntimeRequest({
4556 + requestId: request.id,
4557 + decision: "accept",
4558 + });
4559 + assert.deepEqual(yield* Fiber.join(answer), { action: "accept", content: {} });
4560 +
4561 + // The card is gone, so a second click is an unknown request.
4562 + const late = yield* Effect.flip(
4563 + harness.runtime.respondToRuntimeRequest({ requestId: request.id, decision: "decline" }),
4564 + );
4565 + assert.include(String(late.cause), "No pending Claude runtime request");
4566 + }).pipe(Effect.scoped, Effect.provide(testLayer)),
4567 + );
4568 +
4569 + it.effect.each(["decline", "cancel"] as const)("answers %s with that action", (decision) =>
4570 + Effect.gen(function* () {
4571 + const { harness, elicit, awaitCard } = yield* startElicitationTurn();
4572 + const answer = yield* elicit(approvalOnly);
4573 + const request = yield* awaitCard(1);
4574 + yield* harness.runtime.respondToRuntimeRequest({ requestId: request.id, decision });
4575 + assert.deepEqual(yield* Fiber.join(answer), { action: decision });
4576 + }).pipe(Effect.scoped, Effect.provide(testLayer)),
4577 + );
4578 +
4579 + it.effect.each(["acceptForSession", "acceptAlways"] as const)(
4580 + "declines an unsupported %s decision",
4581 + (decision) =>
4582 + Effect.gen(function* () {
4583 + const { harness, elicit, awaitCard } = yield* startElicitationTurn();
4584 + const answer = yield* elicit(approvalOnly);
4585 + const request = yield* awaitCard(1);
4586 + yield* harness.runtime.respondToRuntimeRequest({ requestId: request.id, decision });
4587 + assert.deepEqual(yield* Fiber.join(answer), { action: "decline" });
4588 + }).pipe(Effect.scoped, Effect.provide(testLayer)),
4589 + );
4590 +
4591 + it.effect("declines URL and value forms without a card", () =>
4592 + Effect.gen(function* () {
4593 + const { elicit, runtimeRequests } = yield* startElicitationTurn();
4594 + for (const request of [
4595 + { ...approvalOnly, mode: "url", url: "https://example.com/auth" },
4596 + {
4597 + ...approvalOnly,
4598 + requestedSchema: {
4599 + type: "object",
4600 + properties: { reason: { type: "string" } },
4601 + required: ["reason"],
4602 + },
4603 + },
4604 + ] satisfies ReadonlyArray<ElicitationRequest>) {
4605 + assert.deepEqual(yield* Fiber.join(yield* elicit(request)), { action: "decline" });
4606 + }
4607 + assert.isEmpty(runtimeRequests());
4608 + }).pipe(Effect.scoped, Effect.provide(testLayer)),
4609 + );
4610 +
4611 + it.effect("cancels an already-aborted request without a card", () =>
4612 + Effect.gen(function* () {
4613 + const { harness, elicit, awaitCard, runtimeRequests } = yield* startElicitationTurn();
4614 + const aborted = yield* Effect.sync(() => {
4615 + const controller = new AbortController();
4616 + controller.abort();
4617 + return controller.signal;
4618 + });
4619 + const answer = yield* elicit(approvalOnly, aborted);
4620 + assert.deepEqual(yield* Fiber.join(answer), { action: "cancel" });
4621 + assert.isEmpty(runtimeRequests());
4622 + const next = yield* elicit(approvalOnly);
4623 + const card = yield* awaitCard(1);
4624 + assert.equal(card.nativeRequestRef?.nativeId, "mcp-elicitation:sdk-1");
4625 + yield* harness.runtime.respondToRuntimeRequest({ requestId: card.id, decision: "accept" });
4626 + assert.deepEqual(yield* Fiber.join(next), { action: "accept", content: {} });
4627 + }).pipe(Effect.scoped, Effect.provide(testLayer)),
4628 + );
4629 +
4630 + it.effect("withdraws an open card when the SDK cancels while the session continues", () =>
4631 + Effect.gen(function* () {
4632 + const { harness, elicit, awaitCard } = yield* startElicitationTurn();
4633 + const controller = yield* Effect.sync(() => new AbortController());
4634 + const answer = yield* elicit(approvalOnly, controller.signal);
4635 + const request = yield* awaitCard(1);
4636 + yield* Effect.sync(() => controller.abort());
4637 + assert.deepEqual(yield* Fiber.join(answer), { action: "cancel" });
4638 + const cancelled = yield* Queue.take(harness.runtimeRequestReceipts);
4639 + assert.equal(cancelled.runtimeRequest.id, request.id);
4640 + assert.equal(cancelled.runtimeRequest.status, "cancelled");
4641 + assert.equal(
4642 + harness.events.findLast((e) => e.type === "node.updated")?.node.status,
4643 + "cancelled",
4644 + );
4645 + assert.equal(
4646 + harness.events.findLast((e) => e.type === "turn_item.updated")?.turnItem.status,
4647 + "cancelled",
4648 + );
4649 + yield* Effect.flip(
4650 + harness.runtime.respondToRuntimeRequest({ requestId: request.id, decision: "accept" }),
4651 + );
4652 + }).pipe(Effect.scoped, Effect.provide(testLayer)),
4653 + );
4654 +
4655 + it.effect("cancels an open card when the session stops", () =>
4656 + Effect.gen(function* () {
4657 + // Like the SDK, the fake query aborts in-flight callbacks when closed.
4658 + const inFlight = yield* Effect.sync(() => new AbortController());
4659 + const session = yield* Scope.make();
4660 + const { elicit, awaitCard } = yield* startElicitationTurn({
4661 + close: () => Effect.sync(() => inFlight.abort()),
4662 + }).pipe(Scope.provide(session));
4663 + const answer = yield* elicit(approvalOnly, inFlight.signal);
4664 + yield* awaitCard(1);
4665 + assert.isUndefined(answer.pollUnsafe());
4666 +
4667 + yield* Scope.close(session, Exit.void);
4668 + assert.deepEqual(yield* Fiber.join(answer), { action: "cancel" });
4669 + }).pipe(Effect.scoped, Effect.provide(testLayer)),
4670 + );
4671 + });
4672 +
4673 it.effect(
4674 "applies model, effort and Fast changes to a process running a background shell, but not thinking or a cleared effort",
4675 () =>
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+196 -1
@@ -22,8 +22,11 @@ import {
22
23 import { isWorkspaceImagePreviewPath } from "@t3tools/shared/filePreview";
24 import { normalizeClaudeTurnTokenUsage } from "../../provider/ClaudeTurnTokenUsage.ts";
25 +import { toMcpElicitationResponse } from "../../provider/CodexMcpElicitation.ts";
26 import {
27 type CanUseTool,
28 + type ElicitationRequest,
29 + type ElicitationResult,
30 forkSession as forkClaudeSession,
31 type EffortLevel,
32 type ForkSessionOptions,
@@ -1470,6 +1473,7 @@ export function makeClaudeQueryOptions(input: {
1473 readonly permissionMode?: PermissionMode;
1474 readonly canUseTool?: CanUseTool;
1475 readonly onUserDialog?: ClaudeQueryOptions["onUserDialog"];
1476 + readonly onElicitation?: ClaudeQueryOptions["onElicitation"];
1477 readonly supportedDialogKinds?: ClaudeQueryOptions["supportedDialogKinds"];
1478 readonly allowDangerouslySkipPermissions?: boolean;
1479 readonly appendSystemPromptFileText?: string;
@@ -1568,6 +1572,7 @@ export function makeClaudeQueryOptions(input: {
1572 ? {}
1573 : { settings: effectiveQuerySettings }),
1574 ...(input.onUserDialog === undefined ? {} : { onUserDialog: input.onUserDialog }),
1575 + ...(input.onElicitation === undefined ? {} : { onElicitation: input.onElicitation }),
1576 ...(input.supportedDialogKinds === undefined
1577 ? {}
1578 : { supportedDialogKinds: input.supportedDialogKinds }),
@@ -3443,6 +3448,69 @@ export const awaitClaudeApprovalDecision = Effect.fn("awaitClaudeApprovalDecisio
3448 return yield* Effect.raceFirst(Deferred.await(decision), cancellation);
3449 });
3450
3451 +// Web and mobile offer a session grant when options are omitted, and this
3452 +// path only ever answers once.
3453 +const CLAUDE_MCP_ELICITATION_OPTIONS: ReadonlyArray<ProviderApprovalOption> = [
3454 + { decision: "cancel", label: "Cancel" },
3455 + { decision: "decline", label: "Decline" },
3456 + { decision: "accept", label: "Approve" },
3457 +];
3458 +
3459 +type ClaudeMcpElicitationContent = NonNullable<ElicitationResult["content"]>;
3460 +
3461 +const isClaudeMcpElicitationValue = (
3462 + value: unknown,
3463 +): value is ClaudeMcpElicitationContent[string] =>
3464 + typeof value === "string" ||
3465 + typeof value === "number" ||
3466 + typeof value === "boolean" ||
3467 + (Array.isArray(value) && value.every((item) => typeof item === "string"));
3468 +
3469 +const withoutSchemaDefaults = (schema: Record<string, unknown>): Record<string, unknown> => {
3470 + const properties = schema.properties;
3471 + if (typeof properties !== "object" || properties === null || Array.isArray(properties)) {
3472 + return schema;
3473 + }
3474 + return {
3475 + ...schema,
3476 + properties: Object.fromEntries(
3477 + Object.entries(properties).map(([key, field]) => [
3478 + key,
3479 + typeof field === "object" && field !== null
3480 + ? Object.fromEntries(Object.entries(field).filter(([name]) => name !== "default"))
3481 + : field,
3482 + ]),
3483 + ),
3484 + };
3485 +};
3486 +
3487 +// The card collects consent only; schema defaults must never grant unseen permissions.
3488 +export function claudeMcpElicitationAcceptance(
3489 + request: ElicitationRequest,
3490 +): ElicitationResult | undefined {
3491 + if (request.mode === "url" || request.requestedSchema === undefined) return undefined;
3492 + const response = toMcpElicitationResponse(
3493 + { mode: "form", requestedSchema: withoutSchemaDefaults(request.requestedSchema) },
3494 + "accept",
3495 + );
3496 + // The helper leaves content out when the schema is not a form it can read.
3497 + const filled = response.content;
3498 + if (
3499 + response.action !== "accept" ||
3500 + typeof filled !== "object" ||
3501 + filled === null ||
3502 + Array.isArray(filled)
3503 + ) {
3504 + return undefined;
3505 + }
3506 + const content: ClaudeMcpElicitationContent = {};
3507 + for (const [key, value] of Object.entries(filled)) {
3508 + if (!isClaudeMcpElicitationValue(value)) return undefined;
3509 + content[key] = value;
3510 + }
3511 + return { action: "accept", content };
3512 +}
3513 +
3514 const awaitClaudeUserInputAnswers = Effect.fn("awaitClaudeUserInputAnswers")(function* (
3515 answers: Deferred.Deferred<ProviderUserInputAnswers>,
3516 signal: AbortSignal,
@@ -7015,7 +7083,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7083 readonly nativeRequestId: string;
7084 readonly requestKind: OrchestrationV2RuntimeRequest["kind"];
7085 readonly prompt?: string;
7086 + readonly appName?: string;
7087 + readonly options?: ReadonlyArray<ProviderApprovalOption>;
7088 readonly presentation?: ReturnType<typeof claudeApprovalPresentation>;
7089 +
7090 readonly questions?: ReadonlyArray<OrchestrationV2UserInputQuestion>;
7091 }) {
7092 const createdAt = yield* DateTime.now;
@@ -7075,7 +7146,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7146 responseCapability: {
7147 type: "live",
7148 providerSessionId,
7078 - ...(input.questions === undefined ? { supportsFeedback: true } : {}),
7149 + ...(input.questions === undefined && input.requestKind !== "mcp-elicitation"
7150 + ? { supportsFeedback: true }
7151 + : {}),
7152 },
7153 createdAt,
7154 resolvedAt: null,
@@ -7101,6 +7174,8 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
7174 requestId,
7175 requestKind: input.requestKind as ProviderRequestKind,
7176 ...(input.prompt === undefined ? {} : { prompt: input.prompt }),
7177 + ...(input.appName === undefined ? {} : { appName: input.appName }),
7178 + ...(input.options === undefined ? {} : { options: input.options }),
7179 ...input.presentation,
7180 }
7181 : {
@@ -9715,6 +9790,125 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
9790 const canUseTool: CanUseTool = (toolName, toolInput, callbackOptions) =>
9791 runPromise(canUseToolEffect(toolName, toolInput, callbackOptions));
9792
9793 + const onElicitationEffect = Effect.fn("ClaudeAdapterV2.onElicitation")(function* (
9794 + request: ElicitationRequest,
9795 + callbackOptions: Parameters<NonNullable<ClaudeQueryOptions["onElicitation"]>>[1],
9796 + ) {
9797 + if (callbackOptions.signal.aborted)
9798 + return { action: "cancel" } satisfies ElicitationResult;
9799 + const acceptance = claudeMcpElicitationAcceptance(request);
9800 + const context = yield* Ref.get(activeTurn);
9801 + if (acceptance === undefined || context === null) {
9802 + yield* Effect.logWarning(
9803 + "Declined an MCP elicitation the approval card cannot answer.",
9804 + {
9805 + serverName: request.serverName,
9806 + mode: request.mode,
9807 + activeTurn: context !== null,
9808 + },
9809 + );
9810 + return { action: "decline" } satisfies ElicitationResult;
9811 + }
9812 + // The CLI waits on this answer, so a turn held for its prompt echo
9813 + // must show its output now, as canUseTool does.
9814 + if (context.heldRootFrames.length > 0) {
9815 + yield* releaseHeldRootFrames(context);
9816 + }
9817 +
9818 + // The SDK's requestId names this control request; T3 allocates its own
9819 + // runtime request id from it.
9820 + const nativeRequestId = `mcp-elicitation:${callbackOptions.requestId}`;
9821 + const artifacts = yield* buildApprovalRequestArtifacts({
9822 + context,
9823 + nativeItemId: nativeRequestId,
9824 + nativeRequestId,
9825 + requestKind: "mcp-elicitation",
9826 + prompt: request.message,
9827 + appName: request.displayName ?? request.title ?? request.serverName,
9828 + options: CLAUDE_MCP_ELICITATION_OPTIONS,
9829 + });
9830 + const decision = yield* Deferred.make<ClaudeApprovalResponse>();
9831 + yield* Ref.update(pendingRuntimeRequests, (current) => {
9832 + const updated = new Map(current);
9833 + updated.set(String(artifacts.request.id), {
9834 + type: "approval",
9835 + requestKind: "mcp-elicitation",
9836 + decision,
9837 + });
9838 + return updated;
9839 + });
9840 + yield* Effect.all(
9841 + [
9842 + emitProviderEvent({
9843 + type: "node.updated",
9844 + driver: CLAUDE_PROVIDER,
9845 + node: artifacts.node,
9846 + }),
9847 + emitProviderEvent({
9848 + type: "runtime_request.updated",
9849 + driver: CLAUDE_PROVIDER,
9850 + runtimeRequest: artifacts.request,
9851 + }),
9852 + emitProviderEvent({
9853 + type: "turn_item.updated",
9854 + driver: CLAUDE_PROVIDER,
9855 + turnItem: artifacts.turnItem,
9856 + }),
9857 + ],
9858 + { concurrency: 1 },
9859 + );
9860 +
9861 + // Closing the query aborts the signal, so a stopped session settles
9862 + // this as cancel and a late response finds no pending request.
9863 + const { decision: resolved } = yield* awaitClaudeApprovalDecision(
9864 + decision,
9865 + callbackOptions.signal,
9866 + ).pipe(
9867 + Effect.ensuring(
9868 + Ref.update(pendingRuntimeRequests, (current) => {
9869 + const updated = new Map(current);
9870 + updated.delete(String(artifacts.request.id));
9871 + return updated;
9872 + }),
9873 + ),
9874 + );
9875 + if (resolved === "cancel" && callbackOptions.signal.aborted) {
9876 + const now = yield* DateTime.now;
9877 + yield* emitProviderEvent({
9878 + type: "node.updated",
9879 + driver: CLAUDE_PROVIDER,
9880 + node: { ...artifacts.node, status: "cancelled", completedAt: now },
9881 + });
9882 + yield* emitProviderEvent({
9883 + type: "turn_item.updated",
9884 + driver: CLAUDE_PROVIDER,
9885 + turnItem: {
9886 + ...artifacts.turnItem,
9887 + status: "cancelled",
9888 + completedAt: now,
9889 + updatedAt: now,
9890 + },
9891 + });
9892 + yield* emitProviderEvent({
9893 + type: "runtime_request.updated",
9894 + driver: CLAUDE_PROVIDER,
9895 + runtimeRequest: { ...artifacts.request, status: "cancelled", resolvedAt: now },
9896 + });
9897 + }
9898 + // Never null: the SDK reads null as answered out of band and leaves
9899 + // the server waiting. Every accept is one-time; no grant is offered.
9900 + return resolved === "accept"
9901 + ? acceptance
9902 + : ({
9903 + action: resolved === "cancel" ? "cancel" : "decline",
9904 + } satisfies ElicitationResult);
9905 + });
9906 +
9907 + const onElicitation: NonNullable<ClaudeQueryOptions["onElicitation"]> = (
9908 + request,
9909 + callbackOptions,
9910 + ) => runPromise(onElicitationEffect(request, callbackOptions));
9911 +
9912 const onUserDialog: NonNullable<ClaudeQueryOptions["onUserDialog"]> = (
9913 request,
9914 callbackOptions,
@@ -9988,6 +10182,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10182 }),
10183 canUseTool,
10184 onUserDialog,
10185 + onElicitation,
10186 supportedDialogKinds: ["resume_return"],
10187 ...(appendSystemPromptFileText === undefined ? {} : { appendSystemPromptFileText }),
10188 ...(toolSearchOverride === undefined ? {} : { toolSearchOverride }),
apps/server/src/provider/CodexMcpElicitation.ts
+12 -4
@@ -76,7 +76,14 @@ function mcpElicitationPersistenceDecision(
76 return null;
77 }
78
79 -function mcpElicitationFormFields(payload: EffectCodexSchema.McpServerElicitationRequestParams) {
79 +// Claude hands over the same MCP request with its own envelope; these are the
80 +// only fields the response is built from.
81 +type McpElicitationResponseInput = {
82 + readonly mode: string;
83 + readonly requestedSchema?: unknown;
84 +};
85 +
86 +function mcpElicitationFormFields(payload: McpElicitationResponseInput) {
87 if (payload.mode === "url" || !isMcpElicitationForm(payload.requestedSchema)) {
88 return undefined;
89 }
@@ -171,7 +178,7 @@ export function describeMcpElicitation(
178 }
179
180 export function toMcpElicitationResponse(
174 - payload: EffectCodexSchema.McpServerElicitationRequestParams,
181 + payload: McpElicitationResponseInput,
182 decision: ProviderApprovalDecision,
183 ): EffectCodexSchema.McpServerElicitationRequestResponse {
184 if (decision === "decline" || decision === "cancel") {
@@ -196,8 +203,9 @@ export function toMcpElicitationResponse(
203 const chosenOption = options.find((option) =>
204 persist
205 ? mcpElicitationPersistenceDecision(option.value) === decision
199 - : /once|accept|approve|allow/i.test(option.value) &&
200 - mcpElicitationPersistenceDecision(option.value) === null,
206 + : /^(?:once|accept|approve|allow)(?:[_\s-]*(?:once(?:[_\s-]*only)?|this[_\s-]*time))?$/i.test(
207 + option.value.trim(),
208 + ) && mcpElicitationPersistenceDecision(option.value) === null,
209 );
210 if (chosenOption) {
211 content[key] = chosenOption.value;