From 335e7e2fdfc0daa8dfee7f6814c06f99678c25be Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Thu, 22 Oct 2026 21:15:41 +0000 Subject: [PATCH 1/9] fix(server): show MCP app forms when a write tool defers to them A write tool that defers to its MCP App form returns an `isError` result, which Codex reports as a failed call. T3 only captured and showed apps for completed calls, so the form never appeared and the write never happened. Capture the app whenever the call has a result, pass `isError` on to the app, and let web and mobile show the app for failed calls too. Closes #23825 Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/lib/threadActivity.ts | 5 +- .../Adapters/CodexAdapterV2.test.ts | 69 +++++++++++++++++++ .../Adapters/CodexAdapterV2.ts | 12 +++- apps/web/src/session-logic.test.ts | 17 +++++ apps/web/src/session-logic.ts | 5 +- 5 files changed, 98 insertions(+), 10 deletions(-) diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.ts index 1e942fc8ca762..dd364245e76f0 100644 --- a/apps/mobile/src/lib/threadActivity.ts +++ b/apps/mobile/src/lib/threadActivity.ts @@ -2114,10 +2114,7 @@ export function buildThreadFeed( entryRows.push(index); continue; } - const app = - item.type === "dynamic_tool" && item.status === "completed" - ? mcpAppFromToolItem(item) - : undefined; + const app = item.type === "dynamic_tool" ? mcpAppFromToolItem(item) : undefined; if (app) { const entry: RawThreadFeedEntry = { type: "mcp-app", diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts index 840205edfa619..44e6f8d7a3384 100644 --- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts @@ -4500,6 +4500,75 @@ describe("CodexAdapterV2 post-settle continuation", () => { ), ); + const MCP_APP_DEFERRED_RESULT = { + content: [{ type: "text", text: "An interactive form is being shown to the user." }], + structuredContent: { status: "awaiting_user_submission" }, + }; + // Codex reports a tool's `isError` result, which a write that defers to its + // form returns, as a failed call. + const mcpAppDeferredTranscript = makeCodexReplayTranscript({ + scenario: MCP_APP_SCENARIO, + entries: mcpAppTranscript.entries.map((entry) => + entry.type === "emit_inbound" && entry.label === "item/completed/app-tool" + ? { + ...entry, + frame: { + method: "item/completed", + params: { + item: { + ...mcpAppToolItem("inProgress"), + status: "failed", + result: MCP_APP_DEFERRED_RESULT, + }, + threadId: MCP_APP_NATIVE_THREAD, + turnId: MCP_APP_NATIVE_TURN, + completedAtMs: 1782622441500, + }, + }, + } + : entry, + ), + }); + + it.effect("captures the app of a tool call that defers to its form", () => + Effect.scoped( + Effect.gen(function* () { + const appCaptured = yield* Deferred.make(); + const harness = yield* makeCodexReplayHarness(mcpAppDeferredTranscript, (event) => + event.type === "turn_item.updated" && + event.turnItem.type === "dynamic_tool" && + event.turnItem.status === "failed" + ? Deferred.succeed(appCaptured, event.turnItem) + : Effect.void, + ); + const now = yield* DateTime.now; + + yield* harness.runtime.startTurn( + makeCodexTestTurnInput({ + threadId: harness.threadId, + providerThread: harness.providerThread, + now, + attemptId: RunAttemptId.make("attempt-codex-mcp-app-deferred"), + text: MCP_APP_PROMPT, + }), + ); + const item = yield* Deferred.await(appCaptured); + + const output = item.type === "dynamic_tool" ? (item.output as Record) : {}; + assert.equal( + readMcpAppReference(output[MCP_APP_OUTPUT_KEY])?.resourceUri, + MCP_APP_RESOURCE, + ); + assert.deepEqual(output.result, { ...MCP_APP_DEFERRED_RESULT, isError: true }); + assert.isFalse(yield* harness.hasPendingBackgroundWork); + }).pipe( + Effect.provide( + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer), + ), + ), + ), + ); + const ORPHAN_WAIT_SCENARIO = "codex-orphaned-dynamic-tool"; const ORPHAN_WAIT_NATIVE_THREAD = "native-codex-orphan-wait-thread"; const ORPHAN_WAIT_NATIVE_TURN = "native-codex-orphan-wait-turn"; diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts index 067551ff9a912..abaa4fbab060b 100644 --- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts @@ -3816,8 +3816,10 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* ( // item, removes it, so no stored app goes unreferenced. Effect.uninterruptibleMask((restore) => Effect.gen(function* () { + // Codex reports an `isError` result as failed. Apps still render + // for it: a write tool that defers to its form returns one. const reference = - item.status === "completed" && item.result != null && item.error == null + item.result != null && item.error == null ? yield* restore( getNativeThreadId(context.providerThread).pipe( Effect.flatMap((threadId) => @@ -3875,7 +3877,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* ( ? artifacts.turnItem : { ...artifacts.turnItem, - output: { [MCP_APP_OUTPUT_KEY]: reference, result: item.result }, + output: { + [MCP_APP_OUTPUT_KEY]: reference, + result: + item.status === "failed" + ? { ...item.result, isError: true } + : item.result, + }, }; yield* emitProviderEvent({ type: "node.updated", diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.ts index de8b3373e44b2..c4344c24238d2 100644 --- a/apps/web/src/session-logic.test.ts +++ b/apps/web/src/session-logic.test.ts @@ -1487,6 +1487,23 @@ describe("HTML renders in the timeline", () => { expect(rowsFor(entries, false)).toEqual(["message", "turn-fold", "mcp-app", "message"]); }); + it("hosts an MCP app whose call failed, as a form-deferring write does", () => { + const mcpApp = { + attachmentId: "render-thread-app-html", + server: "github", + tool: "create_pull_request", + resourceUri: "ui://github-mcp-server/pr-create", + }; + const call = renderCall("failed", { + t3McpApp: mcpApp, + result: { content: [], isError: true }, + }); + const entries = turn( + call.type === "dynamic_tool" ? { ...call, toolName: "github.create_pull_request" } : call, + ); + expect(entries.find((entry) => entry.kind === "mcp-app")).toMatchObject({ mcpApp }); + }); + it("keeps a render visible when its superseded attempt folds", () => { const attempt: OrchestrationV2RunAttempt = { id: RunAttemptId.make("attempt-superseded"), diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts index b504606b4d5e1..c99bd4ffde45b 100644 --- a/apps/web/src/session-logic.ts +++ b/apps/web/src/session-logic.ts @@ -771,10 +771,7 @@ export function deriveTimelineEntriesFromVisibleTurnItems( continue; } - const mcpApp = - item.type === "dynamic_tool" && item.status === "completed" - ? mcpAppFromToolItem(item) - : undefined; + const mcpApp = item.type === "dynamic_tool" ? mcpAppFromToolItem(item) : undefined; if (mcpApp !== undefined) { entries.push({ id: item.id, From 0dc488beba57174b927d34675d8d02cde0f73686 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Fri, 23 Oct 2026 18:52:45 +0000 Subject: [PATCH 2/9] fix(server): a submitted MCP App form no longer comes back empty An MCP App's tool call keeps the result it first returned. For a form that deferred a write, that is "form shown, nothing created yet", so the form came back empty after a reload or on another device, even though the write had gone through. When an app writes through its own tool and it succeeds, the server now records that call on the tool call that shows the app, as an internal orchestration command. Web and mobile open the app on the recorded call when there is one. Reads aren't recorded, since apps can repeat them without asking. Refs #23825 Co-Authored-By: Claude Opus 5.5 --- .../src/features/threads/McpAppWebView.tsx | 8 +- .../server/src/mcpApps/McpAppRequests.test.ts | 64 +++++++++++++- apps/server/src/mcpApps/McpAppRequests.ts | 27 +++++- .../Orchestrator.control-reads.test.ts | 88 +++++++++++++++++++ .../src/orchestration-v2/Orchestrator.ts | 48 ++++++++++ apps/web/src/components/chat/McpAppFrame.tsx | 11 ++- packages/contracts/src/orchestrationV2.ts | 13 +++ packages/shared/src/mcpApp.test.ts | 22 +++++ packages/shared/src/mcpApp.ts | 17 ++++ 9 files changed, 286 insertions(+), 12 deletions(-) diff --git a/apps/mobile/src/features/threads/McpAppWebView.tsx b/apps/mobile/src/features/threads/McpAppWebView.tsx index 601ee7fc8a42d..2457cc576e27d 100644 --- a/apps/mobile/src/features/threads/McpAppWebView.tsx +++ b/apps/mobile/src/features/threads/McpAppWebView.tsx @@ -18,6 +18,7 @@ import { mcpAppAllowAttribute, mcpAppFileName, mcpAppReferencesEqual, + mcpAppToolCall, type McpAppReference, } from "@t3tools/shared/mcpApp"; import * as Predicate from "effect/Predicate"; @@ -195,10 +196,9 @@ export function ThreadMcpApp(props: { const storedItem = detail.data?.item; const toolCall = useMemo(() => { if (storedItem?.type !== "dynamic_tool") return undefined; - const output = storedItem.output as { readonly result?: unknown } | undefined; - return { - arguments: storedItem.input, - result: output?.result as McpAppCallToolResult | undefined, + return mcpAppToolCall(storedItem) as { + readonly arguments: unknown; + readonly result: McpAppCallToolResult | undefined; }; }, [storedItem]); diff --git a/apps/server/src/mcpApps/McpAppRequests.test.ts b/apps/server/src/mcpApps/McpAppRequests.test.ts index 1fde091c06423..cd29e25e65ee5 100644 --- a/apps/server/src/mcpApps/McpAppRequests.test.ts +++ b/apps/server/src/mcpApps/McpAppRequests.test.ts @@ -1,4 +1,5 @@ import { + type OrchestrationV2ServerCommand, ProviderSessionId, ProviderThreadId, ThreadId, @@ -7,6 +8,7 @@ import { type OrchestrationV2ProviderThread, type OrchestrationV2TurnItem, } from "@t3tools/contracts"; +import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; import { assert, describe, it } from "@effect/vitest"; import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; @@ -63,15 +65,18 @@ const app = { }; const storedContext = new Map(); +const dispatched: Array = []; function makeLayer(input: { readonly item: OrchestrationV2TurnItem | null; readonly mcpApps?: ProviderAdapter.ProviderAdapterV2McpApps; readonly live?: boolean; + readonly recordFails?: boolean; }) { return McpAppRequests.layer.pipe( Layer.provide( Layer.mergeAll( + NodeCrypto.layer, Layer.mock(McpAppModelContext.McpAppModelContext)({ set: (entry) => Effect.sync(() => { @@ -84,6 +89,13 @@ function makeLayer(input: { getTurnItem: () => Effect.succeed(input.item), }), Layer.mock(ThreadManagementService.ThreadManagementService)({ + dispatch: (command) => + input.recordFails === true + ? Effect.fail(new Orchestrator.OrchestratorProjectionError({ threadId })) + : Effect.sync(() => { + dispatched.push(command); + return {} as never; + }), getThreadRecords: (id: ThreadId) => Effect.succeed({ thread: { @@ -139,11 +151,15 @@ describe("McpAppRequests", () => { Effect.succeed([ { name: "refresh", annotations: { readOnlyHint: true } }, { name: "model_only", _meta: { ui: { visibility: ["model"] } } }, + { name: "get_weather" }, + { name: "set_alert" }, ]), callTool: (input) => Effect.sync(() => { calls.push({ server: input.server, tool: input.tool }); - return { content: [{ type: "text", text: "ok" }] }; + return input.arguments.fail === true + ? { content: [{ type: "text", text: "no" }], isError: true } + : { content: [{ type: "text", text: "ok" }] }; }), readResource: () => Effect.succeed({ contents: [] }), }; @@ -167,6 +183,52 @@ describe("McpAppRequests", () => { }).pipe(Effect.provide(makeLayer({ item: appItem({ t3McpApp: app }), mcpApps }))), ); + it.effect("keeps the app's writes through its own tool on the tool call", () => + Effect.gen(function* () { + const requests = yield* McpAppRequests.McpAppRequests; + const before = dispatched.length; + const call = (name: string, args: Record) => + requests.callTool({ threadId, itemId, name, arguments: args }); + yield* call("get_weather", { city: "Paris", _ui_submitted: true }); + // Reads, other tools and failed writes leave the call as it was. + yield* call("refresh", {}); + yield* call("set_alert", {}); + yield* call("get_weather", { fail: true }); + assert.deepEqual( + dispatched.slice(before).map((command) => + command.type === "mcp_app.call.record" + ? { + threadId: command.threadId, + turnItemId: command.turnItemId, + arguments: command.arguments, + result: command.result, + } + : command.type, + ), + [ + { + threadId, + turnItemId: itemId, + arguments: { city: "Paris", _ui_submitted: true }, + result: { content: [{ type: "text", text: "ok" }] }, + }, + ], + ); + }).pipe(Effect.provide(makeLayer({ item: appItem({ t3McpApp: app }), mcpApps }))), + ); + + it.effect("returns a write's result even when it can't be recorded", () => + Effect.gen(function* () { + const requests = yield* McpAppRequests.McpAppRequests; + assert.deepEqual( + yield* requests.callTool({ threadId, itemId, name: "get_weather", arguments: {} }), + { content: [{ type: "text", text: "ok" }] }, + ); + }).pipe( + Effect.provide(makeLayer({ item: appItem({ t3McpApp: app }), mcpApps, recordFails: true })), + ), + ); + it.effect("refuses tools hidden from apps or missing from the server", () => Effect.gen(function* () { const requests = yield* McpAppRequests.McpAppRequests; diff --git a/apps/server/src/mcpApps/McpAppRequests.ts b/apps/server/src/mcpApps/McpAppRequests.ts index 6e97a726a021b..9363506ab7ff2 100644 --- a/apps/server/src/mcpApps/McpAppRequests.ts +++ b/apps/server/src/mcpApps/McpAppRequests.ts @@ -1,4 +1,5 @@ import { + CommandId, McpAppRequestError, type McpAppCallToolInput, type McpAppCallToolResult, @@ -14,6 +15,7 @@ import { import { mcpAppToolCallableByApp, type McpAppReference } from "@t3tools/shared/mcpApp"; import { mcpAppFromToolItem } from "@t3tools/shared/toolOutput"; import * as Context from "effect/Context"; +import * as Crypto from "effect/Crypto"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; @@ -64,6 +66,7 @@ const make = Effect.gen(function* () { const threadManagement = yield* ThreadManagementService.ThreadManagementService; const providerSessions = yield* ProviderSessionManager.ProviderSessionManagerV2; const modelContext = yield* McpAppModelContext.McpAppModelContext; + const crypto = yield* Crypto.Crypto; const fail = (threadId: ThreadId, reason: McpAppRequestError["reason"], cause?: unknown) => new McpAppRequestError({ threadId, reason, ...(cause === undefined ? {} : { cause }) }); @@ -139,7 +142,7 @@ const make = Effect.gen(function* () { if (tool === undefined || !mcpAppToolCallableByApp(tool._meta)) { return yield* fail(input.threadId, "tool-not-callable"); } - return yield* resolved.mcpApps + const result = yield* resolved.mcpApps .callTool({ providerThread: resolved.providerThread, server: resolved.app.server, @@ -147,6 +150,28 @@ const make = Effect.gen(function* () { arguments: input.arguments, }) .pipe(Effect.mapError((cause) => fail(input.threadId, "request-failed", cause))); + // A write through the app's own tool, such as a deferred form's submit, is + // kept so the app opens on its outcome. Reads are left out: an app can + // repeat those unprompted. + if (input.name === resolved.app.tool && !readOnlyHint(tool) && result.isError !== true) { + const uuid = yield* crypto.randomUUIDv4().pipe(Effect.orDie); + yield* threadManagement + .dispatch({ + type: "mcp_app.call.record", + commandId: CommandId.make(`server:mcp-app-call:${input.itemId}:${uuid}`), + threadId: input.threadId, + turnItemId: input.itemId, + arguments: input.arguments, + result, + }) + .pipe( + // The write already happened; failing the call would offer it again. + Effect.catch((cause) => + Effect.logWarning("Could not record an MCP App's tool call", { cause }), + ), + ); + } + return result; }); const readResource = Effect.fn("McpAppRequests.readResource")(function* ( diff --git a/apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts b/apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts index eda76857a9efe..be47df2ed6fc6 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts @@ -1231,3 +1231,91 @@ it.effect("explicit settle clears snooze atomically and stays idempotent after r assert.deepInclude((yield* projections.getThreadProjection(threadId)).thread, active); }).pipe(Effect.provide(layerTest)), ); + +it.effect("keeps an MCP App's recorded call beside the tool's own result", () => + Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const projections = yield* ProjectionStore.ProjectionStoreV2; + const threadId = ThreadId.make("thread:mcp-app-call"); + const now = yield* DateTime.now; + yield* orchestrator.dispatch({ + type: "thread.create", + commandId: CommandId.make("create-mcp-app-call"), + threadId, + projectId: ProjectId.make("project:mcp-app-call"), + title: "MCP App call", + modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + createdBy: "user", + creationSource: "web", + }); + const deferred = { content: [{ type: "text", text: "Form shown" }], isError: true }; + const toolItem = (id: TurnItemId, output: unknown) => ({ + id, + threadId, + runId: null, + nodeId: null, + providerThreadId: null, + providerTurnId: null, + nativeItemRef: null, + parentItemId: null, + ordinal: 0, + status: "failed" as const, + title: null, + startedAt: now, + completedAt: now, + updatedAt: now, + type: "dynamic_tool" as const, + toolName: "github.issue_write", + input: { title: "Draft" }, + output, + }); + const appItemId = TurnItemId.make("turn-item:mcp-app-call:app"); + const plainItemId = TurnItemId.make("turn-item:mcp-app-call:plain"); + for (const item of [ + toolItem(appItemId, { + t3McpApp: { + attachmentId: "thread-mcp-app-call-html", + server: "github", + tool: "issue_write", + resourceUri: "ui://github/issue-write", + }, + result: deferred, + }), + toolItem(plainItemId, { result: deferred }), + ]) { + yield* projections.apply({ + id: EventId.make(`mcp-app-call:${item.id}`), + type: "turn-item.updated", + threadId, + occurredAt: now, + payload: item, + }); + } + const submitted = { + arguments: { title: "Shipped", _ui_submitted: true }, + result: { content: [{ type: "text", text: "Created issue #1" }] }, + }; + const record = (turnItemId: TurnItemId) => + orchestrator.dispatch({ + type: "mcp_app.call.record", + commandId: CommandId.make(`record:${turnItemId}`), + threadId, + turnItemId, + ...submitted, + }); + + // Clients refetch an item's detail when its update time moves. + yield* TestClock.adjust("1 second"); + yield* record(appItemId); + const recorded = yield* projections.getTurnItem({ threadId, itemId: appItemId }); + assert(recorded?.type === "dynamic_tool"); + assert.deepInclude(recorded.output, { result: deferred, t3McpAppCall: submitted }); + assert.isTrue(DateTime.isGreaterThan(recorded.updatedAt, now)); + // Only a call that shows an app has an app to keep a call for. + assert.isTrue(Result.isFailure(yield* record(plainItemId).pipe(Effect.result))); + }).pipe(Effect.provide(layerTest)), +); diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index 8c8620088fa94..2e9bc2681f68b 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -63,7 +63,9 @@ import { ThreadId, type TurnItemId, } from "@t3tools/contracts"; +import { MCP_APP_CALL_OUTPUT_KEY } from "@t3tools/shared/mcpApp"; import { modelSelectionsEqual } from "@t3tools/shared/model"; +import { mcpAppFromToolItem } from "@t3tools/shared/toolOutput"; import { derivePendingBackgroundWork, pendingBackgroundTurnItems, @@ -74,6 +76,7 @@ import * as Effect from "effect/Effect"; import * as Exit from "effect/Exit"; import * as FileSystem from "effect/FileSystem"; import * as Path from "effect/Path"; +import * as Predicate from "effect/Predicate"; import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; import * as Ref from "effect/Ref"; @@ -497,6 +500,7 @@ function commandThreadId(command: OrchestrationV2ServerCommand): ThreadId { case "thread.created.record": return command.parentThreadId; case "secret_request.record": + case "mcp_app.call.record": return command.threadId; case "thread.fork": case "thread.merge_back": @@ -7634,6 +7638,47 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio }, ); + const dispatchMcpAppCallRecord = Effect.fn("orchestrationV2.dispatch.mcpAppCallRecord")( + function* ( + command: Extract, + events: Ref.Ref>, + ) { + const item = yield* projectionStore + .getTurnItem({ threadId: command.threadId, itemId: command.turnItemId }) + .pipe( + Effect.mapError( + (cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }), + ), + ); + if (item?.type !== "dynamic_tool" || mcpAppFromToolItem(item) === undefined) { + return yield* new OrchestratorDispatchError({ + commandId: command.commandId, + commandType: command.type, + cause: `Turn item ${command.turnItemId} does not show an MCP App.`, + }); + } + const now = yield* DateTime.now; + yield* emit( + events, + command, + )({ + type: "turn-item.updated", + threadId: command.threadId, + ...(item.runId === null ? {} : { runId: item.runId }), + ...(item.nodeId === null ? {} : { nodeId: item.nodeId }), + occurredAt: now, + payload: { + ...item, + output: { + ...(Predicate.isObject(item.output) ? item.output : {}), + [MCP_APP_CALL_OUTPUT_KEY]: { arguments: command.arguments, result: command.result }, + }, + updatedAt: now, + }, + }); + }, + ); + const dispatchRuntimeRequestRespond = Effect.fn("Orchestrator.dispatchRuntimeRequestRespond")( function* ( command: Extract, @@ -11559,6 +11604,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio case "secret_request.record": yield* dispatchSecretRequestRecord(command, events); break; + case "mcp_app.call.record": + yield* dispatchMcpAppCallRecord(command, events); + break; default: return yield* dispatchUnsupported(command); } diff --git a/apps/web/src/components/chat/McpAppFrame.tsx b/apps/web/src/components/chat/McpAppFrame.tsx index ff54f21960a2a..ca4b552c19995 100644 --- a/apps/web/src/components/chat/McpAppFrame.tsx +++ b/apps/web/src/components/chat/McpAppFrame.tsx @@ -16,6 +16,7 @@ import { MCP_APP_MAX_HEIGHT, mcpAppAllowAttribute, mcpAppFileName, + mcpAppToolCall, type McpAppReference, } from "@t3tools/shared/mcpApp"; import { Minimize2Icon } from "lucide-react"; @@ -135,12 +136,10 @@ export function McpAppFrame(props: { // The host gets the tool call pushed by an effect keyed on it, so it must stay cached. const toolCall = storedItem?.type === "dynamic_tool" - ? { - arguments: storedItem.input, - result: (storedItem.output as { readonly result?: unknown } | undefined)?.result as - | McpAppCallToolResult - | undefined, - } + ? (mcpAppToolCall(storedItem) as { + readonly arguments: unknown; + readonly result: McpAppCallToolResult | undefined; + }) : undefined; const callTool = useAtomCommand(mcpAppEnvironment.callTool, { reportFailure: false }); diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index 881a316f59ae1..1881d414a77fa 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -37,6 +37,7 @@ import { TurnItemId, } from "./baseSchemas.ts"; import { ChatAttachment } from "./chatAttachment.ts"; +import { McpAppCallToolResult } from "./mcpApps.ts"; import { OrchestrationGetFullThreadDiffInput, OrchestrationGetFullThreadDiffResult, @@ -3078,6 +3079,18 @@ const OrchestrationV2InternalCommand = Schema.Union([ placeholder: Schema.optional(Schema.String), secretStatus: OrchestrationV2SecretRequestStatus, }), + /** + * An MCP App's write through its own tool, kept on the tool call that shows + * the app. Internal so no client can rewrite what a tool returned. + */ + Schema.Struct({ + type: Schema.Literal("mcp_app.call.record"), + commandId: CommandId, + threadId: ThreadId, + turnItemId: TurnItemId, + arguments: Schema.Record(Schema.String, Schema.Unknown), + result: McpAppCallToolResult, + }), ]); export type OrchestrationV2InternalCommand = typeof OrchestrationV2InternalCommand.Type; diff --git a/packages/shared/src/mcpApp.test.ts b/packages/shared/src/mcpApp.test.ts index 7ed3b9a83b112..69cafd5651c49 100644 --- a/packages/shared/src/mcpApp.test.ts +++ b/packages/shared/src/mcpApp.test.ts @@ -6,6 +6,7 @@ import { injectMcpAppThemeBootstrap, injectMcpAppCookieBootstrap, mcpAppContentSecurityPolicy, + mcpAppToolCall, mcpAppToolCallableByApp, readMcpAppCsp, readMcpAppReference, @@ -261,3 +262,24 @@ describe("MCP App cookie bootstrap", () => { expect(() => Reflect.get(document, "cookie")).toThrow(failure); }); }); + +describe("mcpAppToolCall", () => { + const deferred = { content: [], isError: true }; + const submitted = { arguments: { title: "Shipped" }, result: { content: [] } }; + + it("opens the app on its recorded write, or else on the call that showed it", () => { + expect( + mcpAppToolCall({ + input: { title: "Draft" }, + output: { result: deferred, t3McpAppCall: submitted }, + }), + ).toEqual(submitted); + expect(mcpAppToolCall({ input: { title: "Draft" }, output: { result: deferred } })).toEqual({ + arguments: { title: "Draft" }, + result: deferred, + }); + expect( + mcpAppToolCall({ input: {}, output: { result: deferred, t3McpAppCall: { arguments: {} } } }), + ).toEqual({ arguments: {}, result: deferred }); + }); +}); diff --git a/packages/shared/src/mcpApp.ts b/packages/shared/src/mcpApp.ts index 5be6c3954f050..8892abe7c5049 100644 --- a/packages/shared/src/mcpApp.ts +++ b/packages/shared/src/mcpApp.ts @@ -5,6 +5,7 @@ export const MCP_APP_MIME_TYPE = "text/html;profile=mcp-app"; export const MCP_APP_EXTENSION_ID = "io.modelcontextprotocol/ui"; export const MCP_APP_RESOURCE_SCHEME = "ui://"; export const MCP_APP_OUTPUT_KEY = "t3McpApp"; +export const MCP_APP_CALL_OUTPUT_KEY = "t3McpAppCall"; const MCP_APP_MIN_HEIGHT = 80; export const MCP_APP_DEFAULT_HEIGHT = 320; @@ -124,6 +125,22 @@ export function readMcpAppReference(value: unknown): McpAppReference | undefined }; } +/** + * The call an app is handed when it opens: its last write through its own + * tool, or else the tool call that showed it. A form that deferred a write + * then shows what the write did instead of asking again. + */ +export function mcpAppToolCall(item: { readonly input: unknown; readonly output?: unknown }): { + readonly arguments: unknown; + readonly result: unknown; +} { + const output = Predicate.isObject(item.output) ? item.output : undefined; + const call = output?.[MCP_APP_CALL_OUTPUT_KEY]; + return Predicate.isObject(call) && Predicate.isObject(call.result) + ? { arguments: call.arguments, result: call.result } + : { arguments: item.input, result: output?.result }; +} + export function mcpAppReferencesEqual(left: McpAppReference, right: McpAppReference): boolean { return ( left.attachmentId === right.attachmentId && From 020d56c614f779fbedf0195319ab77f42bf83e59 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Fri, 23 Oct 2026 19:09:36 +0000 Subject: [PATCH 3/9] fix(server): keep a recorded MCP App call through provider updates Review follow-ups for the recorded MCP App call: - A provider resending the tool call no longer drops the recorded call; the ingestor carries it over, so the stored event and a replay keep it. - A call that would push the item's output past what clients read whole is refused, keeping the previous one, since clients would otherwise get truncated text and lose both results. - A failed record logs bounded fields instead of the error. - Tests cover a read-only own tool, and use a per-test recorder. Refs #23825 Co-Authored-By: Claude Opus 5.5 --- .../server/src/mcpApps/McpAppRequests.test.ts | 36 ++++++--- apps/server/src/mcpApps/McpAppRequests.ts | 8 +- .../Orchestrator.control-reads.test.ts | 15 +++- .../src/orchestration-v2/Orchestrator.ts | 23 ++++-- .../ProviderEventIngestor.test.ts | 81 +++++++++++++++++++ .../orchestration-v2/ProviderEventIngestor.ts | 29 ++++++- .../src/orchestration-v2/WireProjection.ts | 6 ++ 7 files changed, 175 insertions(+), 23 deletions(-) diff --git a/apps/server/src/mcpApps/McpAppRequests.test.ts b/apps/server/src/mcpApps/McpAppRequests.test.ts index cd29e25e65ee5..1651095964abd 100644 --- a/apps/server/src/mcpApps/McpAppRequests.test.ts +++ b/apps/server/src/mcpApps/McpAppRequests.test.ts @@ -65,13 +65,13 @@ const app = { }; const storedContext = new Map(); -const dispatched: Array = []; function makeLayer(input: { readonly item: OrchestrationV2TurnItem | null; readonly mcpApps?: ProviderAdapter.ProviderAdapterV2McpApps; readonly live?: boolean; readonly recordFails?: boolean; + readonly dispatched?: Array; }) { return McpAppRequests.layer.pipe( Layer.provide( @@ -93,7 +93,7 @@ function makeLayer(input: { input.recordFails === true ? Effect.fail(new Orchestrator.OrchestratorProjectionError({ threadId })) : Effect.sync(() => { - dispatched.push(command); + input.dispatched?.push(command); return {} as never; }), getThreadRecords: (id: ThreadId) => @@ -183,19 +183,19 @@ describe("McpAppRequests", () => { }).pipe(Effect.provide(makeLayer({ item: appItem({ t3McpApp: app }), mcpApps }))), ); - it.effect("keeps the app's writes through its own tool on the tool call", () => - Effect.gen(function* () { + it.effect("keeps the app's writes through its own tool on the tool call", () => { + const dispatched: Array = []; + return Effect.gen(function* () { const requests = yield* McpAppRequests.McpAppRequests; - const before = dispatched.length; const call = (name: string, args: Record) => requests.callTool({ threadId, itemId, name, arguments: args }); yield* call("get_weather", { city: "Paris", _ui_submitted: true }); - // Reads, other tools and failed writes leave the call as it was. + // Other tools and failed writes leave the call as it was. yield* call("refresh", {}); yield* call("set_alert", {}); yield* call("get_weather", { fail: true }); assert.deepEqual( - dispatched.slice(before).map((command) => + dispatched.map((command) => command.type === "mcp_app.call.record" ? { threadId: command.threadId, @@ -214,8 +214,26 @@ describe("McpAppRequests", () => { }, ], ); - }).pipe(Effect.provide(makeLayer({ item: appItem({ t3McpApp: app }), mcpApps }))), - ); + }).pipe(Effect.provide(makeLayer({ item: appItem({ t3McpApp: app }), mcpApps, dispatched }))); + }); + + it.effect("doesn't keep reads through the app's own tool", () => { + const dispatched: Array = []; + const readOnlyApp: ProviderAdapter.ProviderAdapterV2McpApps = { + ...mcpApps, + listTools: () => + Effect.succeed([{ name: "get_weather", annotations: { readOnlyHint: true } }]), + }; + return Effect.gen(function* () { + const requests = yield* McpAppRequests.McpAppRequests; + yield* requests.callTool({ threadId, itemId, name: "get_weather", arguments: {} }); + assert.deepEqual(dispatched, []); + }).pipe( + Effect.provide( + makeLayer({ item: appItem({ t3McpApp: app }), mcpApps: readOnlyApp, dispatched }), + ), + ); + }); it.effect("returns a write's result even when it can't be recorded", () => Effect.gen(function* () { diff --git a/apps/server/src/mcpApps/McpAppRequests.ts b/apps/server/src/mcpApps/McpAppRequests.ts index 9363506ab7ff2..6fc252b8a2896 100644 --- a/apps/server/src/mcpApps/McpAppRequests.ts +++ b/apps/server/src/mcpApps/McpAppRequests.ts @@ -166,8 +166,12 @@ const make = Effect.gen(function* () { }) .pipe( // The write already happened; failing the call would offer it again. - Effect.catch((cause) => - Effect.logWarning("Could not record an MCP App's tool call", { cause }), + Effect.catch((error) => + Effect.logWarning("Could not record an MCP App's tool call", { + threadId: input.threadId, + itemId: input.itemId, + error: error._tag, + }), ), ); } diff --git a/apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts b/apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts index be47df2ed6fc6..e4eaf8454d0b5 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts @@ -1299,13 +1299,13 @@ it.effect("keeps an MCP App's recorded call beside the tool's own result", () => arguments: { title: "Shipped", _ui_submitted: true }, result: { content: [{ type: "text", text: "Created issue #1" }] }, }; - const record = (turnItemId: TurnItemId) => + const record = (turnItemId: TurnItemId, call = submitted) => orchestrator.dispatch({ type: "mcp_app.call.record", - commandId: CommandId.make(`record:${turnItemId}`), + commandId: CommandId.make(`record:${turnItemId}:${call.arguments.title}`), threadId, turnItemId, - ...submitted, + ...call, }); // Clients refetch an item's detail when its update time moves. @@ -1317,5 +1317,14 @@ it.effect("keeps an MCP App's recorded call beside the tool's own result", () => assert.isTrue(DateTime.isGreaterThan(recorded.updatedAt, now)); // Only a call that shows an app has an app to keep a call for. assert.isTrue(Result.isFailure(yield* record(plainItemId).pipe(Effect.result))); + // Clients would read an output this large as truncated text, losing both results. + const oversized = { + arguments: { title: "Oversized", _ui_submitted: true }, + result: { content: [{ type: "text", text: "x".repeat(300 * 1024) }] }, + }; + assert.isTrue(Result.isFailure(yield* record(appItemId, oversized).pipe(Effect.result))); + const kept = yield* projections.getTurnItem({ threadId, itemId: appItemId }); + assert(kept?.type === "dynamic_tool"); + assert.deepInclude(kept.output, { t3McpAppCall: submitted }); }).pipe(Effect.provide(layerTest)), ); diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index 2e9bc2681f68b..a4aa80782cb06 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -147,6 +147,7 @@ import { ThreadForkServiceV2, } from "./ThreadForkService.ts"; import { planThreadDeletion } from "./ThreadDeletion.ts"; +import { toolOutputFitsDetail } from "./WireProjection.ts"; import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter"; import * as ServerSettings from "../serverSettings.ts"; @@ -7657,6 +7658,19 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio cause: `Turn item ${command.turnItemId} does not show an MCP App.`, }); } + const output = { + ...(Predicate.isObject(item.output) ? item.output : {}), + [MCP_APP_CALL_OUTPUT_KEY]: { arguments: command.arguments, result: command.result }, + }; + // Clients read an oversized output as truncated text, which would leave + // the app with neither result. + if (!toolOutputFitsDetail(output)) { + return yield* new OrchestratorDispatchError({ + commandId: command.commandId, + commandType: command.type, + cause: `The MCP App call on turn item ${command.turnItemId} is too large to keep.`, + }); + } const now = yield* DateTime.now; yield* emit( events, @@ -7667,14 +7681,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio ...(item.runId === null ? {} : { runId: item.runId }), ...(item.nodeId === null ? {} : { nodeId: item.nodeId }), occurredAt: now, - payload: { - ...item, - output: { - ...(Predicate.isObject(item.output) ? item.output : {}), - [MCP_APP_CALL_OUTPUT_KEY]: { arguments: command.arguments, result: command.result }, - }, - updatedAt: now, - }, + payload: { ...item, output, updatedAt: now }, }); }, ); diff --git a/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts b/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts index 849cedded9292..8f43e3f70251b 100644 --- a/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts +++ b/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts @@ -4,6 +4,7 @@ import { CheckpointId, CheckpointRef, CheckpointScopeId, + EventId, MessageId, GitCommandError, type ModelSelection, @@ -1490,6 +1491,86 @@ layer("ProviderEventIngestorV2", (it) => { }), ); + it.effect("keeps an MCP App's recorded call when the provider resends its tool call", () => + Effect.gen(function* () { + const now = yield* DateTime.now; + const eventSink = yield* EventSink.EventSinkV2; + const eventStore = yield* EventStore.EventStoreV2; + const projectionStore = yield* ProjectionStore.ProjectionStoreV2; + const ingestor = yield* ProviderEventIngestor.ProviderEventIngestorV2; + const idAllocator = yield* IdAllocator.IdAllocatorV2; + const threadEvent = yield* threadCreatedEvent(now); + const providerSessionId = yield* idAllocator.allocate.providerSession({ + providerInstanceId: modelSelection.instanceId, + threadId: threadEvent.threadId, + }); + const providerOutput = { + t3McpApp: { + attachmentId: "thread-app-html", + server: "github", + tool: "issue_write", + resourceUri: "ui://github/issue-write", + }, + result: { content: [{ type: "text", text: "Form shown" }], isError: true }, + }; + const call = { + arguments: { title: "Shipped", _ui_submitted: true }, + result: { content: [{ type: "text", text: "Created issue #1" }] }, + }; + const turnItem: OrchestrationV2TurnItem = { + id: TurnItemId.make("turn-item:mcp-app"), + threadId: threadEvent.threadId, + runId: null, + nodeId: null, + providerThreadId: null, + providerTurnId: null, + nativeItemRef: null, + parentItemId: null, + ordinal: 1, + status: "failed", + title: "github.issue_write", + startedAt: now, + completedAt: now, + updatedAt: now, + type: "dynamic_tool", + toolName: "github.issue_write", + input: { title: "Draft" }, + output: providerOutput, + }; + const ingest = ingestor.ingestNormalized({ + providerSessionId, + providerInstanceId: modelSelection.instanceId, + threadId: threadEvent.threadId, + event: { type: "turn_item.updated", driver: CODEX_DRIVER, turnItem }, + }); + + yield* eventSink.write({ events: [threadEvent] }); + yield* ingest; + yield* projectionStore.apply({ + id: EventId.make("event:mcp-app-call-recorded"), + type: "turn-item.updated", + threadId: threadEvent.threadId, + occurredAt: now, + payload: { ...turnItem, output: { ...providerOutput, t3McpAppCall: call } }, + }); + yield* ingest; + + const projected = yield* projectionStore.getTurnItem({ + threadId: threadEvent.threadId, + itemId: turnItem.id, + }); + assert(projected?.type === "dynamic_tool"); + assert.deepEqual(projected.output, { ...providerOutput, t3McpAppCall: call }); + // The resent item's event carries the call too, so a replay keeps it. + const stored = yield* eventStore + .read({ threadId: threadEvent.threadId, eventType: "turn-item.updated" }) + .pipe(Stream.runCollect); + const last = Array.from(stored).at(-1)?.event; + assert(last?.type === "turn-item.updated" && last.payload.type === "dynamic_tool"); + assert.deepEqual(last.payload.output, { ...providerOutput, t3McpAppCall: call }); + }), + ); + it.effect("stores a bounded copy of a large file-change diff in both SQLite tables", () => Effect.gen(function* () { const now = yield* DateTime.now; diff --git a/apps/server/src/orchestration-v2/ProviderEventIngestor.ts b/apps/server/src/orchestration-v2/ProviderEventIngestor.ts index 8e916ab79319b..59ee8fec4ffd4 100644 --- a/apps/server/src/orchestration-v2/ProviderEventIngestor.ts +++ b/apps/server/src/orchestration-v2/ProviderEventIngestor.ts @@ -7,6 +7,7 @@ import { type OrchestrationV2Run, type OrchestrationV2ProviderTurn, type OrchestrationV2Subagent, + type OrchestrationV2TurnItem, type OrchestrationV2ThreadProjection, type ModelSelection, type RuntimeMode, @@ -24,9 +25,11 @@ import * as Context from "effect/Context"; import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; +import * as Predicate from "effect/Predicate"; import * as Schema from "effect/Schema"; import { AgentScope } from "@t3tools/shared/AgentScope"; +import { MCP_APP_CALL_OUTPUT_KEY, MCP_APP_OUTPUT_KEY } from "@t3tools/shared/mcpApp"; import { isTemporaryWorktreeBranch } from "@t3tools/shared/git"; import { getModelSelectionStringOptionValue, modelSelectionsEqual } from "@t3tools/shared/model"; import * as AnalyticsService from "../telemetry/AnalyticsService.ts"; @@ -304,6 +307,28 @@ export const layer: Layer.Layer< const eventSink = yield* EventSink.EventSinkV2; const git = yield* GitVcsDriver.GitVcsDriver; const projections = yield* ProjectionStore.ProjectionStoreV2; + // A provider's copy of a tool call never carries the call its MCP App + // recorded on it later, so an update would otherwise drop that call. + const keepRecordedMcpAppCall = Effect.fn("ProviderEventIngestor.keepRecordedMcpAppCall")( + function* (item: OrchestrationV2TurnItem) { + if ( + item.type !== "dynamic_tool" || + !Predicate.isObject(item.output) || + !(MCP_APP_OUTPUT_KEY in item.output) || + MCP_APP_CALL_OUTPUT_KEY in item.output + ) { + return item; + } + const stored = yield* projections.getTurnItem({ threadId: item.threadId, itemId: item.id }); + const call = + stored?.type === "dynamic_tool" && Predicate.isObject(stored.output) + ? stored.output[MCP_APP_CALL_OUTPUT_KEY] + : undefined; + return call === undefined + ? item + : { ...item, output: { ...item.output, [MCP_APP_CALL_OUTPUT_KEY]: call } }; + }, + ); const idAllocator = yield* IdAllocator.IdAllocatorV2; const threadCommands = yield* ThreadCommandExecutor.ThreadCommandExecutor; const analytics = yield* ProviderTurnAnalytics; @@ -637,7 +662,9 @@ export const layer: Layer.Layer< type: "turn-item.updated", threadId: input.event.turnItem.threadId, payload: boundFileChangeForStorage( - stripUnservedToolOutputImageBytes(input.event.turnItem), + stripUnservedToolOutputImageBytes( + yield* keepRecordedMcpAppCall(input.event.turnItem), + ), ), runId: input.event.turnItem.runId, nodeId: input.event.turnItem.nodeId, diff --git a/apps/server/src/orchestration-v2/WireProjection.ts b/apps/server/src/orchestration-v2/WireProjection.ts index 043fbd3435acb..1f5a55ff39f32 100644 --- a/apps/server/src/orchestration-v2/WireProjection.ts +++ b/apps/server/src/orchestration-v2/WireProjection.ts @@ -163,6 +163,12 @@ function boundDynamicValue(value: unknown): unknown { * When the rest is too large to send whole, its truncated text still comes with * the image markers, in order, so clients can load each image by index. */ +/** Whether a tool's output reaches clients whole when its item's detail is read. */ +export function toolOutputFitsDetail(output: unknown): boolean { + const omitted = omitToolOutputImageData(output); + return boundDynamicValue(omitted) === omitted; +} + function boundToolOutput(output: unknown): unknown { const omitted = omitToolOutputImageData(output); const bounded = boundDynamicValue(omitted); From 6cbca805525ace5c2a7d41759943a07b5f81a2c8 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Fri, 23 Oct 2026 19:18:27 +0000 Subject: [PATCH 4/9] fix(server): keep a recorded MCP App call inside the write transaction The recorded call was carried over in the provider ingestor, from a read made before the event was written. A record committed between that read and the write was lost, and the ingestor's image stripping then ran over the carried-over result. The carry-over now happens in EventSink's per-item normalization, inside the write's transaction and after the ingestor has stripped the provider's own output. Refs #23825 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/orchestration-v2/EventSink.ts | 35 ++++++++++++++++++- .../ProviderEventIngestor.test.ts | 8 ++++- .../orchestration-v2/ProviderEventIngestor.ts | 29 +-------------- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/apps/server/src/orchestration-v2/EventSink.ts b/apps/server/src/orchestration-v2/EventSink.ts index bf50bbc8395ee..551789b27e081 100644 --- a/apps/server/src/orchestration-v2/EventSink.ts +++ b/apps/server/src/orchestration-v2/EventSink.ts @@ -3,6 +3,7 @@ import { type OrchestrationV2Run, OrchestrationV2DomainEvent, type OrchestrationV2ProviderThread, + type OrchestrationV2TurnItem, OrchestrationV2StoredEvent, ProviderThreadId, RunAttemptId, @@ -17,12 +18,14 @@ import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; +import * as Predicate from "effect/Predicate"; import * as PubSub from "effect/PubSub"; import * as Semaphore from "effect/Semaphore"; import * as Schema from "effect/Schema"; import * as Stream from "effect/Stream"; import * as SqlClient from "effect/sql/SqlClient"; +import { MCP_APP_CALL_OUTPUT_KEY, MCP_APP_OUTPUT_KEY } from "@t3tools/shared/mcpApp"; import { replayAndBufferProjectedLiveEvents } from "./LiveStreamBudget.ts"; import type { UnsequencedProjectEvent } from "../persistence/OrchestrationEventStore.ts"; import { projectDomainEventForWire } from "./WireProjection.ts"; @@ -337,6 +340,33 @@ const layerBase: Layer.Layer< }); }); + // A provider's copy of a tool call never carries the call its MCP App + // recorded on it later. Merged here, inside the write's transaction, so a + // resent item can't drop a call recorded since it was read. + const keepRecordedMcpAppCall = ( + item: OrchestrationV2TurnItem, + ): Effect.Effect => { + if (item.type !== "dynamic_tool") return Effect.succeed(item); + const output = Predicate.isObject(item.output) ? item.output : undefined; + if ( + output === undefined || + !(MCP_APP_OUTPUT_KEY in output) || + MCP_APP_CALL_OUTPUT_KEY in output + ) + return Effect.succeed(item); + return projectionStore.getTurnItem({ threadId: item.threadId, itemId: item.id }).pipe( + Effect.map((stored) => { + const call = + stored?.type === "dynamic_tool" && Predicate.isObject(stored.output) + ? stored.output[MCP_APP_CALL_OUTPUT_KEY] + : undefined; + return call === undefined + ? item + : { ...item, output: { ...output, [MCP_APP_CALL_OUTPUT_KEY]: call } }; + }), + ); + }; + const normalizeEvents = (events: ReadonlyArray) => { const runOrdinals = new Map( events.flatMap((event) => @@ -354,7 +384,10 @@ const layerBase: Layer.Layer< event.payload, event.payload.runId === null ? undefined : runOrdinals.get(event.payload.runId), ) - .pipe(Effect.map((payload) => ({ ...event, payload }))) + .pipe( + Effect.flatMap(keepRecordedMcpAppCall), + Effect.map((payload) => ({ ...event, payload })), + ) : Effect.succeed(event), { concurrency: 1 }, ); diff --git a/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts b/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts index 8f43e3f70251b..045a96343d0e2 100644 --- a/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts +++ b/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts @@ -1513,9 +1513,15 @@ layer("ProviderEventIngestorV2", (it) => { }, result: { content: [{ type: "text", text: "Form shown" }], isError: true }, }; + // The recorded result's image must survive the provider's image stripping. const call = { arguments: { title: "Shipped", _ui_submitted: true }, - result: { content: [{ type: "text", text: "Created issue #1" }] }, + result: { + content: [ + { type: "text", text: "Created issue #1" }, + { type: "image", mimeType: "image/png", data: Buffer.alloc(300, 7).toString("base64") }, + ], + }, }; const turnItem: OrchestrationV2TurnItem = { id: TurnItemId.make("turn-item:mcp-app"), diff --git a/apps/server/src/orchestration-v2/ProviderEventIngestor.ts b/apps/server/src/orchestration-v2/ProviderEventIngestor.ts index 59ee8fec4ffd4..8e916ab79319b 100644 --- a/apps/server/src/orchestration-v2/ProviderEventIngestor.ts +++ b/apps/server/src/orchestration-v2/ProviderEventIngestor.ts @@ -7,7 +7,6 @@ import { type OrchestrationV2Run, type OrchestrationV2ProviderTurn, type OrchestrationV2Subagent, - type OrchestrationV2TurnItem, type OrchestrationV2ThreadProjection, type ModelSelection, type RuntimeMode, @@ -25,11 +24,9 @@ import * as Context from "effect/Context"; import * as DateTime from "effect/DateTime"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; -import * as Predicate from "effect/Predicate"; import * as Schema from "effect/Schema"; import { AgentScope } from "@t3tools/shared/AgentScope"; -import { MCP_APP_CALL_OUTPUT_KEY, MCP_APP_OUTPUT_KEY } from "@t3tools/shared/mcpApp"; import { isTemporaryWorktreeBranch } from "@t3tools/shared/git"; import { getModelSelectionStringOptionValue, modelSelectionsEqual } from "@t3tools/shared/model"; import * as AnalyticsService from "../telemetry/AnalyticsService.ts"; @@ -307,28 +304,6 @@ export const layer: Layer.Layer< const eventSink = yield* EventSink.EventSinkV2; const git = yield* GitVcsDriver.GitVcsDriver; const projections = yield* ProjectionStore.ProjectionStoreV2; - // A provider's copy of a tool call never carries the call its MCP App - // recorded on it later, so an update would otherwise drop that call. - const keepRecordedMcpAppCall = Effect.fn("ProviderEventIngestor.keepRecordedMcpAppCall")( - function* (item: OrchestrationV2TurnItem) { - if ( - item.type !== "dynamic_tool" || - !Predicate.isObject(item.output) || - !(MCP_APP_OUTPUT_KEY in item.output) || - MCP_APP_CALL_OUTPUT_KEY in item.output - ) { - return item; - } - const stored = yield* projections.getTurnItem({ threadId: item.threadId, itemId: item.id }); - const call = - stored?.type === "dynamic_tool" && Predicate.isObject(stored.output) - ? stored.output[MCP_APP_CALL_OUTPUT_KEY] - : undefined; - return call === undefined - ? item - : { ...item, output: { ...item.output, [MCP_APP_CALL_OUTPUT_KEY]: call } }; - }, - ); const idAllocator = yield* IdAllocator.IdAllocatorV2; const threadCommands = yield* ThreadCommandExecutor.ThreadCommandExecutor; const analytics = yield* ProviderTurnAnalytics; @@ -662,9 +637,7 @@ export const layer: Layer.Layer< type: "turn-item.updated", threadId: input.event.turnItem.threadId, payload: boundFileChangeForStorage( - stripUnservedToolOutputImageBytes( - yield* keepRecordedMcpAppCall(input.event.turnItem), - ), + stripUnservedToolOutputImageBytes(input.event.turnItem), ), runId: input.event.turnItem.runId, nodeId: input.event.turnItem.nodeId, From f06ebe95518c53217aa0bd1c44520e6380a17f20 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Fri, 23 Oct 2026 19:23:02 +0000 Subject: [PATCH 5/9] fix(server): a provider resend can't push a recorded MCP App call past the detail limit When a provider resends a tool call with a larger output, the recorded call is only carried over if the merged output still fits what clients read whole. Otherwise the provider's own output is kept, rather than both results turning into truncated text. Refs #23825 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/orchestration-v2/EventSink.ts | 9 ++++-- .../ProviderEventIngestor.test.ts | 31 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/apps/server/src/orchestration-v2/EventSink.ts b/apps/server/src/orchestration-v2/EventSink.ts index 551789b27e081..677016f61fd21 100644 --- a/apps/server/src/orchestration-v2/EventSink.ts +++ b/apps/server/src/orchestration-v2/EventSink.ts @@ -28,7 +28,7 @@ import * as SqlClient from "effect/sql/SqlClient"; import { MCP_APP_CALL_OUTPUT_KEY, MCP_APP_OUTPUT_KEY } from "@t3tools/shared/mcpApp"; import { replayAndBufferProjectedLiveEvents } from "./LiveStreamBudget.ts"; import type { UnsequencedProjectEvent } from "../persistence/OrchestrationEventStore.ts"; -import { projectDomainEventForWire } from "./WireProjection.ts"; +import { projectDomainEventForWire, toolOutputFitsDetail } from "./WireProjection.ts"; import { makeRunOutcomeRecorder, type RunOutcome } from "./RunMetrics.ts"; import * as CommandReceiptStore from "./CommandReceiptStore.ts"; @@ -360,9 +360,12 @@ const layerBase: Layer.Layer< stored?.type === "dynamic_tool" && Predicate.isObject(stored.output) ? stored.output[MCP_APP_CALL_OUTPUT_KEY] : undefined; - return call === undefined + const merged = { ...output, [MCP_APP_CALL_OUTPUT_KEY]: call }; + // Past the detail limit clients would read both results as truncated + // text, so the provider's own output wins. + return call === undefined || !toolOutputFitsDetail(merged) ? item - : { ...item, output: { ...output, [MCP_APP_CALL_OUTPUT_KEY]: call } }; + : { ...item, output: merged }; }), ); }; diff --git a/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts b/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts index 045a96343d0e2..9c05f50c49284 100644 --- a/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts +++ b/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts @@ -1543,15 +1543,16 @@ layer("ProviderEventIngestorV2", (it) => { input: { title: "Draft" }, output: providerOutput, }; - const ingest = ingestor.ingestNormalized({ - providerSessionId, - providerInstanceId: modelSelection.instanceId, - threadId: threadEvent.threadId, - event: { type: "turn_item.updated", driver: CODEX_DRIVER, turnItem }, - }); + const ingest = (item = turnItem) => + ingestor.ingestNormalized({ + providerSessionId, + providerInstanceId: modelSelection.instanceId, + threadId: threadEvent.threadId, + event: { type: "turn_item.updated", driver: CODEX_DRIVER, turnItem: item }, + }); yield* eventSink.write({ events: [threadEvent] }); - yield* ingest; + yield* ingest(); yield* projectionStore.apply({ id: EventId.make("event:mcp-app-call-recorded"), type: "turn-item.updated", @@ -1559,7 +1560,7 @@ layer("ProviderEventIngestorV2", (it) => { occurredAt: now, payload: { ...turnItem, output: { ...providerOutput, t3McpAppCall: call } }, }); - yield* ingest; + yield* ingest(); const projected = yield* projectionStore.getTurnItem({ threadId: threadEvent.threadId, @@ -1574,6 +1575,20 @@ layer("ProviderEventIngestorV2", (it) => { const last = Array.from(stored).at(-1)?.event; assert(last?.type === "turn-item.updated" && last.payload.type === "dynamic_tool"); assert.deepEqual(last.payload.output, { ...providerOutput, t3McpAppCall: call }); + + // An output that clients read whole on its own, but not with the call + // beside it, wins over the call. + const largeOutput = { + ...providerOutput, + result: { content: [{ type: "text", text: "x".repeat(256 * 1024 - 500) }] }, + }; + yield* ingest({ ...turnItem, output: largeOutput }); + const resent = yield* projectionStore.getTurnItem({ + threadId: threadEvent.threadId, + itemId: turnItem.id, + }); + assert(resent?.type === "dynamic_tool"); + assert.deepEqual(resent.output, largeOutput); }), ); From de53b23a8aa6732cf160064337bce8689c50bf7b Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Fri, 23 Oct 2026 19:31:52 +0000 Subject: [PATCH 6/9] fix(server): land a recorded MCP App call on the provider's latest tool call The record command builds its update from the item it read, and a provider update can commit between that read and the command's write, since provider writes don't take the thread's command lock. The record then restored the provider's older copy. EventSink now merges in both directions inside the write's transaction: a provider's copy keeps the stored call, and a recorded call is rebuilt on the stored item. The helper is an untraced Effect function like the sink's other per-event steps. Refs #23825 Co-Authored-By: Claude Opus 5.5 --- apps/server/src/orchestration-v2/EventSink.ts | 60 +++++++++---------- .../ProviderEventIngestor.test.ts | 28 ++++++++- 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/apps/server/src/orchestration-v2/EventSink.ts b/apps/server/src/orchestration-v2/EventSink.ts index 677016f61fd21..39dc46de76f70 100644 --- a/apps/server/src/orchestration-v2/EventSink.ts +++ b/apps/server/src/orchestration-v2/EventSink.ts @@ -340,35 +340,35 @@ const layerBase: Layer.Layer< }); }); - // A provider's copy of a tool call never carries the call its MCP App - // recorded on it later. Merged here, inside the write's transaction, so a - // resent item can't drop a call recorded since it was read. - const keepRecordedMcpAppCall = ( - item: OrchestrationV2TurnItem, - ): Effect.Effect => { - if (item.type !== "dynamic_tool") return Effect.succeed(item); - const output = Predicate.isObject(item.output) ? item.output : undefined; - if ( - output === undefined || - !(MCP_APP_OUTPUT_KEY in output) || - MCP_APP_CALL_OUTPUT_KEY in output - ) - return Effect.succeed(item); - return projectionStore.getTurnItem({ threadId: item.threadId, itemId: item.id }).pipe( - Effect.map((stored) => { - const call = - stored?.type === "dynamic_tool" && Predicate.isObject(stored.output) - ? stored.output[MCP_APP_CALL_OUTPUT_KEY] - : undefined; - const merged = { ...output, [MCP_APP_CALL_OUTPUT_KEY]: call }; - // Past the detail limit clients would read both results as truncated - // text, so the provider's own output wins. - return call === undefined || !toolOutputFitsDetail(merged) - ? item - : { ...item, output: merged }; - }), - ); - }; + // An MCP App's recorded call (`mcp_app.call.record`) belongs to the server + // and the rest of its tool call to the provider, and either writer may have + // read the item before the other changed it. Merged here, inside the + // write's transaction: a provider's copy keeps the stored call, and a + // recorded call lands on the provider's latest copy. + const mergeMcpAppCall = + /* This helper runs for individual orchestration events; the enclosing operation owns the span. */ + Effect.fnUntraced(function* (item: OrchestrationV2TurnItem) { + if (item.type !== "dynamic_tool") return item; + const output = Predicate.isObject(item.output) ? item.output : undefined; + if (output === undefined || !(MCP_APP_OUTPUT_KEY in output)) return item; + const stored = yield* projectionStore.getTurnItem({ + threadId: item.threadId, + itemId: item.id, + }); + if (stored?.type !== "dynamic_tool" || !Predicate.isObject(stored.output)) return item; + const recorded = MCP_APP_CALL_OUTPUT_KEY in output; + const call = (recorded ? output : stored.output)[MCP_APP_CALL_OUTPUT_KEY]; + if (call === undefined) return item; + const base = recorded ? { ...stored, updatedAt: item.updatedAt } : item; + const merged = { + ...(Predicate.isObject(base.output) ? base.output : {}), + [MCP_APP_CALL_OUTPUT_KEY]: call, + }; + // Past the detail limit clients would read both results as truncated + // text, so the provider's output wins over the call. + if (!toolOutputFitsDetail(merged)) return recorded ? stored : item; + return { ...base, output: merged }; + }); const normalizeEvents = (events: ReadonlyArray) => { const runOrdinals = new Map( @@ -388,7 +388,7 @@ const layerBase: Layer.Layer< event.payload.runId === null ? undefined : runOrdinals.get(event.payload.runId), ) .pipe( - Effect.flatMap(keepRecordedMcpAppCall), + Effect.flatMap(mergeMcpAppCall), Effect.map((payload) => ({ ...event, payload })), ) : Effect.succeed(event), diff --git a/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts b/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts index 9c05f50c49284..d7010728c122e 100644 --- a/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts +++ b/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts @@ -1491,7 +1491,7 @@ layer("ProviderEventIngestorV2", (it) => { }), ); - it.effect("keeps an MCP App's recorded call when the provider resends its tool call", () => + it.effect("merges an MCP App's recorded call with the provider's latest tool call", () => Effect.gen(function* () { const now = yield* DateTime.now; const eventSink = yield* EventSink.EventSinkV2; @@ -1589,6 +1589,32 @@ layer("ProviderEventIngestorV2", (it) => { }); assert(resent?.type === "dynamic_tool"); assert.deepEqual(resent.output, largeOutput); + + // A call recorded from a copy read before the provider's latest update + // lands on that update instead of restoring the copy. + const finalOutput = { + ...providerOutput, + result: { content: [{ type: "text", text: "Provider final" }] }, + }; + yield* ingest({ ...turnItem, status: "completed", output: finalOutput }); + yield* eventSink.write({ + events: [ + { + id: EventId.make("event:mcp-app-call-from-stale-copy"), + type: "turn-item.updated", + threadId: threadEvent.threadId, + occurredAt: now, + payload: { ...turnItem, output: { ...providerOutput, t3McpAppCall: call } }, + }, + ], + }); + const latest = yield* projectionStore.getTurnItem({ + threadId: threadEvent.threadId, + itemId: turnItem.id, + }); + assert(latest?.type === "dynamic_tool"); + assert.equal(latest.status, "completed"); + assert.deepEqual(latest.output, { ...finalOutput, t3McpAppCall: call }); }), ); From 957a1f209b80f0a3b9c4a9d587bf5385c8a893e2 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Mon, 26 Oct 2026 02:59:32 +0000 Subject: [PATCH 7/9] fix(server): preserve MCP App item updates after submission --- apps/server/src/orchestration-v2/EventSink.ts | 21 ++++++++------- .../ProviderEventIngestor.test.ts | 26 ++++++++++++++++++- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/apps/server/src/orchestration-v2/EventSink.ts b/apps/server/src/orchestration-v2/EventSink.ts index 4f9f6b401ceea..013138553b1af 100644 --- a/apps/server/src/orchestration-v2/EventSink.ts +++ b/apps/server/src/orchestration-v2/EventSink.ts @@ -330,14 +330,10 @@ const layerBase: Layer.Layer< }); }); - // An MCP App's recorded call (`mcp_app.call.record`) belongs to the server - // and the rest of its tool call to the provider, and either writer may have - // read the item before the other changed it. Merged here, inside the - // write's transaction: a provider's copy keeps the stored call, and a - // recorded call lands on the provider's latest copy. + // Merge against the latest item inside the write transaction; either writer may hold a stale copy. const mergeMcpAppCall = /* This helper runs for individual orchestration events; the enclosing operation owns the span. */ - Effect.fnUntraced(function* (item: OrchestrationV2TurnItem) { + Effect.fnUntraced(function* (item: OrchestrationV2TurnItem, recorded: boolean) { if (item.type !== "dynamic_tool") return item; const output = Predicate.isObject(item.output) ? item.output : undefined; if (output === undefined || !(MCP_APP_OUTPUT_KEY in output)) return item; @@ -346,7 +342,6 @@ const layerBase: Layer.Layer< itemId: item.id, }); if (stored?.type !== "dynamic_tool" || !Predicate.isObject(stored.output)) return item; - const recorded = MCP_APP_CALL_OUTPUT_KEY in output; const call = (recorded ? output : stored.output)[MCP_APP_CALL_OUTPUT_KEY]; if (call === undefined) return item; const base = recorded ? { ...stored, updatedAt: item.updatedAt } : item; @@ -360,7 +355,10 @@ const layerBase: Layer.Layer< return { ...base, output: merged }; }); - const normalizeEvents = (events: ReadonlyArray) => { + const normalizeEvents = ( + events: ReadonlyArray, + recorded = false, + ) => { const runOrdinals = new Map( events.flatMap((event) => event.type === "run.created" || event.type === "run.updated" @@ -378,7 +376,7 @@ const layerBase: Layer.Layer< event.payload.runId === null ? undefined : runOrdinals.get(event.payload.runId), ) .pipe( - Effect.flatMap(mergeMcpAppCall), + Effect.flatMap((item) => mergeMcpAppCall(item, recorded)), Effect.map((payload) => ({ ...event, payload })), ) : Effect.succeed(event), @@ -682,7 +680,10 @@ const layerBase: Layer.Layer< return { ...existing, committed: false as const, cancelledEffectIds: [] }; } - const normalized = yield* normalizeEvents(input.events); + const normalized = yield* normalizeEvents( + input.events, + input.commandType === "mcp_app.call.record", + ); const storedEvents = yield* eventStore.append({ commandId: input.commandId, events: normalized, diff --git a/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts b/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts index c636476615974..7cdb7cacf4fac 100644 --- a/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts +++ b/apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts @@ -2,6 +2,7 @@ import { assert, it } from "@effect/vitest"; import * as NodeServices from "@effect/platform-node/NodeServices"; import { CheckpointId, + CommandId, CheckpointRef, CheckpointScopeId, EventId, @@ -1627,6 +1628,24 @@ layer("ProviderEventIngestorV2", (it) => { assert(last?.type === "turn-item.updated" && last.payload.type === "dynamic_tool"); assert.deepEqual(last.payload.output, { ...providerOutput, t3McpAppCall: call }); + yield* eventSink.write({ + events: [ + { + id: EventId.make("event:mcp-app-status-update"), + type: "turn-item.updated", + threadId: threadEvent.threadId, + occurredAt: now, + payload: { ...projected, status: "completed", title: "Provider completed" }, + }, + ], + }); + const updated = yield* projectionStore.getTurnItem({ + threadId: threadEvent.threadId, + itemId: turnItem.id, + }); + assert.equal(updated?.status, "completed"); + assert.equal(updated?.title, "Provider completed"); + // An output that clients read whole on its own, but not with the call // beside it, wins over the call. const largeOutput = { @@ -1648,7 +1667,12 @@ layer("ProviderEventIngestorV2", (it) => { result: { content: [{ type: "text", text: "Provider final" }] }, }; yield* ingest({ ...turnItem, status: "completed", output: finalOutput }); - yield* eventSink.write({ + yield* eventSink.commitCommand({ + commandId: CommandId.make("command:mcp-app-call"), + commandType: "mcp_app.call.record", + threadId: threadEvent.threadId, + acceptedAt: now, + effects: [], events: [ { id: EventId.make("event:mcp-app-call-from-stale-copy"), From 1262ccf90fcbb0c82e8be88f375504b2e4dd176c Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Mon, 26 Oct 2026 03:14:35 +0000 Subject: [PATCH 8/9] fix(web): preserve the MCP App host after recording a call --- apps/web/src/components/chat/McpAppFrame.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/chat/McpAppFrame.tsx b/apps/web/src/components/chat/McpAppFrame.tsx index 2c1eec96fe3f3..e97f1369cac08 100644 --- a/apps/web/src/components/chat/McpAppFrame.tsx +++ b/apps/web/src/components/chat/McpAppFrame.tsx @@ -16,6 +16,7 @@ import { MCP_APP_MAX_HEIGHT, mcpAppAllowAttribute, mcpAppFileName, + mcpAppReferencesEqual, mcpAppToolCall, type McpAppReference, } from "@t3tools/shared/mcpApp"; @@ -73,7 +74,8 @@ export function McpAppFrame(props: { readonly awaitingUser?: boolean; readonly onFullscreenChange?: (fullscreen: boolean) => void; }) { - const { app } = props; + const [app, setApp] = useState(props.app); + if (!mcpAppReferencesEqual(app, props.app)) setApp(props.app); const theme = useHtmlRenderTheme(); const frameRef = useRef(null); const boxRef = useRef(null); From 99c900314732bf019e5fe77c461a832c6704f990 Mon Sep 17 00:00:00 2001 From: maria-rcks Date: Tue, 27 Oct 2026 01:45:04 +0000 Subject: [PATCH 9/9] fix(mobile): retain submitted calls with the MCP App subscription --- apps/mobile/src/features/threads/McpAppWebView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/mobile/src/features/threads/McpAppWebView.tsx b/apps/mobile/src/features/threads/McpAppWebView.tsx index 260ac15995142..d7ce599b413c2 100644 --- a/apps/mobile/src/features/threads/McpAppWebView.tsx +++ b/apps/mobile/src/features/threads/McpAppWebView.tsx @@ -96,7 +96,7 @@ function storedToolCall( item: { readonly type: string; readonly input?: unknown; readonly output?: unknown } | null, ) { if (item?.type !== "dynamic_tool") return undefined; - return mcpAppToolCall(item) as { + return mcpAppToolCall({ input: item.input, output: item.output }) as { readonly arguments: unknown; readonly result: McpAppCallToolResult | undefined; };