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 22, 13:15 UTC
fix(server): outside MCP clients get thread links they can open (#26642)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 28, 2026 at 17:12 UTC
26caea23c0fa849baa99502791a3626ad5a1d4ca
7 files changed
+51
-18
apps/server/src/auth/McpOAuth.ts
+1
@@ -573,6 +573,7 @@ export const layerMcpClientAuthenticator = Layer.effect(
573
label: client.label,
574
access: client.access,
575
linked: client.peerLink,
576
+ ...(client.peerLink ? {} : { webOrigin: requestUrls(request).issuer }),
577
},
578
capabilities: new Set<McpInvocationContext.McpCapability>([
579
"orchestration",
apps/server/src/mcp/McpInvocationContext.ts
+17
@@ -12,6 +12,7 @@ import {
12
import * as Context from "effect/Context";
13
import * as Effect from "effect/Effect";
14
import * as Fiber from "effect/Fiber";
15
+import { formatThreadLink } from "@t3tools/shared/threadLinks";
16
17
const ALL_MCP_CAPABILITIES = [
18
"preview",
@@ -44,6 +45,8 @@ export interface McpClientCaller {
45
* another environment passing on the limits of the agent it calls for.
46
*/
47
readonly narrowedTo?: ClientModes | undefined;
48
+ /** The origin an outside client reached; its thread links open the web app there. */
49
+ readonly webOrigin?: string | undefined;
50
}
51
52
/**
@@ -105,6 +108,20 @@ export interface McpInvocationScope {
108
readonly linkedEnvironments?: boolean;
109
}
110
111
+/**
112
+ * T3 Code renders `t3-thread://` links as thread chips. Other MCP clients cannot open them, so
113
+ * they get a web URL on the origin they reached instead.
114
+ */
115
+export const threadLinkFor = (
116
+ scope: Pick<McpInvocationScope, "environmentId" | "client">,
117
+ threadId: ThreadId,
118
+): string => {
119
+ const origin = scope.client?.webOrigin;
120
+ return origin === undefined
121
+ ? formatThreadLink({ environmentId: scope.environmentId, threadId })
122
+ : `${origin}/${encodeURIComponent(scope.environmentId)}/${encodeURIComponent(threadId)}`;
123
+};
124
+
125
export class McpInvocationContext extends Context.Service<
126
McpInvocationContext,
127
McpInvocationScope
apps/server/src/mcp/OrchestratorMcpService.ts
+8
-8
@@ -1,6 +1,5 @@
1
import {
2
CommandId,
3
- type EnvironmentId,
3
type RunId,
4
isProviderAvailable,
5
MessageId,
@@ -108,6 +107,7 @@ import {
107
type McpInvocationScope,
108
type McpThreadInvocationScope,
109
requireThreadScope,
110
+ threadLinkFor,
111
} from "./McpInvocationContext.ts";
112
import * as Metrics from "../observability/Metrics.ts";
113
import {
@@ -752,7 +752,7 @@ function threadPullRequests(
752
}
753
754
function listItemFromShell(
755
- environmentId: EnvironmentId,
755
+ scope: McpInvocationScope,
756
shell: OrchestrationV2ThreadShell,
757
nowMs: number,
758
): OrchestratorMcpThreadListItem {
@@ -760,7 +760,7 @@ function listItemFromShell(
760
threadId: shell.id,
761
projectId: shell.projectId,
762
title: shell.title,
763
- link: formatThreadLink({ environmentId, threadId: shell.id }),
763
+ link: threadLinkFor(scope, shell.id),
764
createdBy: shell.createdBy,
765
creationSource: shell.creationSource,
766
status: shell.activityRunStatus ?? shell.status,
@@ -782,7 +782,7 @@ function listItemFromShell(
782
}
783
784
function threadDetail(
785
- environmentId: EnvironmentId,
785
+ scope: McpInvocationScope,
786
projection: Pick<OrchestrationV2ThreadProjection, "thread" | "runs" | "runtimeRequests">,
787
itemCount: number,
788
shell: OrchestrationV2ThreadShell,
@@ -794,7 +794,7 @@ function threadDetail(
794
threadId: projection.thread.id,
795
projectId: projection.thread.projectId,
796
title: projection.thread.title,
797
- link: formatThreadLink({ environmentId, threadId: projection.thread.id }),
797
+ link: threadLinkFor(scope, projection.thread.id),
798
createdBy: projection.thread.createdBy,
799
creationSource: projection.thread.creationSource,
800
status: active?.status ?? latest?.status ?? "idle",
@@ -2806,7 +2806,7 @@ const make = Effect.gen(function* () {
2806
return {
2807
projectId,
2808
currentThreadId: parent?.thread.id ?? null,
2809
- threads: page.map((shell) => listItemFromShell(scope.environmentId, shell, nowMs)),
2809
+ threads: page.map((shell) => listItemFromShell(scope, shell, nowMs)),
2810
nextCursor,
2811
total: filtered.length,
2812
} satisfies OrchestratorMcpThreadListResult;
@@ -2887,7 +2887,7 @@ const make = Effect.gen(function* () {
2887
}
2888
return {
2889
thread: threadDetail(
2890
- scope.environmentId,
2890
+ scope,
2891
target,
2892
timeline.totalItems,
2893
shell,
@@ -2951,7 +2951,7 @@ const make = Effect.gen(function* () {
2951
);
2952
return {
2953
threadId: input.threadId,
2954
- link: formatThreadLink({ environmentId: scope.environmentId, threadId: input.threadId }),
2954
+ link: threadLinkFor(scope, input.threadId),
2955
messageId,
2956
runId: result.run.id,
2957
...(result.run.delegatedTaskId === undefined ? {} : { taskId: result.run.delegatedTaskId }),
apps/server/src/mcp/toolkits/project/handlers.test.ts
+12
-2
@@ -42,6 +42,7 @@ const clientLaunchHarness = (input: {
42
readonly launched: Array<ThreadLaunch.ThreadLaunchInput>;
43
readonly workspaceRoot?: string;
44
readonly checkWorktreeBase?: ThreadLaunch.ThreadLaunchService["Service"]["checkWorktreeBase"];
45
+ readonly webOrigin?: string;
46
}) => {
47
const projectId = ProjectId.make("project:client-target");
48
const modelSelection = {
@@ -75,6 +76,7 @@ const clientLaunchHarness = (input: {
76
sessionId: "session-1",
77
label: "Claude Code",
78
access: input.runtimeModeCeiling,
79
+ webOrigin: input.webOrigin,
80
},
81
issuedAt: 0,
82
capabilities: new Set(["orchestration" as const]),
@@ -155,15 +157,17 @@ it.effect(
157
readonly runtimeMode?: RuntimeMode;
158
readonly targeted?: false;
159
readonly overrideModel?: ModelSelection;
160
+ readonly webOrigin?: string;
161
},
162
) {
160
- const { targeted, overrideModel, ...input } = params;
163
+ const { targeted, overrideModel, webOrigin, ...input } = params;
164
const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];
165
const { projectId, modelSelection, dependencies } = clientLaunchHarness({
166
runtimeModeCeiling,
167
defaultRuntimeMode,
168
launched,
169
...(overrideModel === undefined ? {} : { overrideModel }),
170
+ ...(webOrigin === undefined ? {} : { webOrigin }),
171
});
172
const toolkit = yield* ProjectToolkit.pipe(
173
Effect.provide(
@@ -190,8 +194,14 @@ it.effect(
194
expect(belowCeiling.launched[0]?.runtimeMode).toBe("approval-required");
195
expect(belowCeiling.launched[0]?.initialMessage?.senderThreadId).toBeUndefined();
196
193
- const aboveCeiling = yield* launchWith("auto-accept-edits", "full-access", { title: "Fix" });
197
+ const aboveCeiling = yield* launchWith("auto-accept-edits", "full-access", {
198
+ title: "Fix",
199
+ webOrigin: "https://box.example.ts.net",
200
+ });
201
expect(aboveCeiling.launched[0]?.runtimeMode).toBe("auto-accept-edits");
202
+ expect(aboveCeiling.result).toMatchObject({
203
+ link: `https://box.example.ts.net/environment/${encodeURIComponent(aboveCeiling.launched[0]?.threadId ?? "")}`,
204
+ });
205
206
const requested = yield* launchWith("full-access", "approval-required", {
207
title: "Fix",
apps/server/src/mcp/toolkits/project/handlers.ts
+1
-2
@@ -19,7 +19,6 @@ import * as Repositories from "../../../sourceControl/SourceControlRepositorySer
19
import * as GitVcsDriver from "../../../vcs/GitVcsDriver.ts";
20
import * as ServerSettings from "../../../serverSettings.ts";
21
import { resolveProjectSettings } from "@t3tools/shared/projectSettings";
22
-import { formatThreadLink } from "@t3tools/shared/threadLinks";
22
import { resolveRuntimeMode } from "../../delegatedTaskModes.ts";
23
import * as McpInvocationContext from "../../McpInvocationContext.ts";
24
import * as McpToolAccess from "../../McpToolAccess.ts";
@@ -240,7 +239,7 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, {
239
const run = result.projection.runs.find((run) => run.userMessageId === messageId);
240
return {
241
threadId: thread.id,
243
- link: formatThreadLink({ environmentId: scope.environmentId, threadId: thread.id }),
242
+ link: McpInvocationContext.threadLinkFor(scope, thread.id),
243
projectId: thread.projectId,
244
modelSelection: thread.modelSelection,
245
runId: run?.id ?? null,
apps/server/src/mcp/toolkits/thread/handlers.ts
+8
-5
@@ -9,7 +9,6 @@ import {
9
} from "@t3tools/contracts";
10
import * as Effect from "effect/Effect";
11
import { modelSelectionCommandType } from "@t3tools/shared/model";
12
-import { formatThreadLink } from "@t3tools/shared/threadLinks";
12
13
import * as McpInvocationContext from "../../McpInvocationContext.ts";
14
import * as McpToolAccess from "../../McpToolAccess.ts";
@@ -104,11 +103,15 @@ export const layer = McpToolAccess.toLayer(ThreadToolkit, {
103
const { task, threadId } = yield* scheduler
104
.runNow({ id: input.taskId })
105
.pipe(Effect.mapError(unavailable));
107
- const { environmentId } = yield* McpInvocationContext.McpInvocationContext;
106
+ const scope = yield* McpInvocationContext.McpInvocationContext;
107
return {
108
taskId: task.id,
109
threadId,
111
- ...(threadId === null ? {} : { link: formatThreadLink({ environmentId, threadId }) }),
110
+ ...(threadId === null
111
+ ? {}
112
+ : {
113
+ link: McpInvocationContext.threadLinkFor(scope, threadId),
114
+ }),
115
lastRunStatus: task.lastRunStatus,
116
runCount: task.runCount,
117
nextRunAt: task.nextRunAt,
@@ -118,7 +121,7 @@ export const layer = McpToolAccess.toLayer(ThreadToolkit, {
121
t3_thread_search: McpToolAccess.reads((input) =>
122
Effect.gen(function* () {
123
const { caller } = yield* readCaller();
121
- const { environmentId } = yield* McpInvocationContext.McpInvocationContext;
124
+ const scope = yield* McpInvocationContext.McpInvocationContext;
125
const threadSearch = yield* ThreadSearch.ThreadSearch;
126
const { matches } = yield* threadSearch
127
.searchThreads({ ...input, projectId: input.projectId ?? caller?.projectId })
@@ -126,7 +129,7 @@ export const layer = McpToolAccess.toLayer(ThreadToolkit, {
129
return {
130
matches: matches.map((match) => ({
131
...match,
129
- link: formatThreadLink({ environmentId, threadId: match.threadId }),
132
+ link: McpInvocationContext.threadLinkFor(scope, match.threadId),
133
})),
134
};
135
}),
docs/orchestration-v2/orchestrator-mcp-server.md
+4
-1
@@ -398,7 +398,10 @@ delegated to a linked environment name that environment. Clients open only that
398
environment's thread and show its current title; a link to a thread they do not
399
know renders as a label that opens nothing. Older `t3-thread://v1/<threadId>`
400
links name no environment: clients resolve them in the message's environment,
401
-then by a unique match in another enabled environment.
401
+then by a unique match in another enabled environment. An outside OAuth client,
402
+one that is not a linked environment, cannot render `t3-thread://` links, so it
403
+gets a web URL on the origin it reached, `<origin>/<environmentId>/<threadId>`,
404
+for threads in this environment.
405
406
List and read results report `snoozed` and `snoozedUntil`, and
407
`t3_thread_list` filters on `snoozed`. The server's `isSnoozed` follows the