@devries-cameron20 / t3code Mirror · read-only / commits / 2a1e43e89e
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 19:45 UTC

fix(server): t3_thread_search says which thread is the caller's (#35377)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Joseph Vidal committed Nov 12, 2026 at 12:23 UTC 2a1e43e89ebe9cfe75f07056f42469e2b1bb3a07
3 files changed +60
apps/server/src/mcp/toolkits/core.test.ts
+58
@@ -10,6 +10,7 @@ import {
10 EnvironmentId,
11 NodeId,
12 OrchestratorMcpThreadReadResult,
13 + ProjectId,
14 ProviderDriverKind,
15 ProviderInstanceId,
16 RunId,
@@ -59,6 +60,7 @@ import * as AnalyticsService from "../../telemetry/AnalyticsService.ts";
60 import { dispatchFailure } from "../threadAccess.ts";
61 import * as EnvironmentHandlers from "./environment/handlers.ts";
62 import * as AttachmentHandlers from "./attachment/handlers.ts";
63 +import { ThreadToolkit } from "./thread/tools.ts";
64 import * as PeerForwarding from "../../peer/PeerForwarding.ts";
65 import * as PeerLinkRequests from "../../peer/PeerLinkRequests.ts";
66 import * as PeerLinks from "../../peer/PeerLinks.ts";
@@ -76,6 +78,9 @@ import { htmlRenderFromToolItem } from "@t3tools/shared/toolOutput";
78
79 const decodeMcpAttachmentInput = Schema.decodeUnknownEffect(McpAttachmentInput);
80 const decodeThreadReadResult = Schema.decodeUnknownEffect(OrchestratorMcpThreadReadResult);
81 +const decodeThreadSearchResult = Schema.decodeUnknownEffect(
82 + ThreadToolkit.tools.t3_thread_search.successSchema,
83 +);
84
85 const layerThreadToolkit = McpHttpServer.layerThreadToolkit.pipe(
86 Layer.provide(Layer.mock(ThreadSearch.ThreadSearch)({})),
@@ -589,6 +594,59 @@ it.effect("a client caller targets any thread within its ceiling and cannot act
594 ),
595 );
596
597 +it.effect("search names the calling thread, so an agent can tell its own match apart", () =>
598 + Effect.gen(function* () {
599 + const server = yield* McpServer.McpServer;
600 + const search = (invocation: McpInvocationContext.McpInvocationScope) =>
601 + server
602 + .callTool({ name: "t3_thread_search", arguments: { query: "release notes" } })
603 + .pipe(
604 + Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
605 + Effect.provideService(McpSchema.McpServerClient, client),
606 + );
607 +
608 + const fromThread = yield* search(scope);
609 + expect(fromThread.structuredContent).toMatchObject({
610 + currentThreadId: threadId,
611 + matches: [{ threadId }, { threadId: "earlier-thread" }],
612 + });
613 +
614 + const fromClient = yield* search(clientScope("auto"));
615 + expect(fromClient.structuredContent).toMatchObject({ currentThreadId: null });
616 +
617 + // A linked environment on an older version answers without the field.
618 + const fromOlderPeer = yield* decodeThreadSearchResult({ matches: [] });
619 + expect(fromOlderPeer).toEqual({ matches: [] });
620 + }).pipe(
621 + Effect.provide(
622 + McpHttpServer.layerThreadToolkit.pipe(
623 + Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),
624 + Layer.provide(NodeCrypto.layer),
625 + Layer.provide(McpToolAccessTestkit.liveThreadsLayer),
626 + Layer.provide(
627 + Layer.mock(ThreadSearch.ThreadSearch)({
628 + searchThreads: () =>
629 + Effect.succeed({
630 + matches: [threadId, ThreadId.make("earlier-thread")].map((id) => ({
631 + threadId: id,
632 + projectId: ProjectId.make("project:mcp-test"),
633 + title: "Release notes",
634 + source: "title" as const,
635 + snippet: "",
636 + messageCreatedAt: null,
637 + })),
638 + }),
639 + }),
640 + ),
641 + Layer.provide(Layer.mock(ScheduledTaskService.ScheduledTaskService)({})),
642 + Layer.provide(Layer.mock(PeerForwarding.PeerForwarding)({})),
643 + Layer.provide(Layer.mock(PeerLinkRequests.PeerLinkRequests)({})),
644 + Layer.provide(Layer.mock(PeerLinks.PeerLinks)({})),
645 + ),
646 + ),
647 + ),
648 +);
649 +
650 it.effect("a read-only client reads threads and is refused every write before it runs", () =>
651 Effect.gen(function* () {
652 const server = yield* McpServer.McpServer;
apps/server/src/mcp/toolkits/thread/handlers.ts
+1
@@ -132,6 +132,7 @@ export const layer = McpToolAccess.toLayer(ThreadToolkit, {
132 .searchThreads({ ...input, projectId: input.projectId ?? caller?.projectId })
133 .pipe(Effect.mapError(unavailable));
134 return {
135 + currentThreadId: scope.thread?.threadId ?? null,
136 matches: matches.map((match) => ({
137 ...match,
138 link: McpInvocationContext.threadLinkFor(scope, match.threadId, match.title),
apps/server/src/mcp/toolkits/thread/tools.ts
+1
@@ -199,6 +199,7 @@ const ThreadSearchTool = Tool.make("t3_thread_search", {
199 projectId: Schema.optional(ProjectId),
200 }),
201 success: Schema.Struct({
202 + currentThreadId: Schema.optional(Schema.NullOr(ThreadId)),
203 matches: Schema.Array(
204 Schema.Struct({
205 threadId: OrchestrationThreadSearchMatch.fields.threadId,