Skip to content

Commit d437550

Browse files
feat(server): outside MCP clients get the same thread link Copy thread copies
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent c4186d0 commit d437550

4 files changed

Lines changed: 27 additions & 18 deletions

File tree

‎apps/server/src/auth/McpOAuth.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
mcpClientScopes,
1818
type RuntimeMode,
1919
} from "@t3tools/contracts";
20+
import { DEFAULT_HOSTED_APP_URL } from "@t3tools/shared/connectAuth";
2021
import { encodeOAuthScope } from "@t3tools/shared/oauthScope";
2122
import * as Clock from "effect/Clock";
2223
import * as Context from "effect/Context";
@@ -29,6 +30,7 @@ import * as Ref from "effect/Ref";
2930
import * as Schema from "effect/Schema";
3031
import { HttpServerRequest } from "effect/http";
3132

33+
import { hostedAppUrlConfig } from "../cloud/publicConfig.ts";
3234
import * as ServerEnvironment from "../environment/ServerEnvironment.ts";
3335
import * as ServerSettings from "../serverSettings.ts";
3436
import * as McpHttpServer from "../mcp/McpHttpServer.ts";
@@ -576,6 +578,13 @@ export const layerMcpClientAuthenticator = Layer.effect(
576578
const environmentAuth = yield* EnvironmentAuth.EnvironmentAuth;
577579
const environment = yield* ServerEnvironment.ServerEnvironment;
578580
const environmentId = yield* environment.getEnvironmentId;
581+
const hostedAppUrl = yield* hostedAppUrlConfig.pipe(
582+
Effect.catch((cause) =>
583+
Effect.logWarning("Outside MCP clients get app.t3.codes thread links", { cause }).pipe(
584+
Effect.as(DEFAULT_HOSTED_APP_URL),
585+
),
586+
),
587+
);
579588
return McpHttpServer.McpClientAuthenticator.of({
580589
authenticate: Effect.fn("McpHttpServer.McpClientAuthenticator.authenticate")(
581590
function (request) {
@@ -591,7 +600,7 @@ export const layerMcpClientAuthenticator = Layer.effect(
591600
label: client.label,
592601
access: client.access,
593602
linked: client.peerLink,
594-
...(client.peerLink ? {} : { webOrigin: requestUrls(request).issuer }),
603+
...(client.peerLink ? {} : { hostedAppUrl }),
595604
},
596605
capabilities: new Set<McpInvocationContext.McpCapability>([
597606
"orchestration",

‎apps/server/src/mcp/McpInvocationContext.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import * as Context from "effect/Context";
1313
import * as Effect from "effect/Effect";
1414
import * as Fiber from "effect/Fiber";
15-
import { formatThreadLink } from "@t3tools/shared/threadLinks";
15+
import { formatThreadLink, hostedThreadLink } from "@t3tools/shared/threadLinks";
1616

1717
const ALL_MCP_CAPABILITIES = [
1818
"preview",
@@ -45,8 +45,8 @@ export interface McpClientCaller {
4545
* another environment passing on the limits of the agent it calls for.
4646
*/
4747
readonly narrowedTo?: ClientModes | undefined;
48-
/** The origin an outside client reached; its thread links open the web app there. */
49-
readonly webOrigin?: string | undefined;
48+
/** An outside client's thread links go through this hosted app, as Copy thread's do. */
49+
readonly hostedAppUrl?: string | undefined;
5050
}
5151

5252
/**
@@ -135,16 +135,15 @@ export interface McpInvocationScope {
135135

136136
/**
137137
* T3 Code renders `t3-thread://` links as thread chips. Other MCP clients cannot open them, so
138-
* they get a web URL on the origin they reached instead.
138+
* they get the hosted link Copy thread copies, which opens the thread in either app or a browser.
139139
*/
140140
export const threadLinkFor = (
141141
scope: Pick<McpInvocationScope, "environmentId" | "client">,
142142
threadId: ThreadId,
143143
): string => {
144-
const origin = scope.client?.webOrigin;
145-
return origin === undefined
146-
? formatThreadLink({ environmentId: scope.environmentId, threadId })
147-
: `${origin}/${encodeURIComponent(scope.environmentId)}/${encodeURIComponent(threadId)}`;
144+
const hostedAppUrl = scope.client?.hostedAppUrl;
145+
const ref = { environmentId: scope.environmentId, threadId };
146+
return hostedAppUrl === undefined ? formatThreadLink(ref) : hostedThreadLink(ref, hostedAppUrl);
148147
};
149148

150149
export class McpInvocationContext extends Context.Service<

‎apps/server/src/mcp/toolkits/project/handlers.test.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const clientLaunchHarness = (input: {
5050
readonly launched: Array<ThreadLaunch.ThreadLaunchInput>;
5151
readonly workspaceRoot?: string;
5252
readonly checkWorktreeBase?: ThreadLaunch.ThreadLaunchService["Service"]["checkWorktreeBase"];
53-
readonly webOrigin?: string;
53+
readonly hostedAppUrl?: string;
5454
/** The orchestrator refuses the new thread's mode, as under a managed ceiling. */
5555
readonly refusedByCeiling?: true;
5656
}) => {
@@ -90,7 +90,7 @@ const clientLaunchHarness = (input: {
9090
sessionId: "session-1",
9191
label: "Claude Code",
9292
access: input.runtimeModeCeiling,
93-
webOrigin: input.webOrigin,
93+
hostedAppUrl: input.hostedAppUrl,
9494
},
9595
issuedAt: 0,
9696
capabilities: new Set(["orchestration" as const]),
@@ -188,18 +188,18 @@ it.effect(
188188
readonly runtimeMode?: RuntimeMode;
189189
readonly targeted?: false;
190190
readonly overrideModel?: ModelSelection;
191-
readonly webOrigin?: string;
191+
readonly hostedAppUrl?: string;
192192
readonly refusedByCeiling?: true;
193193
},
194194
) {
195-
const { targeted, overrideModel, webOrigin, refusedByCeiling, ...input } = params;
195+
const { targeted, overrideModel, hostedAppUrl, refusedByCeiling, ...input } = params;
196196
const launched: Array<ThreadLaunch.ThreadLaunchInput> = [];
197197
const { projectId, modelSelection, dependencies } = clientLaunchHarness({
198198
runtimeModeCeiling,
199199
defaultRuntimeMode,
200200
launched,
201201
...(overrideModel === undefined ? {} : { overrideModel }),
202-
...(webOrigin === undefined ? {} : { webOrigin }),
202+
...(hostedAppUrl === undefined ? {} : { hostedAppUrl }),
203203
...(refusedByCeiling === undefined ? {} : { refusedByCeiling }),
204204
});
205205
const toolkit = yield* ProjectToolkit.pipe(
@@ -229,11 +229,11 @@ it.effect(
229229

230230
const aboveCeiling = yield* launchWith("auto-accept-edits", "full-access", {
231231
title: "Fix",
232-
webOrigin: "https://box.example.ts.net",
232+
hostedAppUrl: "https://t3.example.com",
233233
});
234234
expect(aboveCeiling.launched[0]?.runtimeMode).toBe("auto-accept-edits");
235235
expect(aboveCeiling.result).toMatchObject({
236-
link: `https://box.example.ts.net/environment/${encodeURIComponent(aboveCeiling.launched[0]?.threadId ?? "")}`,
236+
link: `https://t3.example.com/threads/environment/${encodeURIComponent(aboveCeiling.launched[0]?.threadId ?? "")}`,
237237
});
238238

239239
const requested = yield* launchWith("full-access", "approval-required", {

‎docs/orchestration-v2/orchestrator-mcp-server.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,9 @@ know renders as a label that opens nothing. Older `t3-thread://v1/<threadId>`
406406
links name no environment: clients resolve them in the message's environment,
407407
then by a unique match in another enabled environment. An outside OAuth client,
408408
one that is not a linked environment, cannot render `t3-thread://` links, so it
409-
gets a web URL on the origin it reached, `<origin>/<environmentId>/<threadId>`,
410-
for threads in this environment.
409+
gets the link Copy thread copies, `https://app.t3.codes/threads/<environmentId>/<threadId>`
410+
on the server's `T3CODE_HOSTED_APP_URL`, for threads in this environment. The
411+
hosted app offers the desktop app, the mobile app, or itself.
411412

412413
List and read results report `snoozed` and `snoozedUntil`, and
413414
`t3_thread_list` filters on `snoozed`. The server's `isSnoozed` follows the

0 commit comments

Comments
 (0)