Skip to content
TypeScript

fix(mcp): t3_thread_read tells agents which thread sent a message (#18194)

Igor Makowski934f91777c45
diff --git a/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts b/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
index af78061ccd7..82c49485270 100644
--- a/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
+++ b/apps/server/src/mcp/OrchestratorMcpService.activity.test.ts
@@ -28,7 +28,7 @@ import { OrchestratorDispatchError } from "../orchestration-v2/Orchestrator.ts";
import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
import type * as McpInvocationContext from "./McpInvocationContext.ts";
import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
-import { liveThreadShell } from "./McpToolAccess.testkit.ts";
+import { idleThreadProjection, liveThreadShell } from "./McpToolAccess.testkit.ts";
const layerOrchestratorService = OrchestratorMcpService.layer.pipe(
Layer.provide(Layer.mock(ThreadLaunchService.ThreadLaunchService)({})),
@@ -686,3 +686,61 @@ it("sendToThread reports why the orchestrator refused the message", async () =>
);
}).pipe(Effect.provide(layer), Effect.runPromise);
});
+
+it("readThread exposes the stored sender thread only for thread-sent messages", async () => {
+ const shell = liveThreadShell(parentThreadId);
+ const messages = [
+ { id: "message-from-child", text: "Child reporting in", senderThreadId: childThreadId },
+ { id: "message-from-user", text: "Thanks" },
+ ];
+ const projection = {
+ ...idleThreadProjection(shell),
+ messages,
+ visibleTurnItems: messages.map((message, position) => ({
+ position,
+ visibility: "local",
+ sourceThreadId: parentThreadId,
+ sourceItemId: `item-${message.id}`,
+ item: {
+ id: `item-${message.id}`,
+ type: "user_message",
+ messageId: message.id,
+ runId: activeRunId,
+ status: "completed",
+ title: null,
+ text: message.text,
+ updatedAt: now,
+ },
+ })),
+ } as unknown as OrchestrationV2ThreadProjection;
+ const layer = layerOrchestratorService.pipe(
+ Layer.provide(
+ Layer.mergeAll(
+ Layer.mock(ThreadManagementService.ThreadManagementService)({
+ getThreadShell: () => Effect.succeed(shell),
+ getThreadRecords: () => Effect.succeed(projection),
+ getProjectThreadRecords: () => Effect.succeed(projection),
+ getTimelinePage: () =>
+ Effect.succeed({ items: projection.visibleTurnItems, totalItems: 2, hasMore: false }),
+ }),
+ ServerSettings.layerTest(),
+ Layer.mock(ProviderRegistry.ProviderRegistry)({ getProviders: Effect.succeed([]) }),
+ Layer.mock(ProjectService.ProjectService)({}),
+ Layer.mock(SecretRequests.SecretRequests)({}),
+ Layer.mock(ScheduledTaskService.ScheduledTaskService)({}),
+ Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({}),
+ NodeCrypto.layer,
+ ),
+ ),
+ );
+
+ await Effect.gen(function* () {
+ const service = yield* OrchestratorMcpService.OrchestratorMcpService;
+ const result = yield* service.readThread(makeScope(), { threadId: parentThreadId });
+ expect(result.items).toMatchObject([
+ { messageId: "message-from-child", senderThreadId: childThreadId },
+ { messageId: "message-from-user" },
+ ]);
+ expect(result.items[1]).not.toHaveProperty("senderThreadId");
+ }).pipe(Effect.provide(layer), Effect.runPromise);
+});
diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts
index b1aa1547950..5cc1fe4f128 100644
--- a/apps/server/src/mcp/OrchestratorMcpService.ts
+++ b/apps/server/src/mcp/OrchestratorMcpService.ts
@@ -915,6 +915,7 @@ function timelineItem(input: {
messageId,
createdBy: message?.createdBy ?? null,
creationSource: message?.creationSource ?? null,
+ ...(message?.senderThreadId === undefined ? {} : { senderThreadId: message.senderThreadId }),
type: input.row.item.type,
status: input.row.item.status,
title: input.row.item.title,
diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts
index 778712ad239..bf41ea299d9 100644
--- a/packages/contracts/src/orchestratorMcp.ts
+++ b/packages/contracts/src/orchestratorMcp.ts
@@ -421,6 +421,7 @@ export const OrchestratorMcpThreadTimelineItem = Schema.Struct({
messageId: Schema.NullOr(MessageId),
createdBy: Schema.NullOr(OrchestrationV2Actor),
creationSource: Schema.NullOr(OrchestrationV2CreationSource),
+ senderThreadId: Schema.optional(ThreadId),
type: Schema.String,
status: OrchestrationV2TurnItemStatus,
title: Schema.NullOr(Schema.String),