Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

fix(codex): show app access approval prompts (#8058)

Theo Browne7c6163c67aa1
diff --git a/apps/mobile/src/features/threads/PendingApprovalCard.tsx b/apps/mobile/src/features/threads/PendingApprovalCard.tsx
index 377ae82ab..fb9cc72d2 100644
--- a/apps/mobile/src/features/threads/PendingApprovalCard.tsx
+++ b/apps/mobile/src/features/threads/PendingApprovalCard.tsx
@@ -1,4 +1,8 @@
-import type { ApprovalRequestId, ProviderApprovalDecision } from "@t3tools/contracts";
+import type {
+ ApprovalRequestId,
+ ProviderApprovalDecision,
+ ProviderApprovalOption,
+} from "@t3tools/contracts";
import { Pressable, View } from "react-native";
import { AppText as Text } from "../../components/AppText";
@@ -13,7 +17,14 @@ export interface PendingApprovalCardProps {
) => Promise<unknown>;
}
+const DEFAULT_APPROVAL_OPTIONS = [
+ { decision: "accept", label: "Allow once" },
+ { decision: "acceptForSession", label: "Allow session" },
+ { decision: "decline", label: "Decline" },
+] satisfies ReadonlyArray<ProviderApprovalOption>;
+
export function PendingApprovalCard(props: PendingApprovalCardProps) {
+ const options = props.approval.options ?? DEFAULT_APPROVAL_OPTIONS;
// Opaque for the same reason as PendingUserInputCard: nothing blurs the feed
// behind this card, so a translucent surface bleeds messages through it.
return (
@@ -22,7 +33,7 @@ export function PendingApprovalCard(props: PendingApprovalCardProps) {
Approval needed
</Text>
<Text className="font-t3-bold text-lg text-neutral-950 dark:text-neutral-50">
- {props.approval.requestKind}
+ {props.approval.appName ?? props.approval.requestKind}
</Text>
{props.approval.detail ? (
<Text className="font-sans text-sm leading-normal text-neutral-600 dark:text-neutral-400">
@@ -30,29 +41,32 @@ export function PendingApprovalCard(props: PendingApprovalCardProps) {
</Text>
) : null}
<View className="flex-row flex-wrap gap-2.5">
- <Pressable
- className="items-center justify-center rounded-[14px] bg-blue-500 px-3.5 py-3"
- disabled={props.respondingApprovalId === props.approval.requestId}
- onPress={() => void props.onRespond(props.approval.requestId, "accept")}
- >
- <Text className="font-t3-extrabold text-sm text-white">Allow once</Text>
- </Pressable>
- <Pressable
- className="items-center justify-center rounded-[14px] bg-neutral-200 px-3.5 py-3 dark:bg-neutral-800"
- disabled={props.respondingApprovalId === props.approval.requestId}
- onPress={() => void props.onRespond(props.approval.requestId, "acceptForSession")}
- >
- <Text className="font-t3-bold text-sm text-neutral-950 dark:text-neutral-50">
- Allow session
- </Text>
- </Pressable>
- <Pressable
- className="items-center justify-center rounded-[14px] bg-rose-100 px-3.5 py-3 dark:bg-rose-500/18"
- disabled={props.respondingApprovalId === props.approval.requestId}
- onPress={() => void props.onRespond(props.approval.requestId, "decline")}
- >
- <Text className="font-t3-bold text-sm text-rose-700 dark:text-rose-300">Decline</Text>
- </Pressable>
+ {options.map((option) => (
+ <Pressable
+ key={option.decision}
+ className={`items-center justify-center rounded-[14px] px-3.5 py-3 ${
+ option.decision === "accept"
+ ? "bg-blue-500"
+ : option.decision === "decline"
+ ? "bg-rose-100 dark:bg-rose-500/18"
+ : "bg-neutral-200 dark:bg-neutral-800"
+ }`}
+ disabled={props.respondingApprovalId === props.approval.requestId}
+ onPress={() => void props.onRespond(props.approval.requestId, option.decision)}
+ >
+ <Text
+ className={`text-sm ${
+ option.decision === "accept"
+ ? "font-t3-extrabold text-white"
+ : option.decision === "decline"
+ ? "font-t3-bold text-rose-700 dark:text-rose-300"
+ : "font-t3-bold text-neutral-950 dark:text-neutral-50"
+ }`}
+ >
+ {option.label}
+ </Text>
+ </Pressable>
+ ))}
</View>
</View>
);
diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.ts
index 55dcaa9fb..e2943ebc1 100644
--- a/apps/mobile/src/lib/threadActivity.test.ts
+++ b/apps/mobile/src/lib/threadActivity.test.ts
@@ -15,6 +15,7 @@ import {
import {
buildPendingUserInputAnswers,
buildThreadFeed,
+ derivePendingApprovals,
deriveThreadFeedPresentation,
isPendingUserInputOptionSelected,
setPendingUserInputCustomAnswer,
@@ -142,6 +143,59 @@ describe("pending user input answers", () => {
});
});
+describe("pending approvals", () => {
+ it("keeps app access approvals and persistence choices from remote environments", () => {
+ const options = [
+ { decision: "decline", label: "Decline" },
+ { decision: "acceptAlways", label: "Always allow Safari" },
+ { decision: "accept", label: "Approve" },
+ ];
+ const activity = makeActivity({
+ id: EventId.make("approval-safari"),
+ kind: "approval.requested",
+ summary: "App access approval requested",
+ createdAt: "2026-08-24T00:00:00.000Z",
+ payload: {
+ requestId: "req-safari",
+ requestType: "mcp_elicitation_approval",
+ detail: "Allow ChatGPT to use Safari?",
+ appName: "Safari",
+ options,
+ },
+ });
+
+ expect(derivePendingApprovals([activity])).toEqual([
+ {
+ requestId: "req-safari",
+ requestKind: "mcp-elicitation",
+ createdAt: "2026-08-24T00:00:00.000Z",
+ detail: "Allow ChatGPT to use Safari?",
+ appName: "Safari",
+ options,
+ },
+ ]);
+ });
+
+ it("removes an app access approval after a remote client rejects it", () => {
+ const requested = makeActivity({
+ id: EventId.make("approval-safari-open"),
+ kind: "approval.requested",
+ summary: "App access approval requested",
+ createdAt: "2026-08-24T00:00:00.000Z",
+ payload: { requestId: "req-safari", requestKind: "mcp-elicitation" },
+ });
+ const resolved = makeActivity({
+ id: EventId.make("approval-safari-resolved"),
+ kind: "approval.resolved",
+ summary: "Approval resolved",
+ createdAt: "2026-08-24T00:00:01.000Z",
+ payload: { requestId: "req-safari", decision: "decline" },
+ });
+
+ expect(derivePendingApprovals([requested, resolved])).toEqual([]);
+ });
+});
+
function makeActivity(
input: Partial<OrchestrationThreadActivity> &
Pick<OrchestrationThreadActivity, "id" | "kind" | "summary" | "createdAt">,
diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.ts
index fbde33da8..9e0cb64ae 100644
--- a/apps/mobile/src/lib/threadActivity.ts
+++ b/apps/mobile/src/lib/threadActivity.ts
@@ -1,4 +1,9 @@
-import { ApprovalRequestId, isToolLifecycleItemType } from "@t3tools/contracts";
+import {
+ ApprovalRequestId,
+ isToolLifecycleItemType,
+ ProviderApprovalOption,
+ ProviderRequestKind,
+} from "@t3tools/contracts";
import type {
OrchestrationLatestTurn,
OrchestrationThread,
@@ -11,14 +16,20 @@ import { formatDuration } from "@t3tools/shared/orchestrationTiming";
import * as Arr from "effect/Array";
import * as Order from "effect/Order";
+import * as Schema from "effect/Schema";
export interface PendingApproval {
readonly requestId: ApprovalRequestId;
- readonly requestKind: "command" | "file-read" | "file-change";
+ readonly requestKind: ProviderRequestKind;
readonly createdAt: string;
readonly detail?: string;
+ readonly appName?: string;
+ readonly options?: ReadonlyArray<ProviderApprovalOption>;
}
+const isProviderRequestKind = Schema.is(ProviderRequestKind);
+const isProviderApprovalOption = Schema.is(ProviderApprovalOption);
+
export interface PendingUserInput {
readonly requestId: ApprovalRequestId;
readonly createdAt: string;
@@ -147,6 +158,8 @@ function requestKindFromRequestType(requestType: unknown): PendingApproval["requ
case "file_change_approval":
case "apply_patch_approval":
return "file-change";
+ case "mcp_elicitation_approval":
+ return "mcp-elicitation";
default:
return null;
}
@@ -1375,13 +1388,14 @@ export function derivePendingApprovals(
? (activity.payload as Record<string, unknown>)
: null;
const requestId = parseApprovalRequestId(payload?.requestId);
- const requestKind =
- payload?.requestKind === "command" ||
- payload?.requestKind === "file-read" ||
- payload?.requestKind === "file-change"
- ? payload.requestKind
- : requestKindFromRequestType(payload?.requestType);
+ const requestKind = isProviderRequestKind(payload?.requestKind)
+ ? payload.requestKind
+ : requestKindFromRequestType(payload?.requestType);
const detail = typeof payload?.detail === "string" ? payload.detail : undefined;
+ const appName = typeof payload?.appName === "string" ? payload.appName : undefined;
+ const options = Array.isArray(payload?.options)
+ ? payload.options.filter(isProviderApprovalOption)
+ : undefined;
if (activity.kind === "approval.requested" && requestId && requestKind) {
openByRequestId.set(requestId, {
@@ -1389,6 +1403,8 @@ export function derivePendingApprovals(
requestKind,
createdAt: activity.createdAt,
...(detail ? { detail } : {}),
+ ...(appName ? { appName } : {}),
+ ...(options && options.length > 0 ? { options } : {}),
});
continue;
}
diff --git a/apps/server/integration/OrchestrationEngineHarness.integration.ts b/apps/server/integration/OrchestrationEngineHarness.integration.ts
index 71ef59a09..f332b080c 100644
--- a/apps/server/integration/OrchestrationEngineHarness.integration.ts
+++ b/apps/server/integration/OrchestrationEngineHarness.integration.ts
@@ -8,6 +8,7 @@ import {
ProviderDriverKind,
type OrchestrationEvent,
type OrchestrationThread,
+ type ProviderApprovalDecision,
} from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as Exit from "effect/Exit";
@@ -199,14 +200,14 @@ export interface OrchestrationIntegrationHarness {
requestId: string,
predicate: (row: {
readonly status: "pending" | "resolved";
- readonly decision: "accept" | "acceptForSession" | "decline" | "cancel" | null;
+ readonly decision: ProviderApprovalDecision | null;
readonly resolvedAt: string | null;
}) => boolean,
timeoutMs?: number,
) => Effect.Effect<
{
readonly status: "pending" | "resolved";
- readonly decision: "accept" | "acceptForSession" | "decline" | "cancel" | null;
+ readonly decision: ProviderApprovalDecision | null;
readonly resolvedAt: string | null;
},
never
@@ -493,7 +494,7 @@ export const makeOrchestrationIntegrationHarness = (
row,
): row is {
readonly status: "pending" | "resolved";
- readonly decision: "accept" | "acceptForSession" | "decline" | "cancel" | null;
+ readonly decision: ProviderApprovalDecision | null;
readonly resolvedAt: string | null;
} => row !== null && predicate(row),
`pending approval '${requestId}'`,
@@ -501,7 +502,7 @@ export const makeOrchestrationIntegrationHarness = (
) as Effect.Effect<
{
readonly status: "pending" | "resolved";
- readonly decision: "accept" | "acceptForSession" | "decline" | "cancel" | null;
+ readonly decision: ProviderApprovalDecision | null;
readonly resolvedAt: string | null;
},
never
diff --git a/apps/server/src/orchestration/Layers/ProjectionPipeline.ts b/apps/server/src/orchestration/Layers/ProjectionPipeline.ts
index e9a625dd9..d06bb03ec 100644
--- a/apps/server/src/orchestration/Layers/ProjectionPipeline.ts
+++ b/apps/server/src/orchestration/Layers/ProjectionPipeline.ts
@@ -1507,6 +1507,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
const resolvedDecision =
resolvedDecisionRaw === "accept" ||
resolvedDecisionRaw === "acceptForSession" ||
+ resolvedDecisionRaw === "acceptAlways" ||
resolvedDecisionRaw === "decline" ||
resolvedDecisionRaw === "cancel"
? resolvedDecisionRaw
diff --git a/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.approval.test.ts b/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.approval.test.ts
index 05370781c..0d262028d 100644
--- a/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.approval.test.ts
+++ b/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.approval.test.ts
@@ -30,4 +30,41 @@ describe("runtimeEventToActivities approval details", () => {
expect(activity?.kind).toBe("approval.requested");
expect((activity?.payload as Record<string, unknown> | undefined)?.detail).toBe(detail);
});
+
+ it("keeps app details and approval options available to remote clients", () => {
+ const options = [
+ { decision: "decline", label: "Decline" },
+ { decision: "acceptAlways", label: "Always allow Safari" },
+ { decision: "accept", label: "Approve" },
+ ] as const;
+ const event = {
+ type: "request.opened",
+ eventId: EventId.make("evt-mcp-elicitation"),
+ provider: ProviderDriverKind.make("codex"),
+ createdAt: "2026-08-24T00:00:00.000Z",
+ threadId: ThreadId.make("thread-1"),
+ requestId: RuntimeRequestId.make("approval-safari"),
+ payload: {
+ requestType: "mcp_elicitation_approval",
+ detail: "Allow ChatGPT to use Safari?",
+ appName: "Safari",
+ options,
+ },
+ } satisfies ProviderRuntimeEvent;
+
+ const [activity] = runtimeEventToActivities(event);
+
+ expect(activity).toMatchObject({
+ kind: "approval.requested",
+ summary: "App access approval requested",
+ payload: {
+ requestId: "approval-safari",
+ requestKind: "mcp-elicitation",
+ requestType: "mcp_elicitation_approval",
+ detail: "Allow ChatGPT to use Safari?",
+ appName: "Safari",
+ options,
+ },
+ });
+ });
});
diff --git a/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts b/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts
index 953ba1ec9..7ec3a7e64 100644
--- a/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts
+++ b/apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts
@@ -298,7 +298,7 @@ function sessionStatusAllowsActiveTurn(
function requestKindFromCanonicalRequestType(
requestType: string | undefined,
-): "command" | "file-read" | "file-change" | undefined {
+): "command" | "file-read" | "file-change" | "mcp-elicitation" | undefined {
switch (requestType) {
case "command_execution_approval":
case "exec_command_approval":
@@ -308,6 +308,8 @@ function requestKindFromCanonicalRequestType(
case "file_change_approval":
case "apply_patch_approval":
return "file-change";
+ case "mcp_elicitation_approval":
+ return "mcp-elicitation";
default:
return undefined;
}
@@ -388,12 +390,16 @@ export function runtimeEventToActivities(
? "File-read approval requested"
: requestKind === "file-change"
? "File-change approval requested"
- : "Approval requested",
+ : requestKind === "mcp-elicitation"
+ ? "App access approval requested"
+ : "Approval requested",
payload: {
requestId: toApprovalRequestId(event.requestId),
...(requestKind ? { requestKind } : {}),
requestType: event.payload.requestType,
...(event.payload.detail ? { detail: event.payload.detail } : {}),
+ ...(event.payload.appName ? { appName: event.payload.appName } : {}),
+ ...(event.payload.options ? { options: event.payload.options } : {}),
},
turnId: toTurnId(event.turnId) ?? null,
...maybeSequence,
diff --git a/apps/server/src/provider/Layers/CodexAdapter.test.ts b/apps/server/src/provider/Layers/CodexAdapter.test.ts
index 26fb1b166..4986d02c9 100644
--- a/apps/server/src/provider/Layers/CodexAdapter.test.ts
+++ b/apps/server/src/provider/Layers/CodexAdapter.test.ts
@@ -1066,6 +1066,79 @@ lifecycleLayer("CodexAdapterLive lifecycle", (it) => {
}),
);
+ it.effect("maps MCP elicitation requests into app access approvals", () =>
+ Effect.gen(function* () {
+ const { adapter, runtime } = yield* startLifecycleRuntime();
+ const firstEventFiber = yield* Stream.runHead(adapter.streamEvents).pipe(Effect.forkChild);
+
+ yield* runtime.emit({
+ id: asEventId("evt-mcp-elicitation"),
+ kind: "request",
+ provider: ProviderDriverKind.make("codex"),
+ threadId: asThreadId("thread-1"),
+ createdAt: "2026-08-24T00:00:00.000Z",
+ method: "mcpServer/elicitation/request",
+ requestKind: "mcp-elicitation",
+ requestId: ApprovalRequestId.make("req-safari"),
+ turnId: asTurnId("turn-1"),
+ payload: {
+ mode: "form",
+ message: "Allow ChatGPT to use Safari?",
+ serverName: "computer-use",
+ threadId: "provider-thread-1",
+ turnId: "turn-1",
+ _meta: { app_name: "Safari", persist: ["session", "always"] },
+ requestedSchema: { type: "object", properties: {} },
+ },
+ } satisfies ProviderEvent);
+
+ const firstEvent = yield* Fiber.join(firstEventFiber);
+
+ NodeAssert.equal(firstEvent._tag, "Some");
+ if (firstEvent._tag !== "Some" || firstEvent.value.type !== "request.opened") {
+ return;
+ }
+ NodeAssert.equal(firstEvent.value.payload.requestType, "mcp_elicitation_approval");
+ NodeAssert.equal(firstEvent.value.payload.appName, "Safari");
+ NodeAssert.equal(firstEvent.value.payload.detail, "Allow ChatGPT to use Safari?");
+ NodeAssert.deepStrictEqual(firstEvent.value.payload.options, [
+ { decision: "cancel", label: "Cancel" },
+ { decision: "decline", label: "Decline" },
+ { decision: "acceptForSession", label: "Always allow this session" },
+ { decision: "acceptAlways", label: "Always allow" },
+ { decision: "accept", label: "Approve" },
+ ]);
+ }),
+ );
+
+ it.effect("preserves MCP elicitation type when an app access request resolves", () =>
+ Effect.gen(function* () {
+ const { adapter, runtime } = yield* startLifecycleRuntime();
+ const firstEventFiber = yield* Stream.runHead(adapter.streamEvents).pipe(Effect.forkChild);
+
+ yield* runtime.emit({
+ id: asEventId("evt-mcp-elicitation-resolved"),
+ kind: "notification",
+ provider: ProviderDriverKind.make("codex"),
+ threadId: asThreadId("thread-1"),
+ createdAt: "2026-08-24T00:00:00.000Z",
+ method: "item/requestApproval/decision",
+ requestKind: "mcp-elicitation",
+ requestId: ApprovalRequestId.make("req-safari"),
+ payload: { decision: "acceptAlways" },
+ } satisfies ProviderEvent);
+
+ const firstEvent = yield* Fiber.join(firstEventFiber);
+
+ NodeAssert.equal(firstEvent._tag, "Some");
+ if (firstEvent._tag !== "Some" || firstEvent.value.type !== "request.resolved") {
+ return;
+ }
+ NodeAssert.equal(firstEvent.value.payload.requestType, "mcp_elicitation_approval");
+ NodeAssert.equal(firstEvent.value.payload.decision, "acceptAlways");
+ }),
+ );
+
it.effect("preserves file-read request type when mapping serverRequest/resolved", () =>
Effect.gen(function* () {
const { adapter, runtime } = yield* startLifecycleRuntime();
diff --git a/apps/server/src/provider/Layers/CodexAdapter.ts b/apps/server/src/provider/Layers/CodexAdapter.ts
index bc48f94b3..0f7d99966 100644
--- a/apps/server/src/provider/Layers/CodexAdapter.ts
+++ b/apps/server/src/provider/Layers/CodexAdapter.ts
@@ -57,6 +57,7 @@ import { ServerConfig } from "../../config.ts";
import {
CodexResumeCursorSchema,
CodexSessionRuntimeThreadIdMissingError,
+ describeMcpElicitation,
makeCodexSessionRuntime,
type CodexSessionRuntimeError,
type CodexSessionRuntimeOptions,
@@ -302,6 +303,8 @@ function toRequestTypeFromMethod(method: string): CanonicalRequestType {
return "file_read_approval";
case "item/fileChange/requestApproval":
return "file_change_approval";
+ case "mcpServer/elicitation/request":
+ return "mcp_elicitation_approval";
case "applyPatchApproval":
return "apply_patch_approval";
case "execCommandApproval":
@@ -325,6 +328,8 @@ function toRequestTypeFromKind(kind: ProviderRequestKind | undefined): Canonical
return "file_read_approval";
case "file-change":
return "file_change_approval";
+ case "mcp-elicitation":
+ return "mcp_elicitation_approval";
default:
return "unknown";
}
@@ -800,6 +805,11 @@ function mapToRuntimeEvents(
];
}
+ const elicitation =
+ event.method === "mcpServer/elicitation/request"
+ ? readPayload(EffectCodexSchema.McpServerElicitationRequestParams, event.payload)
+ : undefined;
+ const elicitationApproval = elicitation ? describeMcpElicitation(elicitation) : undefined;
const detail = (() => {
switch (event.method) {
case "item/commandExecution/requestApproval": {
@@ -816,6 +826,8 @@ function mapToRuntimeEvents(
);
return payload?.reason ?? undefined;
}
+ case "mcpServer/elicitation/request":
+ return elicitation?.message;
case "applyPatchApproval": {
const payload = readPayload(
EffectCodexSchema.ServerRequest__ApplyPatchApprovalParams,
@@ -849,6 +861,12 @@ function mapToRuntimeEvents(
payload: {
requestType: toRequestTypeFromMethod(event.method),
...(detail ? { detail } : {}),
+ ...(elicitationApproval
+ ? {
+ appName: elicitationApproval.appName,
+ options: elicitationApproval.options,
+ }
+ : {}),
...(event.payload !== undefined ? { args: event.payload } : {}),
},
},
diff --git a/apps/server/src/provider/Layers/CodexCollabRuntime.integration.test.ts b/apps/server/src/provider/Layers/CodexCollabRuntime.integration.test.ts
index a1b46e003..5af06efb7 100644
--- a/apps/server/src/provider/Layers/CodexCollabRuntime.integration.test.ts
+++ b/apps/server/src/provider/Layers/CodexCollabRuntime.integration.test.ts
@@ -13,9 +13,11 @@ import * as NodePath from "node:path";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { it } from "@effect/vitest";
-import { ThreadId } from "@t3tools/contracts";
+import { type ProviderApprovalDecision, type ProviderEvent, ThreadId } from "@t3tools/contracts";
+import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
+import * as Schema from "effect/Schema";
import * as Stream from "effect/Stream";
import { assert, describe } from "vite-plus/test";
@@ -25,6 +27,14 @@ import { makeCodexSessionRuntime } from "./CodexSessionRuntime.ts";
const ROOT = wireFixture.rootThreadId;
const [CHILD_A, CHILD_B] = wireFixture.childThreadIds as [string, string];
const MEMORY = "memory-consolidation-thread";
+const decodeMcpElicitationResponse = Schema.decodeUnknownEffect(
+ Schema.fromJsonString(
+ Schema.Struct({
+ id: Schema.Number,
+ result: Schema.Unknown,
+ }),
+ ),
+);
/**
* The captured sequence, extended with the shapes the live capture didn't
@@ -328,4 +338,116 @@ describe("CodexSessionRuntime collab integration", () => {
yield* runtime.close;
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);
+
+ const elicitationCases = [
+ {
+ decision: "accept",
+ response: { action: "accept", content: { approval: "once" } },
+ },
+ {
+ decision: "acceptForSession",
+ response: {
+ action: "accept",
+ _meta: { persist: "session" },
+ content: { approval: "session" },
+ },
+ },
+ {
+ decision: "acceptAlways",
+ response: {
+ action: "accept",
+ _meta: { persist: "always" },
+ content: { approval: "always" },
+ },
+ },
+ { decision: "decline", response: { action: "decline" } },
+ { decision: "cancel", response: { action: "cancel" } },
+ ] satisfies ReadonlyArray<{
+ readonly decision: ProviderApprovalDecision;
+ readonly response: Record<string, unknown>;
+ }>;
+
+ for (const { decision, response } of elicitationCases) {
+ it.live(`returns the MCP elicitation ${decision} response to Codex`, () =>
+ Effect.gen(function* () {
+ const scriptedRequest = {
+ id: 7001,
+ method: "mcpServer/elicitation/request",
+ params: {
+ mode: "form",
+ message: "Allow ChatGPT to use Safari?",
+ serverName: "computer-use",
+ threadId: ROOT,
+ turnId: wireFixture.responses.turnStart.turn.id,
+ _meta: { app_name: "Safari", persist: ["session", "always"] },
+ requestedSchema: {
+ type: "object",
+ properties: {
+ approval: {
+ type: "string",
+ enum: ["once", "session", "always"],
+ },
+ },
+ required: ["approval"],
+ },
+ },
+ };
+ const script = {
+ rootThreadId: ROOT,
+ holdTurnOpen: true,
+ completeTurnOnServerResponse: true,
+ notifications: [],
+ serverRequests: [scriptedRequest],
+ };
+ const responsesPath = `${scriptPath}.responses`;
+ // @effect-diagnostics-next-line preferSchemaOverJson:off
+ NodeFS.writeFileSync(scriptPath, JSON.stringify(script), "utf8");
+ NodeFS.rmSync(responsesPath, { force: true });
+ yield* Effect.addFinalizer(() =>
+ Effect.sync(() => {
+ NodeFS.rmSync(scriptPath, { force: true });
+ NodeFS.rmSync(responsesPath, { force: true });
+ }),
+ );
+
+ const runtime = yield* makeCodexSessionRuntime({
+ threadId: ThreadId.make("thread-codex-mcp-elicitation"),
+ binaryPath: peerPath,
+ cwd: "/tmp",
+ runtimeMode: "auto",
+ environment: { ...process.env, T3_CODEX_COLLAB_SCRIPT: scriptPath },
+ });
+ const approvalRequested = yield* Deferred.make<ProviderEvent>();
+ const turnCompleted = yield* Deferred.make<void>();
+ yield* runtime.events.pipe(
+ Stream.runForEach((event) =>
+ event.method === "mcpServer/elicitation/request"
+ ? Deferred.succeed(approvalRequested, event).pipe(Effect.asVoid)
+ : event.method === "turn/completed"
+ ? Deferred.succeed(turnCompleted, undefined).pipe(Effect.asVoid)
+ : Effect.void,
+ ),
+ Effect.forkScoped,
+ );
+
+ yield* runtime.start();
+ yield* runtime.sendTurn({ input: "Open Safari" });
+ const approval = yield* Deferred.await(approvalRequested);
+ assert.equal(approval.requestKind, "mcp-elicitation");
+ assert.isDefined(approval.requestId);
+ if (approval.requestId === undefined) return;
+
+ yield* runtime.respondToRequest(approval.requestId, decision);
+ yield* Deferred.await(turnCompleted);
+
+ const recordedResponse = yield* decodeMcpElicitationResponse(
+ NodeFS.readFileSync(responsesPath, "utf8"),
+ );
+ assert.equal(recordedResponse.id, scriptedRequest.id);
+ assert.deepEqual(recordedResponse.result, response);
+
+ yield* runtime.close;
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
+ );
+ }
});
diff --git a/apps/server/src/provider/Layers/CodexSessionRuntime.test.ts b/apps/server/src/provider/Layers/CodexSessionRuntime.test.ts
index a80ef2cf5..6a6cec5b1 100644
--- a/apps/server/src/provider/Layers/CodexSessionRuntime.test.ts
+++ b/apps/server/src/provider/Layers/CodexSessionRuntime.test.ts
@@ -17,10 +17,12 @@ import {
import { codexSessionAppServerArgs } from "./codexLaunchArgs.ts";
import {
buildTurnStartParams,
+ describeMcpElicitation,
hasConfiguredMcpServer,
isRecoverableThreadResumeError,
makeMemoryConsolidationNotificationFilter,
openCodexThread,
+ toMcpElicitationResponse,
} from "./CodexSessionRuntime.ts";
const isCodexAppServerRequestError = Schema.is(CodexErrors.CodexAppServerRequestError);
@@ -248,6 +250,208 @@ describe("buildTurnStartParams", () => {
});
});
+describe("Codex MCP elicitation approvals", () => {
+ const request = {
+ mode: "form",
+ message: "Allow ChatGPT to use Safari?",
+ serverName: "computer-use",
+ threadId: "provider-thread-1",
+ turnId: "turn-1",
+ _meta: {
+ app_name: "Safari",
+ persist: ["session", "always"],
+ },
+ requestedSchema: {
+ type: "object",
+ properties: {
+ approval: {
+ type: "string",
+ oneOf: [
+ { const: "once", title: "Allow once" },
+ { const: "session", title: "Allow for this session" },
+ { const: "always", title: "Always allow Safari" },
+ ],
+ },
+ },
+ required: ["approval"],
+ },
+ } satisfies EffectCodexSchema.McpServerElicitationRequestParams;
+
+ it("preserves the app name and advertised persistence choices", () => {
+ NodeAssert.deepStrictEqual(describeMcpElicitation(request), {
+ appName: "Safari",
+ options: [
+ { decision: "cancel", label: "Cancel" },
+ { decision: "decline", label: "Decline" },
+ { decision: "acceptForSession", label: "Allow for this session" },
+ { decision: "acceptAlways", label: "Always allow Safari" },
+ { decision: "accept", label: "Approve" },
+ ],
+ });
+ });
+
+ it("extracts the app name from a Computer Use request without metadata", () => {
+ const { _meta, ...requestWithoutMetadata } = request;
+
+ NodeAssert.equal(describeMcpElicitation(requestWithoutMetadata).appName, "Safari");
+ });
+
+ it("returns the accepted form option to Codex", () => {
+ NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "accept"), {
+ action: "accept",
+ content: { approval: "once" },
+ });
+ });
+
+ it("returns session-scoped approval in the MCP response", () => {
+ NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "acceptForSession"), {
+ action: "accept",
+ _meta: { persist: "session" },
+ content: { approval: "session" },
+ });
+ });
+
+ it("returns persistent approval in the MCP response", () => {
+ NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "acceptAlways"), {
+ action: "accept",
+ _meta: { persist: "always" },
+ content: { approval: "always" },
+ });
+ });
+
+ it("returns rejection without form content", () => {
+ NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "decline"), {
+ action: "decline",
+ });
+ });
+
+ it("returns cancellation without form content", () => {
+ NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "cancel"), {
+ action: "cancel",
+ });
+ });
+
+ it("supports boolean permanent-approval fields", () => {
+ const booleanRequest = {
+ ...request,
+ _meta: { app_name: "Safari" },
+ requestedSchema: {
+ type: "object",
+ properties: {
+ always: { type: "boolean", title: "Always allow Safari" },
+ },
+ },
+ } satisfies EffectCodexSchema.McpServerElicitationRequestParams;
+
+ NodeAssert.ok(
+ describeMcpElicitation(booleanRequest).options.some(
+ (option) => option.decision === "acceptAlways",
+ ),
+ );
+ NodeAssert.deepStrictEqual(toMcpElicitationResponse(booleanRequest, "acceptAlways"), {
+ action: "accept",
+ _meta: { persist: "always" },
+ content: { always: true },
+ });
+ });
+
+ it("preserves valid nullable MCP form fields and persistence choices", () => {
+ const nullableRequest = {
+ ...request,
+ _meta: {
+ app_name: null,
+ appName: "Safari",
+ connector_name: null,
+ persist: null,
+ target: null,
+ tool_params: null,
+ },
+ requestedSchema: {
+ type: "object",
+ properties: {
+ approval: {
+ type: "string",
+ title: null,
+ description: null,
+ default: null,
+ enum: ["once", "always"],
+ enumNames: null,
+ },
+ },
+ required: ["approval"],
+ },
+ } satisfies EffectCodexSchema.McpServerElicitationRequestParams;
+
+ NodeAssert.equal(describeMcpElicitation(nullableRequest).appName, "Safari");
+ NodeAssert.ok(
+ describeMcpElicitation(nullableRequest).options.some(
+ (option) => option.decision === "acceptAlways",
+ ),
+ );
+ NodeAssert.deepStrictEqual(toMcpElicitationResponse(nullableRequest, "acceptAlways"), {
+ action: "accept",
+ _meta: { persist: "always" },
+ content: { approval: "always" },
+ });
+ });
+
+ it("declines required form fields that an approval prompt cannot collect", () => {
+ const inputRequest = {
+ ...request,
+ requestedSchema: {
+ type: "object",
+ properties: {
+ email: { type: "string", format: "email" },
+ },
+ required: ["email"],
+ },
+ } satisfies EffectCodexSchema.McpServerElicitationRequestParams;
+
+ NodeAssert.deepStrictEqual(toMcpElicitationResponse(inputRequest, "accept"), {
+ action: "decline",
+ });
+ });
+
+ it("does not approve URL elicitations without opening their requested URL", () => {
+ const urlRequest = {
+ mode: "url",
+ message: "Finish signing in to continue.",
+ serverName: "computer-use",
+ threadId: "provider-thread-1",
+ turnId: "turn-1",
+ elicitationId: "sign-in-1",
+ url: "https://example.com/authorize",
+ } satisfies EffectCodexSchema.McpServerElicitationRequestParams;
+
+ NodeAssert.deepStrictEqual(toMcpElicitationResponse(urlRequest, "accept"), {
+ action: "decline",
+ });
+ });
+
+ it("omits persistence choices that cannot satisfy required form fields", () => {
+ const onceOnlyRequest = {
+ ...request,
+ _meta: { app_name: "Safari", persist: ["session", "always"] },
+ requestedSchema: {
+ type: "object",
+ properties: {
+ approval: {
+ type: "string",
+ enum: ["once"],
+ },
+ },
+ required: ["approval"],
+ },
+ } satisfies EffectCodexSchema.McpServerElicitationRequestParams;
+
+ NodeAssert.deepStrictEqual(describeMcpElicitation(onceOnlyRequest).options, [
+ { decision: "cancel", label: "Cancel" },
+ { decision: "decline", label: "Decline" },
+ { decision: "accept", label: "Approve" },
+ ]);
+ });
+});
+
describe("buildCodexDeveloperInstructions", () => {
it("appends runtime info after the mode instructions", () => {
const instructions = buildCodexDeveloperInstructions("default", {
diff --git a/apps/server/src/provider/Layers/CodexSessionRuntime.ts b/apps/server/src/provider/Layers/CodexSessionRuntime.ts
index fd926e43d..b34067b7f 100644
--- a/apps/server/src/provider/Layers/CodexSessionRuntime.ts
+++ b/apps/server/src/provider/Layers/CodexSessionRuntime.ts
@@ -6,6 +6,7 @@ import {
ProviderItemId,
type ProviderInstanceId,
type ProviderApprovalDecision,
+ type ProviderApprovalOption,
type ProviderEvent,
type ProviderInteractionMode,
type ProviderRequestKind,
@@ -73,6 +74,58 @@ const CodexUserInputAnswerObject = Schema.Struct({
});
const isCodexResumeCursorSchema = Schema.is(CodexResumeCursorSchema);
const isCodexUserInputAnswerObject = Schema.is(CodexUserInputAnswerObject);
+const NullableMcpElicitationString = Schema.NullOr(Schema.String);
+const McpElicitationMetadata = Schema.Struct({
+ app: Schema.optionalKey(NullableMcpElicitationString),
+ app_name: Schema.optionalKey(NullableMcpElicitationString),
+ appName: Schema.optionalKey(NullableMcpElicitationString),
+ connector_name: Schema.optionalKey(NullableMcpElicitationString),
+ connectorName: Schema.optionalKey(NullableMcpElicitationString),
+ allowPersistentApproval: Schema.optionalKey(Schema.NullOr(Schema.Boolean)),
+ persist: Schema.optionalKey(
+ Schema.NullOr(Schema.Union([Schema.String, Schema.Array(Schema.String)])),
+ ),
+ target: Schema.optionalKey(
+ Schema.NullOr(
+ Schema.Struct({
+ app: Schema.optionalKey(NullableMcpElicitationString),
+ name: Schema.optionalKey(NullableMcpElicitationString),
+ }),
+ ),
+ ),
+ tool_params: Schema.optionalKey(
+ Schema.NullOr(
+ Schema.Struct({
+ app: Schema.optionalKey(NullableMcpElicitationString),
+ app_name: Schema.optionalKey(NullableMcpElicitationString),
+ }),
+ ),
+ ),
+});
+const McpElicitationFormField = Schema.Struct({
+ type: Schema.optionalKey(NullableMcpElicitationString),
+ title: Schema.optionalKey(NullableMcpElicitationString),
+ description: Schema.optionalKey(NullableMcpElicitationString),
+ default: Schema.optionalKey(Schema.Unknown),
+ enum: Schema.optionalKey(Schema.NullOr(Schema.Array(Schema.String))),
+ enumNames: Schema.optionalKey(Schema.NullOr(Schema.Array(Schema.String))),
+ oneOf: Schema.optionalKey(
+ Schema.NullOr(
+ Schema.Array(
+ Schema.Struct({
+ const: Schema.String,
+ title: Schema.optionalKey(NullableMcpElicitationString),
+ }),
+ ),
+ ),
+ ),
+});
+const McpElicitationForm = Schema.Struct({
+ properties: Schema.optionalKey(Schema.Record(Schema.String, McpElicitationFormField)),
+ required: Schema.optionalKey(Schema.NullOr(Schema.Array(Schema.String))),
+});
+const isMcpElicitationMetadata = Schema.is(McpElicitationMetadata);
+const isMcpElicitationForm = Schema.is(McpElicitationForm);
// TODO: Verify `packages/effect-codex-app-server/scripts/generate.ts` so the generated
// `V2TurnStartParams` schema includes `collaborationMode` directly.
@@ -231,6 +284,172 @@ interface PendingUserInput {
readonly answers: Deferred.Deferred<ProviderUserInputAnswers>;
}
+type McpElicitationPersistenceDecision = Extract<
+ ProviderApprovalDecision,
+ "acceptForSession" | "acceptAlways"
+>;
+
+function mcpElicitationPersistenceDecision(
+ value: string,
+): McpElicitationPersistenceDecision | null {
+ const normalized = value.toLowerCase();
+ if (normalized.includes("session")) return "acceptForSession";
+ if (
+ normalized.includes("always") ||
+ normalized.includes("permanent") ||
+ normalized.includes("forever") ||
+ normalized.includes("persistent")
+ ) {
+ return "acceptAlways";
+ }
+ return null;
+}
+
+function mcpElicitationFormFields(payload: EffectCodexSchema.McpServerElicitationRequestParams) {
+ if (payload.mode === "url" || !isMcpElicitationForm(payload.requestedSchema)) {
+ return undefined;
+ }
+ return payload.requestedSchema;
+}
+
+function mcpElicitationFieldOptions(field: typeof McpElicitationFormField.Type) {
+ if (field.oneOf) {
+ return field.oneOf.map((option) => ({ value: option.const, label: option.title }));
+ }
+ return (field.enum ?? []).map((value, index) => ({
+ value,
+ label: field.enumNames?.[index],
+ }));
+}
+
+function isMcpElicitationPersistenceField(
+ key: string,
+ field: typeof McpElicitationFormField.Type,
+): boolean {
+ return (
+ mcpElicitationPersistenceDecision(key) !== null ||
+ key.toLowerCase() === "persist" ||
+ mcpElicitationPersistenceDecision(field.title ?? "") !== null ||
+ mcpElicitationPersistenceDecision(field.description ?? "") !== null
+ );
+}
+
+/** Returns the app and approval choices advertised by an MCP elicitation. */
+export function describeMcpElicitation(
+ payload: EffectCodexSchema.McpServerElicitationRequestParams,
+): { readonly appName: string; readonly options: ReadonlyArray<ProviderApprovalOption> } {
+ const metadata = isMcpElicitationMetadata(payload._meta) ? payload._meta : undefined;
+ const appName =
+ metadata?.app_name ??
+ metadata?.appName ??
+ metadata?.app ??
+ metadata?.target?.app ??
+ metadata?.target?.name ??
+ metadata?.tool_params?.app_name ??
+ metadata?.tool_params?.app ??
+ payload.message.match(/^Allow ChatGPT to use (.+?)\?$/i)?.[1] ??
+ metadata?.connector_name ??
+ metadata?.connectorName ??
+ payload.serverName;
+ const persistenceOptions = new Map<McpElicitationPersistenceDecision, string>();
+ const persist = metadata?.persist;
+ for (const value of typeof persist === "string" ? [persist] : (persist ?? [])) {
+ const decision = mcpElicitationPersistenceDecision(value);
+ if (decision) persistenceOptions.set(decision, "");
+ }
+ if (metadata?.allowPersistentApproval) {
+ persistenceOptions.set("acceptAlways", "");
+ }
+
+ const form = mcpElicitationFormFields(payload);
+ for (const [key, field] of Object.entries(form?.properties ?? {})) {
+ for (const option of mcpElicitationFieldOptions(field)) {
+ const decision = mcpElicitationPersistenceDecision(option.value);
+ if (decision) persistenceOptions.set(decision, option.label ?? "");
+ }
+ if (field.type === "boolean" && isMcpElicitationPersistenceField(key, field)) {
+ persistenceOptions.set("acceptAlways", field.title ?? "");
+ }
+ }
+
+ return {
+ appName,
+ options: [
+ { decision: "cancel", label: "Cancel" },
+ { decision: "decline", label: "Decline" },
+ ...(persistenceOptions.has("acceptForSession") &&
+ toMcpElicitationResponse(payload, "acceptForSession").action === "accept"
+ ? [
+ {
+ decision: "acceptForSession" as const,
+ label: persistenceOptions.get("acceptForSession") || "Always allow this session",
+ },
+ ]
+ : []),
+ ...(persistenceOptions.has("acceptAlways") &&
+ toMcpElicitationResponse(payload, "acceptAlways").action === "accept"
+ ? [
+ {
+ decision: "acceptAlways" as const,
+ label: persistenceOptions.get("acceptAlways") || "Always allow",
+ },
+ ]
+ : []),
+ { decision: "accept", label: "Approve" },
+ ],
+ };
+}
+
+/** Converts a T3 approval decision into the MCP elicitation wire response. */
+export function toMcpElicitationResponse(
+ payload: EffectCodexSchema.McpServerElicitationRequestParams,
+ decision: ProviderApprovalDecision,
+): EffectCodexSchema.McpServerElicitationRequestResponse {
+ if (decision === "decline" || decision === "cancel") {
+ return { action: decision };
+ }
+
+ if (payload.mode === "url") {
+ return { action: "decline" };
+ }
+
+ const persist =
+ decision === "acceptForSession"
+ ? "session"
+ : decision === "acceptAlways"
+ ? "always"
+ : undefined;
+ const form = mcpElicitationFormFields(payload);
+ const content: Record<string, unknown> = {};
+
+ for (const [key, field] of Object.entries(form?.properties ?? {})) {
+ const options = mcpElicitationFieldOptions(field);
+ const chosenOption = options.find((option) =>
+ persist
+ ? mcpElicitationPersistenceDecision(option.value) === decision
+ : /once|accept|approve|allow/i.test(option.value) &&
+ mcpElicitationPersistenceDecision(option.value) === null,
+ );
+ if (chosenOption) {
+ content[key] = chosenOption.value;
+ } else if (field.type === "boolean" && isMcpElicitationPersistenceField(key, field)) {
+ content[key] = decision === "acceptAlways";
+ } else if (field.default !== undefined && field.default !== null) {
+ content[key] = field.default;
+ }
+ }
+
+ if (form?.required?.some((key) => !Object.hasOwn(content, key))) {
+ return { action: "decline" };
+ }
+
+ return {
+ action: "accept",
+ ...(persist ? { _meta: { persist } } : {}),
+ ...(form ? { content } : {}),
+ };
+}
+
type CodexServerNotification = {
readonly [M in CodexRpc.ServerNotificationMethod]: {
readonly method: M;
@@ -1544,7 +1763,7 @@ export const makeCodexSessionRuntime = (
),
);
return {
- decision: resolved,
+ decision: resolved === "acceptAlways" ? "acceptForSession" : resolved,
} satisfies EffectCodexSchema.CommandExecutionRequestApprovalResponse;
}),
);
@@ -1602,11 +1821,76 @@ export const makeCodexSessionRuntime = (
),
);
return {
- decision: resolved,
+ decision: resolved === "acceptAlways" ? "acceptForSession" : resolved,
} satisfies EffectCodexSchema.FileChangeRequestApprovalResponse;
}),
);
+ yield* client.handleServerRequest("mcpServer/elicitation/request", (payload) =>
+ Effect.gen(function* () {
+ if (toMcpElicitationResponse(payload, "accept").action !== "accept") {
+ yield* Effect.logWarning("Declined an unsupported MCP elicitation.", {
+ serverName: payload.serverName,
+ mode: payload.mode,
+ });
+ return {
+ action: "decline",
+ } satisfies EffectCodexSchema.McpServerElicitationRequestResponse;
+ }
+
+ const requestId = ApprovalRequestId.make(yield* randomUUIDv4("mcp-elicitation-request"));
+ const turnId = payload.turnId
+ ? TurnId.make(payload.turnId)
+ : (yield* Ref.get(sessionRef)).activeTurnId;
+ const jsonRpcId = payload.mode === "url" ? payload.elicitationId : requestId;
+ const decision = yield* Deferred.make<ProviderApprovalDecision>();
+
+ yield* Ref.update(pendingApprovalsRef, (current) => {
+ const next = new Map(current);
+ next.set(requestId, {
+ requestId,
+ jsonRpcId,
+ requestKind: "mcp-elicitation",
+ turnId,
+ itemId: undefined,
+ decision,
+ });
+ return next;
+ });
+ yield* Ref.update(approvalCorrelationsRef, (current) => {
+ const next = new Map(current);
+ next.set(jsonRpcId, {
+ requestId,
+ requestKind: "mcp-elicitation",
+ turnId,
+ itemId: undefined,
+ });
+ return next;
+ });
+
+ yield* emitEvent({
+ kind: "request",
+ threadId: options.threadId,
+ method: "mcpServer/elicitation/request",
+ requestId,
+ requestKind: "mcp-elicitation",
+ ...(turnId ? { turnId } : {}),
+ payload,
+ });
+
+ const resolved = yield* Deferred.await(decision).pipe(
+ Effect.ensuring(
+ Ref.update(pendingApprovalsRef, (current) => {
+ const next = new Map(current);
+ next.delete(requestId);
+ return next;
+ }),
+ ),
+ );
+ return toMcpElicitationResponse(payload, resolved);
+ }),
+ );
+
yield* client.handleServerRequest("item/tool/requestUserInput", (payload) =>
Effect.gen(function* () {
const requestId = ApprovalRequestId.make(yield* randomUUIDv4("user-input-request"));
diff --git a/apps/server/src/provider/testFixtures/codexCollabMockPeer.mjs b/apps/server/src/provider/testFixtures/codexCollabMockPeer.mjs
index f06e984c9..d3bdee367 100644
--- a/apps/server/src/provider/testFixtures/codexCollabMockPeer.mjs
+++ b/apps/server/src/provider/testFixtures/codexCollabMockPeer.mjs
@@ -17,6 +17,7 @@ const script = JSON.parse(NodeFS.readFileSync(process.env.T3_CODEX_COLLAB_SCRIPT
const write = (message) => process.stdout.write(`${JSON.stringify(message)}\n`);
let turnStartCount = 0;
+let activeTurn;
const rl = NodeReadline.createInterface({ input: process.stdin });
rl.on("line", (line) => {
@@ -27,6 +28,23 @@ rl.on("line", (line) => {
return;
}
const { id, method } = message;
+ if (method === undefined && script.serverRequests?.some((request) => request.id === id)) {
+ NodeFS.appendFileSync(
+ `${process.env.T3_CODEX_COLLAB_SCRIPT}.responses`,
+ `${JSON.stringify({ id, result: message.result, error: message.error })}\n`,
+ );
+ if (script.completeTurnOnServerResponse && activeTurn) {
+ write({
+ jsonrpc: "2.0",
+ method: "turn/completed",
+ params: {
+ threadId: script.rootThreadId,
+ turn: { ...activeTurn, status: "completed" },
+ },
+ });
+ }
+ return;
+ }
if (method === "initialize") {
write({
id,
@@ -48,6 +66,7 @@ rl.on("line", (line) => {
const turn = turnId
? { ...fixture.responses.turnStart.turn, id: turnId }
: fixture.responses.turnStart.turn;
+ activeTurn = turn;
turnStartCount += 1;
write({ id, result: { ...fixture.responses.turnStart, turn } });
const rootThreadId = script.rootThreadId;
@@ -61,6 +80,9 @@ rl.on("line", (line) => {
for (const notification of script.notifications) {
write({ jsonrpc: "2.0", method: notification.method, params: notification.params });
}
+ for (const request of script.serverRequests ?? []) {
+ write({ jsonrpc: "2.0", id: request.id, method: request.method, params: request.params });
+ }
if (script.holdTurnOpen !== true) {
write({
jsonrpc: "2.0",
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index f29d6c2b4..e854498ad 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -2872,6 +2872,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
<ComposerPendingApprovalActions
requestId={activePendingApproval.requestId}
isResponding={respondingRequestIds.includes(activePendingApproval.requestId)}
+ options={activePendingApproval.options}
onRespondToApproval={onRespondToApproval}
/>
</div>
@@ -2901,6 +2902,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
<ComposerPendingApprovalActions
requestId={activePendingApproval.requestId}
isResponding={respondingRequestIds.includes(activePendingApproval.requestId)}
+ options={activePendingApproval.options}
onRespondToApproval={onRespondToApproval}
/>
</div>
diff --git a/apps/web/src/components/chat/ComposerPendingApprovalActions.test.tsx b/apps/web/src/components/chat/ComposerPendingApprovalActions.test.tsx
index 74e25b9c8..16141270f 100644
--- a/apps/web/src/components/chat/ComposerPendingApprovalActions.test.tsx
+++ b/apps/web/src/components/chat/ComposerPendingApprovalActions.test.tsx
@@ -21,4 +21,38 @@ describe("ComposerPendingApprovalActions", () => {
expect(markup).toContain("sm:text-[11px]");
expect(markup).not.toContain("sm:h-6");
});
+
+ it("shows only the approval choices advertised by an MCP server", () => {
+ const markup = renderToStaticMarkup(
+ <ComposerPendingApprovalActions
+ requestId={ApprovalRequestId.make("approval-safari")}
+ isResponding={false}
+ options={[
+ { decision: "decline", label: "Decline" },
+ { decision: "acceptAlways", label: "Always allow Safari" },
+ { decision: "accept", label: "Approve" },
+ ]}
+ onRespondToApproval={async () => undefined}
+ />,
+ );
+
+ expect(markup).toContain("Always allow Safari");
+ expect(markup).toContain(">Approve<");
+ expect(markup).not.toContain("Always allow this session");
+ });
+
+ it("limits provider-supplied approval labels so narrow rows can wrap", () => {
+ const label = "Allow ".repeat(40).trim();
+ const markup = renderToStaticMarkup(
+ <ComposerPendingApprovalActions
+ requestId={ApprovalRequestId.make("approval-long-label")}
+ isResponding={false}
+ options={[{ decision: "acceptAlways", label }]}
+ onRespondToApproval={async () => undefined}
+ />,
+ );
+
+ expect(markup).toContain('class="max-w-40 truncate"');
+ expect(markup).toContain(label);
+ });
});
diff --git a/apps/web/src/components/chat/ComposerPendingApprovalActions.tsx b/apps/web/src/components/chat/ComposerPendingApprovalActions.tsx
index ef2bc59dd..7482f665b 100644
--- a/apps/web/src/components/chat/ComposerPendingApprovalActions.tsx
+++ b/apps/web/src/components/chat/ComposerPendingApprovalActions.tsx
@@ -1,10 +1,15 @@
-import { type ApprovalRequestId, type ProviderApprovalDecision } from "@t3tools/contracts";
+import {
+ type ApprovalRequestId,
+ type ProviderApprovalDecision,
+ type ProviderApprovalOption,
+} from "@t3tools/contracts";
import { memo } from "react";
import { Button } from "../ui/button";
interface ComposerPendingApprovalActionsProps {
requestId: ApprovalRequestId;
isResponding: boolean;
+ options?: ReadonlyArray<ProviderApprovalOption> | undefined;
onRespondToApproval: (
requestId: ApprovalRequestId,
decision: ProviderApprovalDecision,
@@ -12,50 +17,39 @@ interface ComposerPendingApprovalActionsProps {
}
const APPROVAL_ACTION_CLASS_NAME = "font-normal";
+const DEFAULT_APPROVAL_OPTIONS = [
+ { decision: "cancel", label: "Cancel" },
+ { decision: "decline", label: "Decline" },
+ { decision: "acceptForSession", label: "Always allow this session" },
+ { decision: "accept", label: "Approve" },
+] satisfies ReadonlyArray<ProviderApprovalOption>;
export const ComposerPendingApprovalActions = memo(function ComposerPendingApprovalActions({
requestId,
isResponding,
+ options = DEFAULT_APPROVAL_OPTIONS,
onRespondToApproval,
}: ComposerPendingApprovalActionsProps) {
return (
<>
- <Button
- size="micro"
- variant="ghost-muted"
- className={APPROVAL_ACTION_CLASS_NAME}
- disabled={isResponding}
- onClick={() => void onRespondToApproval(requestId, "cancel")}
- >
- Cancel
- </Button>
- <Button
- size="micro"
- variant="ghost-muted"
- className={`${APPROVAL_ACTION_CLASS_NAME} text-destructive-foreground [:hover,[data-pressed]]:text-destructive-foreground`}
- disabled={isResponding}
- onClick={() => void onRespondToApproval(requestId, "decline")}
- >
- Decline
- </Button>
- <Button
- size="micro"
- variant="ghost-muted"
- className={APPROVAL_ACTION_CLASS_NAME}
- disabled={isResponding}
- onClick={() => void onRespondToApproval(requestId, "acceptForSession")}
- >
- Always allow this session
- </Button>
- <Button
- size="micro"
- variant="ghost-muted"
- className={`${APPROVAL_ACTION_CLASS_NAME} text-foreground`}
- disabled={isResponding}
- onClick={() => void onRespondToApproval(requestId, "accept")}
- >
- Approve
- </Button>
+ {options.map((option) => (
+ <Button
+ key={option.decision}
+ size="micro"
+ variant="ghost-muted"
+ className={`${APPROVAL_ACTION_CLASS_NAME}${
+ option.decision === "decline"
+ ? " text-destructive-foreground [:hover,[data-pressed]]:text-destructive-foreground"
+ : option.decision === "accept"
+ ? " text-foreground"
+ : ""
+ }`}
+ disabled={isResponding}
+ onClick={() => void onRespondToApproval(requestId, option.decision)}
+ >
+ <span className="max-w-40 truncate">{option.label}</span>
+ </Button>
+ ))}
</>
);
});
diff --git a/apps/web/src/components/chat/ComposerPendingApprovalPanel.test.tsx b/apps/web/src/components/chat/ComposerPendingApprovalPanel.test.tsx
index 5e82298d5..a7ef6bc7d 100644
--- a/apps/web/src/components/chat/ComposerPendingApprovalPanel.test.tsx
+++ b/apps/web/src/components/chat/ComposerPendingApprovalPanel.test.tsx
@@ -50,4 +50,46 @@ describe("ComposerPendingApprovalPanel", () => {
expect(markup).toContain("File read approval");
});
+
+ it("shows the app name and message for an MCP access request", () => {
+ const markup = renderToStaticMarkup(
+ <ComposerPendingApprovalPanel
+ approval={{
+ requestId: ApprovalRequestId.make("approval-safari"),
+ requestKind: "mcp-elicitation",
+ createdAt: "2026-08-24T00:00:00.000Z",
+ appName: "Safari",
+ detail: "Allow ChatGPT to use Safari?",
+ }}
+ pendingCount={1}
+ />,
+ );
+
+ expect(markup).toContain('aria-label="App access approval"');
+ expect(markup).toContain('aria-label="App access request"');
+ expect(markup).toContain(">Safari<");
+ expect(markup).toContain("Allow ChatGPT to use Safari?");
+ });
+
+ it("limits long app names so the complete approval message stays readable", () => {
+ const appName = "A".repeat(200);
+ const detail = "Allow ChatGPT to access the selected application?";
+ const markup = renderToStaticMarkup(
+ <ComposerPendingApprovalPanel
+ approval={{
+ requestId: ApprovalRequestId.make("approval-long-app-name"),
+ requestKind: "mcp-elicitation",
+ createdAt: "2026-08-24T00:00:00.000Z",
+ appName,
+ detail,
+ }}
+ pendingCount={1}
+ />,
+ );
+
+ expect(markup).toContain("max-w-32 shrink truncate");
+ expect(markup).toContain(appName);
+ expect(markup).toContain('data-approval-detail="complete"');
+ expect(markup).toContain(detail);
+ });
});
diff --git a/apps/web/src/components/chat/ComposerPendingApprovalPanel.tsx b/apps/web/src/components/chat/ComposerPendingApprovalPanel.tsx
index d73f0f16b..5c6aedb04 100644
--- a/apps/web/src/components/chat/ComposerPendingApprovalPanel.tsx
+++ b/apps/web/src/components/chat/ComposerPendingApprovalPanel.tsx
@@ -14,17 +14,21 @@ export const ComposerPendingApprovalPanel = memo(function ComposerPendingApprova
className,
}: ComposerPendingApprovalPanelProps) {
const fallbackLabel =
- approval.requestKind === "command"
- ? "Command approval"
- : approval.requestKind === "file-read"
- ? "File read approval"
- : "File change approval";
+ approval.requestKind === "mcp-elicitation"
+ ? "App access approval"
+ : approval.requestKind === "command"
+ ? "Command approval"
+ : approval.requestKind === "file-read"
+ ? "File read approval"
+ : "File change approval";
const detailAriaLabel =
- approval.requestKind === "command"
- ? "Command"
- : approval.requestKind === "file-read"
- ? "File to read"
- : "File change";
+ approval.requestKind === "mcp-elicitation"
+ ? "App access request"
+ : approval.requestKind === "command"
+ ? "Command"
+ : approval.requestKind === "file-read"
+ ? "File to read"
+ : "File change";
return (
<div
@@ -32,6 +36,11 @@ export const ComposerPendingApprovalPanel = memo(function ComposerPendingApprova
className={cn("flex min-w-0 flex-1 items-center gap-2", className)}
role="group"
>
+ {approval.appName ? (
+ <span className="max-w-32 shrink truncate text-[11px] font-medium text-foreground">
+ {approval.appName}
+ </span>
+ ) : null}
<code
aria-label={detailAriaLabel}
className="block max-h-20 min-w-0 flex-1 overflow-auto whitespace-pre font-mono text-[11px] text-foreground/85 [scrollbar-width:thin] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70 [&::-webkit-scrollbar]:h-1.5"
diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.ts
index afabd47d4..0c07e53db 100644
--- a/apps/web/src/session-logic.test.ts
+++ b/apps/web/src/session-logic.test.ts
@@ -130,6 +130,39 @@ describe("derivePendingApprovals", () => {
]);
});
+ it("keeps app access approvals and persistence choices from remote activities", () => {
+ const options = [
+ { decision: "decline", label: "Decline" },
+ { decision: "acceptAlways", label: "Always allow Safari" },
+ { decision: "accept", label: "Approve" },
+ ];
+ const activities = [
+ makeActivity({
+ kind: "approval.requested",
+ summary: "App access approval requested",
+ tone: "approval",
+ payload: {
+ requestId: "req-safari",
+ requestType: "mcp_elicitation_approval",
+ detail: "Allow ChatGPT to use Safari?",
+ appName: "Safari",
+ options,
+ },
+ }),
+ ];
+
+ expect(derivePendingApprovals(activities)).toEqual([
+ {
+ requestId: "req-safari",
+ requestKind: "mcp-elicitation",
+ createdAt: "2026-02-23T00:00:00.000Z",
+ detail: "Allow ChatGPT to use Safari?",
+ appName: "Safari",
+ options,
+ },
+ ]);
+ });
+
it("derives dynamic tool requests as actionable generic approvals", () => {
const activities: OrchestrationThreadActivity[] = [
makeActivity({
diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts
index ff06ad57d..59165ec6b 100644
--- a/apps/web/src/session-logic.ts
+++ b/apps/web/src/session-logic.ts
@@ -1,5 +1,6 @@
import * as Option from "effect/Option";
import * as Arr from "effect/Array";
+import * as Schema from "effect/Schema";
import { isBackgroundTaskActivity } from "@t3tools/client-runtime/state/subagentRuntime";
import {
ApprovalRequestId,
@@ -8,6 +9,8 @@ import {
type OrchestrationThreadActivity,
type OrchestrationProposedPlanId,
ProviderDriverKind,
+ ProviderApprovalOption,
+ ProviderRequestKind,
type ToolLifecycleItemType,
type UserInputQuestion,
type ThreadId,
@@ -116,11 +119,16 @@ const derivedWorkLogEntryByActivity = new WeakMap<
export interface PendingApproval {
requestId: ApprovalRequestId;
- requestKind: "command" | "file-read" | "file-change";
+ requestKind: ProviderRequestKind;
createdAt: string;
detail?: string;
+ appName?: string;
+ options?: ReadonlyArray<ProviderApprovalOption>;
}
+const isProviderRequestKind = Schema.is(ProviderRequestKind);
+const isProviderApprovalOption = Schema.is(ProviderApprovalOption);
+
export interface PendingUserInput {
requestId: ApprovalRequestId;
createdAt: string;
@@ -385,6 +393,8 @@ function requestKindFromRequestType(requestType: unknown): PendingApproval["requ
case "file_change_approval":
case "apply_patch_approval":
return "file-change";
+ case "mcp_elicitation_approval":
+ return "mcp-elicitation";
default:
return null;
}
@@ -422,15 +432,16 @@ export function derivePendingApprovals(
? ApprovalRequestId.make(payload.requestId)
: null;
const requestKind =
- payload &&
- (payload.requestKind === "command" ||
- payload.requestKind === "file-read" ||
- payload.requestKind === "file-change")
+ payload && isProviderRequestKind(payload.requestKind)
? payload.requestKind
: payload
? requestKindFromRequestType(payload.requestType)
: null;
const detail = payload && typeof payload.detail === "string" ? payload.detail : undefined;
+ const appName = payload && typeof payload.appName === "string" ? payload.appName : undefined;
+ const options = Array.isArray(payload?.options)
+ ? payload.options.filter(isProviderApprovalOption)
+ : undefined;
if (activity.kind === "approval.requested" && requestId && requestKind) {
openByRequestId.set(requestId, {
@@ -438,6 +449,8 @@ export function derivePendingApprovals(
requestKind,
createdAt: activity.createdAt,
...(detail ? { detail } : {}),
+ ...(appName ? { appName } : {}),
+ ...(options && options.length > 0 ? { options } : {}),
});
continue;
}
diff --git a/docs/user/providers-codex.md b/docs/user/providers-codex.md
index 2396ce402..f696e8877 100644
--- a/docs/user/providers-codex.md
+++ b/docs/user/providers-codex.md
@@ -34,6 +34,12 @@ In an existing Codex thread, send `/feedback` or `/feedback` followed by a descr
issue. T3 Code uploads the thread and Codex logs to OpenAI and shows a thread ID that you can copy
and share with OpenAI employees.
+## Approve access to other apps
+
+When a Codex tool needs access to an app such as Safari, T3 Code shows the app name and asks for
+approval. You can approve, decline, or cancel the request from the desktop app, web app, or mobile
+app. Some tools also offer approval for the current session or permanent approval.
+
## I Want Work And Personal Codex Accounts
Use one real Codex home and one shadow home.
diff --git a/packages/contracts/src/orchestration.ts b/packages/contracts/src/orchestration.ts
index 1c27e6d3c..2535616d4 100644
--- a/packages/contracts/src/orchestration.ts
+++ b/packages/contracts/src/orchestration.ts
@@ -128,17 +128,28 @@ export const DEFAULT_RUNTIME_MODE: RuntimeMode = "full-access";
export const ProviderInteractionMode = Schema.Literals(["default", "plan"]);
export type ProviderInteractionMode = typeof ProviderInteractionMode.Type;
export const DEFAULT_PROVIDER_INTERACTION_MODE: ProviderInteractionMode = "default";
-export const ProviderRequestKind = Schema.Literals(["command", "file-read", "file-change"]);
+export const ProviderRequestKind = Schema.Literals([
+ "command",
+ "file-read",
+ "file-change",
+ "mcp-elicitation",
+]);
export type ProviderRequestKind = typeof ProviderRequestKind.Type;
export const AssistantDeliveryMode = Schema.Literals(["buffered", "streaming"]);
export type AssistantDeliveryMode = typeof AssistantDeliveryMode.Type;
export const ProviderApprovalDecision = Schema.Literals([
"accept",
"acceptForSession",
+ "acceptAlways",
"decline",
"cancel",
]);
export type ProviderApprovalDecision = typeof ProviderApprovalDecision.Type;
+export const ProviderApprovalOption = Schema.Struct({
+ decision: ProviderApprovalDecision,
+ label: TrimmedNonEmptyString,
+});
+export type ProviderApprovalOption = typeof ProviderApprovalOption.Type;
export const ProviderUserInputAnswers = Schema.Record(Schema.String, Schema.Unknown);
export type ProviderUserInputAnswers = typeof ProviderUserInputAnswers.Type;
diff --git a/packages/contracts/src/providerRuntime.ts b/packages/contracts/src/providerRuntime.ts
index bd525e654..a734c797b 100644
--- a/packages/contracts/src/providerRuntime.ts
+++ b/packages/contracts/src/providerRuntime.ts
@@ -14,6 +14,7 @@ import {
TurnId,
} from "./baseSchemas.ts";
import { ProviderInstanceId, ProviderDriverKind } from "./providerInstance.ts";
+import { ProviderApprovalOption } from "./orchestration.ts";
const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString;
const UnknownRecordSchema = Schema.Record(Schema.String, Schema.Unknown);
@@ -138,6 +139,7 @@ export const CanonicalRequestType = Schema.Literals([
"file_change_approval",
"apply_patch_approval",
"exec_command_approval",
+ "mcp_elicitation_approval",
"tool_user_input",
"dynamic_tool_call",
"auth_tokens_refresh",
@@ -430,6 +432,8 @@ export type ContentDeltaPayload = typeof ContentDeltaPayload.Type;
const RequestOpenedPayload = Schema.Struct({
requestType: CanonicalRequestType,
detail: Schema.optional(TrimmedNonEmptyStringSchema),
+ appName: Schema.optional(TrimmedNonEmptyStringSchema),
+ options: Schema.optional(Schema.Array(ProviderApprovalOption)),
args: Schema.optional(Schema.Unknown),
});
export type RequestOpenedPayload = typeof RequestOpenedPayload.Type;
diff --git a/packages/effect-codex-app-server/src/errors.ts b/packages/effect-codex-app-server/src/errors.ts
index f0e0945d3..3803b4d40 100644
--- a/packages/effect-codex-app-server/src/errors.ts
+++ b/packages/effect-codex-app-server/src/errors.ts
@@ -118,6 +118,7 @@ export const CodexAppServerIdentifierPurpose = Schema.Literals([
"provider-event",
"command-approval-request",
"file-change-approval-request",
+ "mcp-elicitation-request",
"user-input-request",
]);
export type CodexAppServerIdentifierPurpose = typeof CodexAppServerIdentifierPurpose.Type;