@devries-cameron20 / t3code Mirror · read-only / commits / f28c74a7d0
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, 11:00 UTC

fix(server): outside MCP clients stop being offered thread-bound tools (#32764)

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

RVZO6 committed Nov 15, 2026 at 04:15 UTC f28c74a7d04047afb5fa421815643f6db8ca23dd
14 files changed +137 -40
apps/server/src/mcp/McpHttpServer.test.ts
+2 -4
@@ -604,13 +604,11 @@ it.effect("refuses preview tools to a client outside a thread before they run",
604 const click = yield* server
605 .callTool({ name: "preview_act", arguments: { action: "click", locator: "text=Send" } })
606 .pipe(
607 + Effect.flip,
608 Effect.provideService(McpInvocationContext.McpInvocationContext, readOnly),
609 Effect.provideService(McpSchema.McpServerClient, client),
610 );
610 - expect(click.isError).toBe(true);
611 - expect(click.content).toEqual([
612 - { type: "text", text: expect.stringContaining("needs an agent running inside T3 Code") },
613 - ]);
611 + expect(click.message).toContain("Tool 'preview_act' not found");
612 }).pipe(Effect.provide(layerTest)),
613 );
614
apps/server/src/mcp/McpInvocationContext.ts
+11
@@ -180,6 +180,17 @@ export const hiddenFromSubagents = (): boolean => {
180 return scope?.thread?.subagent !== true;
181 };
182
183 +/**
184 + * `McpSchema.EnabledWhen` for tools that act as the calling thread: a client
185 + * from outside has none. Discovery only; `McpToolAccess` still refuses the
186 + * call, and `toLayer` requires this on every thread-bound declaration.
187 + */
188 +export const hiddenFromOutsideClients = (): boolean => {
189 + const fiber = Fiber.getCurrent();
190 + const scope = fiber && Context.getOrUndefined(fiber.context, McpInvocationContext);
191 + return scope === undefined || scope.thread !== undefined;
192 +};
193 +
194 /** `McpSchema.EnabledWhen` for tools that only serve links, hidden while the beta is off. */
195 export const hiddenWhileLinksOff = (): boolean => {
196 const fiber = Fiber.getCurrent();
apps/server/src/mcp/McpToolAccess.test.ts
+49 -5
@@ -13,6 +13,8 @@ import * as Effect from "effect/Effect";
13 import * as Exit from "effect/Exit";
14 import * as Layer from "effect/Layer";
15 import * as Schema from "effect/Schema";
16 +import * as Sink from "effect/Sink";
17 +import * as Stream from "effect/Stream";
18 import { McpSchema, McpServer, Tool, Toolkit } from "effect/ai";
19
20 import { OrchestratorProjectionError } from "../orchestration-v2/Orchestrator.ts";
@@ -113,8 +115,14 @@ const probe = {
115 };
116 const ProbeToolkit = Toolkit.make(
117 Tool.make("reads", probe),
116 - Tool.make("reads_as_caller", probe),
117 - Tool.make("acts_as_caller", probe),
118 + Tool.make("reads_as_caller", probe).annotate(
119 + McpSchema.EnabledWhen,
120 + McpInvocationContext.hiddenFromOutsideClients,
121 + ),
122 + Tool.make("acts_as_caller", probe).annotate(
123 + McpSchema.EnabledWhen,
124 + McpInvocationContext.hiddenFromOutsideClients,
125 + ),
126 Tool.make("writes", probe),
127 Tool.make("writes_with_capability", probe),
128 Tool.make("writes_threads", {
@@ -254,7 +262,6 @@ it.effect.each([
262 ["writes_environment", readOnlyClient, {}, "capability_denied"],
263
264 ["reads_as_caller", ended, {}, "ran"],
257 - ["reads_as_caller", fullAccessClient, {}, "thread_credential_required"],
265 ["acts_as_caller", supervised, {}, "ran"],
266 ["acts_as_caller", ended, {}, "parent_not_active"],
267 ["acts_as_caller", background, {}, "ran"],
@@ -262,7 +269,6 @@ it.effect.each([
269 ["acts_as_caller", mismatchedProvider, {}, "parent_not_active"],
270 ["acts_as_caller", archivedBackground, {}, "parent_not_active"],
271 ["acts_as_caller", unknownOwnerBackground, {}, "parent_not_active"],
265 - ["acts_as_caller", fullAccessClient, {}, "thread_credential_required"],
272
273 ["writes", supervised, {}, "ran"],
274 ["writes", ended, {}, "parent_not_active"],
@@ -455,7 +461,12 @@ it.effect.each([
461
462 it.effect("refuses a linked environment to a tool that acts as its calling thread", () =>
463 Effect.gen(function* () {
458 - const CallerToolkit = Toolkit.make(Tool.make("acts_as_caller", linkedProbe));
464 + const CallerToolkit = Toolkit.make(
465 + Tool.make("acts_as_caller", linkedProbe).annotate(
466 + McpSchema.EnabledWhen,
467 + McpInvocationContext.hiddenFromOutsideClients,
468 + ),
469 + );
470 const built = yield* Layer.build(
471 McpToolAccess.HandlersLayer.layer(
472 McpToolAccess.toLayer(CallerToolkit, {
@@ -466,3 +477,36 @@ it.effect("refuses a linked environment to a tool that acts as its calling threa
477 expect(Exit.isFailure(built) && Cause.hasDies(built.cause)).toBe(true);
478 }),
479 );
480 +
481 +// Discovery hides these tools. The handler must refuse on its own if that ever changes.
482 +it.effect.each(["reads_as_caller", "acts_as_caller"] as const)(
483 + "%s refuses an outside client behind discovery",
484 + (tool) =>
485 + Effect.gen(function* () {
486 + const built = yield* ProbeToolkit;
487 + const { result } = yield* built
488 + .handle(tool, {})
489 + .pipe(Stream.unwrap, Stream.run(Sink.last()), Effect.flatMap(Effect.fromOption));
490 + expect(result).toMatchObject({ code: "thread_credential_required" });
491 + }).pipe(
492 + Effect.provide(McpToolAccess.HandlersLayer.layer(layerProbeHandlers)),
493 + Effect.provideService(McpInvocationContext.McpInvocationContext, fullAccessClient),
494 + Effect.provide(Layer.mock(ThreadManagement.ThreadManagementService)({})),
495 + ),
496 +);
497 +
498 +it.effect("refuses to build a thread-bound tool that outside clients would be offered", () =>
499 + Effect.gen(function* () {
500 + const CallerToolkit = Toolkit.make(Tool.make("reads_as_caller", probe));
501 + const built = yield* Layer.build(
502 + McpToolAccess.HandlersLayer.layer(
503 + McpToolAccess.toLayer(CallerToolkit, {
504 + reads_as_caller: McpToolAccess.readsAsCaller(() => ran),
505 + }),
506 + ),
507 + ).pipe(Effect.scoped, Effect.exit);
508 + expect(Exit.isFailure(built) && Cause.pretty(built.cause)).toContain(
509 + "reads_as_caller acts as its calling thread",
510 + );
511 + }),
512 +);
apps/server/src/mcp/McpToolAccess.ts
+12 -1
@@ -7,6 +7,7 @@ import {
7 type RuntimeMode,
8 type ThreadId,
9 } from "@t3tools/contracts";
10 +import * as Context from "effect/Context";
11 import * as Effect from "effect/Effect";
12 import * as Option from "effect/Option";
13 import * as Predicate from "effect/Predicate";
@@ -14,6 +15,7 @@ import * as Ref from "effect/Ref";
15 import * as Struct from "effect/Struct";
16 import type * as Layer from "effect/Layer";
17 import type * as Scope from "effect/Scope";
18 +import { McpSchema } from "effect/ai";
19 import type { Tool, Toolkit } from "effect/ai";
20
21 import {
@@ -420,8 +422,17 @@ const routed = Effect.fn("McpToolAccess.routed")(function* <Tools extends Record
422 const handlers: Record<string, unknown> = { ...checked };
423 for (const [name, declaration] of Object.entries<Declaration<unknown>>(declarations)) {
424 const tool = toolkit.tools[name];
423 - if (tool === undefined || !takesLinkedEnvironment(tool)) continue;
425 + if (tool === undefined) continue;
426 const remote = remoteCheckOf(declaration);
427 + if (
428 + remote === undefined &&
429 + Context.getOrUndefined(tool.annotations, McpSchema.EnabledWhen) !==
430 + McpInvocationContext.hiddenFromOutsideClients
431 + )
432 + return yield* Effect.die(
433 + `${name} acts as its calling thread, so outside clients must not be offered it.`,
434 + );
435 + if (!takesLinkedEnvironment(tool)) continue;
436 const forwarded = forwardedOf(declaration) as
437 | Forwarded<object, unknown, Tool.Failure<Tools[keyof Tools]>, never>
438 | undefined;
apps/server/src/mcp/toolkits/core.test.ts
+4 -3
@@ -964,22 +964,23 @@ it.effect("a read-only client reads threads and is refused every write before it
964 );
965 const dispatched: Array<string> = [];
966
967 -it.effect("refuses act-as-caller tools to a client caller", () =>
967 +it.effect("hides act-as-caller tools from a client caller", () =>
968 Effect.gen(function* () {
969 const server = yield* McpServer.McpServer;
970 - const result = yield* server
970 + const error = yield* server
971 .callTool({
972 name: "delegate_task",
973 arguments: { task: "Review", mode: "async" },
974 })
975 .pipe(
976 + Effect.flip,
977 Effect.provideService(
978 McpInvocationContext.McpInvocationContext,
979 clientScope("full-access"),
980 ),
981 Effect.provideService(McpSchema.McpServerClient, client),
982 );
982 - expect(declaredFailure(result)).toMatchObject({ code: "thread_credential_required" });
983 + expect(error.message).toContain("Tool 'delegate_task' not found");
984 }).pipe(
985 Effect.provide(
986 layerOrchestratorToolkit.pipe(
apps/server/src/mcp/toolkits/device/tools.ts
+9 -5
@@ -12,7 +12,7 @@ import * as Schema from "effect/Schema";
12 import * as FileSystem from "effect/FileSystem";
13 import * as Path from "effect/Path";
14 import * as ServerConfig from "../../../config.ts";
15 -import { Tool, Toolkit } from "effect/ai";
15 +import { McpSchema, Tool, Toolkit } from "effect/ai";
16
17 import * as McpInvocationContext from "../../McpInvocationContext.ts";
18 import * as DeviceService from "../../../device/DeviceService.ts";
@@ -45,7 +45,8 @@ const DeviceListTool = Tool.make("device_list", {
45 .annotate(Tool.Readonly, true)
46 .annotate(Tool.Destructive, false)
47 .annotate(Tool.Idempotent, true)
48 - .annotate(Tool.OpenWorld, false);
48 + .annotate(Tool.OpenWorld, false)
49 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
50
51 const DeviceOpenTool = Tool.make("device_open", {
52 description:
@@ -66,7 +67,8 @@ const DeviceOpenTool = Tool.make("device_open", {
67 .annotate(Tool.Readonly, false)
68 .annotate(Tool.Destructive, false)
69 .annotate(Tool.Idempotent, true)
69 - .annotate(Tool.OpenWorld, true);
70 + .annotate(Tool.OpenWorld, true)
71 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
72
73 export const DeviceScreenshotTool = Tool.make("device_screenshot", {
74 description:
@@ -80,7 +82,8 @@ export const DeviceScreenshotTool = Tool.make("device_screenshot", {
82 .annotate(Tool.Readonly, true)
83 .annotate(Tool.Destructive, false)
84 .annotate(Tool.Idempotent, true)
83 - .annotate(Tool.OpenWorld, true);
85 + .annotate(Tool.OpenWorld, true)
86 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
87
88 const DeviceCloseTool = Tool.make("device_close", {
89 description:
@@ -94,7 +97,8 @@ const DeviceCloseTool = Tool.make("device_close", {
97 .annotate(Tool.Readonly, false)
98 .annotate(Tool.Destructive, true)
99 .annotate(Tool.Idempotent, true)
97 - .annotate(Tool.OpenWorld, true);
100 + .annotate(Tool.OpenWorld, true)
101 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
102
103 export const DeviceStandardToolkit = Toolkit.make(DeviceListTool, DeviceOpenTool, DeviceCloseTool);
104
apps/server/src/mcp/toolkits/html/tools.ts
+5 -3
@@ -10,7 +10,7 @@ import {
10 HTML_RENDER_TOOL_NAME,
11 } from "@t3tools/shared/htmlRender";
12 import * as Schema from "effect/Schema";
13 -import { Tool, Toolkit } from "effect/ai";
13 +import { McpSchema, Tool, Toolkit } from "effect/ai";
14
15 import * as HtmlRender from "../../../htmlRender/HtmlRender.ts";
16 import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
@@ -72,7 +72,8 @@ export const HtmlPreviewTool = Tool.make("html_preview", {
72 .annotate(Tool.Readonly, true)
73 .annotate(Tool.Destructive, false)
74 .annotate(Tool.Idempotent, true)
75 - .annotate(Tool.OpenWorld, true);
75 + .annotate(Tool.OpenWorld, true)
76 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
77
78 // This affects only the caller's thread, not its workspace, so read-only sandboxes and plan mode may use it.
79 const HtmlRenderTool = Tool.make(HTML_RENDER_TOOL_NAME, {
@@ -109,7 +110,8 @@ const HtmlRenderTool = Tool.make(HTML_RENDER_TOOL_NAME, {
110 .annotate(Tool.Readonly, true)
111 .annotate(Tool.Destructive, false)
112 .annotate(Tool.Idempotent, false)
112 - .annotate(Tool.OpenWorld, true);
113 + .annotate(Tool.OpenWorld, true)
114 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
115
116 export const HtmlPreviewToolkit = Toolkit.make(HtmlPreviewTool);
117
apps/server/src/mcp/toolkits/message/tools.ts
+2 -1
@@ -1,7 +1,7 @@
1 import { OrchestratorMcpFailure } from "@t3tools/contracts";
2 import { SEND_TO_USER_MAX_LENGTH, SEND_TO_USER_TOOL_NAME } from "@t3tools/shared/toolOutput";
3 import * as Schema from "effect/Schema";
4 -import { Tool, Toolkit } from "effect/ai";
4 +import { McpSchema, Tool, Toolkit } from "effect/ai";
5
6 import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
7 import * as McpInvocationContext from "../../McpInvocationContext.ts";
@@ -33,6 +33,7 @@ const SendToUserTool = Tool.make(SEND_TO_USER_TOOL_NAME, {
33 .annotate(Tool.Destructive, false)
34 .annotate(Tool.Idempotent, false)
35 .annotate(Tool.OpenWorld, false)
36 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients)
37 // Claude Code defers MCP tools behind ToolSearch; Anthropic says to declare this from the first request.
38 .annotate(Tool.Meta, { "anthropic/alwaysLoad": true });
39
apps/server/src/mcp/toolkits/orchestrator/tools.ts
+12 -6
@@ -97,7 +97,8 @@ const DelegateTaskTool = Tool.make("delegate_task", {
97 })
98 .annotate(Tool.Title, "Delegate a child task")
99 .annotate(Tool.Destructive, true)
100 - .annotate(Tool.OpenWorld, true);
100 + .annotate(Tool.OpenWorld, true)
101 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
102
103 const TaskStatusTool = Tool.make("task_status", {
104 description:
@@ -111,7 +112,8 @@ const TaskStatusTool = Tool.make("task_status", {
112 .annotate(Tool.Title, "Get delegated task status")
113 .annotate(Tool.Readonly, false)
114 .annotate(Tool.Destructive, false)
114 - .annotate(Tool.Idempotent, true);
115 + .annotate(Tool.Idempotent, true)
116 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
117
118 const TaskCancelTool = Tool.make("task_cancel", {
119 description:
@@ -123,7 +125,8 @@ const TaskCancelTool = Tool.make("task_cancel", {
125 dependencies,
126 })
127 .annotate(Tool.Title, "Cancel delegated task")
126 - .annotate(Tool.Destructive, true);
128 + .annotate(Tool.Destructive, true)
129 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
130
131 const WorkflowStopTool = Tool.make("t3_workflow_stop", {
132 description:
@@ -161,7 +164,8 @@ const BackgroundWaitTool = Tool.make("t3_background_wait", {
164 .annotate(Tool.Title, "Wait on background work")
165 // Only marks which tasks keep the thread Working; Claude Plan mode blocks tools without this.
166 .annotate(Tool.Readonly, true)
164 - .annotate(Tool.Destructive, false);
167 + .annotate(Tool.Destructive, false)
168 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
169
170 const ScheduleTaskTool = Tool.make("schedule_task", {
171 description:
@@ -214,7 +218,8 @@ const RequestSecretTool = Tool.make("request_secret", {
218 .annotate(Tool.Title, "Request a secret from the user")
219 .annotate(Tool.Destructive, false)
220 // Claude Code defers MCP tools behind ToolSearch; agents that never load this one ask in chat.
217 - .annotate(Tool.Meta, { "anthropic/alwaysLoad": true });
221 + .annotate(Tool.Meta, { "anthropic/alwaysLoad": true })
222 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
223
224 const CreateThreadsTool = Tool.make("create_threads", {
225 description:
@@ -227,7 +232,8 @@ const CreateThreadsTool = Tool.make("create_threads", {
232 })
233 .annotate(Tool.Title, "Create T3 threads")
234 .annotate(Tool.Destructive, true)
230 - .annotate(Tool.OpenWorld, true);
235 + .annotate(Tool.OpenWorld, true)
236 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
237
238 const ThreadListTool = Tool.make("t3_thread_list", {
239 description:
apps/server/src/mcp/toolkits/preview/tools.ts
+11 -4
@@ -23,7 +23,7 @@ import {
23 } from "@t3tools/contracts";
24 import * as Schema from "effect/Schema";
25 import * as FileSystem from "effect/FileSystem";
26 -import { Tool, Toolkit } from "effect/ai";
26 +import { McpSchema, Tool, Toolkit } from "effect/ai";
27
28 import * as McpInvocationContext from "../../McpInvocationContext.ts";
29 import * as PreviewAutomationBroker from "../../PreviewAutomationBroker.ts";
@@ -43,10 +43,16 @@ const presentationFields = { toolIcon: Schema.optional(ToolActivityIcon) };
43 const PreviewActionResult = Schema.Struct(presentationFields);
44
45 const browserTool = <T extends Tool.Any>(tool: T): T =>
46 - tool.annotate(Tool.OpenWorld, true).annotate(Tool.Destructive, true) as T;
46 + tool
47 + .annotate(Tool.OpenWorld, true)
48 + .annotate(Tool.Destructive, true)
49 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients) as T;
50
51 const safeBrowserTool = <T extends Tool.Any>(tool: T): T =>
49 - tool.annotate(Tool.OpenWorld, true).annotate(Tool.Destructive, false) as T;
52 + tool
53 + .annotate(Tool.OpenWorld, true)
54 + .annotate(Tool.Destructive, false)
55 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients) as T;
56
57 const readonlyBrowserTool = <T extends Tool.Any>(tool: T): T =>
58 safeBrowserTool(tool).annotate(Tool.Readonly, true).annotate(Tool.Idempotent, true) as T;
@@ -62,7 +68,8 @@ const PreviewStatusTool = Tool.make("preview_status", {
68 .annotate(Tool.Title, "Get preview status")
69 .annotate(Tool.Readonly, true)
70 .annotate(Tool.Destructive, false)
65 - .annotate(Tool.Idempotent, true);
71 + .annotate(Tool.Idempotent, true)
72 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
73
74 // `url` already covers websites, so open only adds the dev-server target.
75 const EnvironmentPortTarget = BrowserNavigationTarget.members[1];
apps/server/src/mcp/toolkits/previewControls/tools.ts
+6 -3
@@ -7,7 +7,7 @@ import {
7 PreviewTabId,
8 } from "@t3tools/contracts";
9 import * as Schema from "effect/Schema";
10 -import { Tool, Toolkit } from "effect/ai";
10 +import { McpSchema, Tool, Toolkit } from "effect/ai";
11 import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
12 import * as PreviewManager from "../../../preview/Manager.ts";
13 import * as PreviewAutomationBroker from "../../PreviewAutomationBroker.ts";
@@ -37,12 +37,15 @@ const PreviewListTool = Tool.make("t3_preview_list", {
37 }),
38 })
39 .annotate(Tool.Readonly, true)
40 - .annotate(Tool.Destructive, false);
40 + .annotate(Tool.Destructive, false)
41 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
42 const PreviewCloseTool = Tool.make("t3_preview_close", {
43 ...shared,
44 description:
45 "Close one preview tab this thread owns. Use it on a tab you opened for your own check when you finish.",
46 parameters: Schema.Struct({ tabId: PreviewTabId }),
47 success: Schema.Struct({}),
47 -}).annotate(Tool.Destructive, true);
48 +})
49 + .annotate(Tool.Destructive, true)
50 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
51 export const PreviewControlsToolkit = Toolkit.make(PreviewListTool, PreviewCloseTool);
apps/server/src/mcp/toolkits/toolSearch/tools.ts
+3 -2
@@ -1,6 +1,6 @@
1 import { OrchestratorMcpFailure } from "@t3tools/contracts";
2 import * as Schema from "effect/Schema";
3 -import { Tool, Toolkit } from "effect/ai";
3 +import { McpSchema, Tool, Toolkit } from "effect/ai";
4
5 import * as McpInvocationContext from "../../McpInvocationContext.ts";
6 import * as McpToolExposure from "../../McpToolExposure.ts";
@@ -17,6 +17,7 @@ const ToolSearchTool = Tool.make(McpToolExposure.TOOL_SEARCH, {
17 dependencies: [McpInvocationContext.McpInvocationContext, McpToolExposure.McpToolExposure],
18 })
19 .annotate(Tool.Readonly, true)
20 - .annotate(Tool.Destructive, false);
20 + .annotate(Tool.Destructive, false)
21 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
22
23 export const ToolSearchToolkit = Toolkit.make(ToolSearchTool);
apps/server/src/mcp/toolkits/worktree/tools.ts
+5 -3
@@ -12,7 +12,7 @@ import {
12 import * as Schema from "effect/Schema";
13 import * as ProjectService from "../../../project/ProjectService.ts";
14 import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
15 -import { Tool, Toolkit } from "effect/ai";
15 +import { McpSchema, Tool, Toolkit } from "effect/ai";
16
17 import * as McpInvocationContext from "../../McpInvocationContext.ts";
18 import * as WorktreeMcpService from "../../WorktreeMcpService.ts";
@@ -38,7 +38,8 @@ const WorktreeHandoffTool = Tool.make("t3_worktree_handoff", {
38 .annotate(Tool.Readonly, false)
39 .annotate(Tool.Destructive, true)
40 .annotate(Tool.Idempotent, false)
41 - .annotate(Tool.OpenWorld, true);
41 + .annotate(Tool.OpenWorld, true)
42 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
43
44 const WorktreeStatusTool = Tool.make("t3_worktree_status", {
45 description:
@@ -56,7 +57,8 @@ const WorktreeStatusTool = Tool.make("t3_worktree_status", {
57 .annotate(Tool.Readonly, true)
58 .annotate(Tool.Destructive, false)
59 .annotate(Tool.Idempotent, true)
59 - .annotate(Tool.OpenWorld, false);
60 + .annotate(Tool.OpenWorld, false)
61 + .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
62
63 const WorktreeListTool = Tool.make("t3_worktree_list", {
64 description:
docs/internals/environment-auth.md
+6
@@ -65,6 +65,12 @@ above its ceiling. Inside MCP the credential sets the limits and tool
65 parameters only pick targets; see
66 [threadAccess](../../apps/server/src/mcp/threadAccess.ts).
67
68 +These clients have no calling thread, so `/mcp` does not offer them tools that
69 +act as one, such as `request_secret` or `delegate_task`. Hiding is only
70 +discovery: the handlers still refuse such a call with
71 +`thread_credential_required`. A secret card belongs to a thread's run, so an
72 +outside agent that needs a secret starts a thread and lets that agent ask.
73 +
74 Issuer and resource URLs come from the request's Host and
75 `X-Forwarded-Proto`, so one server answers over loopback, Tailscale Serve and a
76 T3 Connect tunnel. A proxy that rewrites Host or drops the protocol header