Skip to content

Commit f644e7f

Browse files
PR Batch Testerclaude
andcommitted
fix(web,server): this machine's menu copies the MCP URL its tunnel serves
Settings > Connections had no Copy MCP URL for the local machine, so the only one on offer sat on a saved T3 Connect row with the same name. That row is a different environment, and when its tunnel is gone the copied host answers Cloudflare 1033. The server's T3 Connect check now reports the host the running tunnel answered on. The local machine's menu and `t3 connect status` build the MCP URL from it. Refs #23709 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b9aaff4 commit f644e7f

7 files changed

Lines changed: 83 additions & 20 deletions

File tree

‎apps/server/src/cli/connect.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
AuthRelayReadScope,
33
AuthRelayWriteScope,
44
type AuthEnvironmentScope,
5+
connectReachableMcpUrl,
56
type EnvironmentConnectReachability,
67
EnvironmentHttpApi,
78
formatConnectReachable,
@@ -199,6 +200,10 @@ function formatCloudStatus(status: CloudCliStatus, options?: { readonly json?: b
199200
: !status.linked
200201
? "Start T3 to provision the environment link and launch its managed tunnel."
201202
: undefined;
203+
const mcpUrl =
204+
status.reachability?.status === "reachable"
205+
? connectReachableMcpUrl(status.reachability)
206+
: null;
202207

203208
return [
204209
"T3 Connect",
@@ -219,6 +224,7 @@ function formatCloudStatus(status: CloudCliStatus, options?: { readonly json?: b
219224
? [
220225
"",
221226
`✓ Other devices can reach this machine · ${formatConnectReachable(status.reachability)}`,
227+
...(mcpUrl ? [` MCP URL for outside agents: ${mcpUrl}`] : []),
222228
]
223229
: ["", formatReachabilityFailure(status.reachability)]),
224230
...(nextStep ? ["", `Next: ${nextStep}`] : []),

‎apps/server/src/cloud/ConnectReachability.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @effect-diagnostics nodeBuiltinImport:off - reads the user guide to check its anchors.
22
import * as NodeFS from "node:fs";
33

4-
import { T3_CONNECT_TROUBLESHOOTING_SECTIONS } from "@t3tools/contracts";
4+
import { T3_CONNECT_TROUBLESHOOTING_SECTIONS, connectReachableMcpUrl } from "@t3tools/contracts";
55
import { describe, expect, it } from "@effect/vitest";
66

77
import { classifyReachability, type ReachabilityFacts } from "./ConnectReachability.ts";
@@ -60,6 +60,17 @@ describe("classifyReachability", () => {
6060
).toMatchObject({ cause: "dns_failed" });
6161
});
6262

63+
it("gives the MCP URL on the host the running tunnel answered on", () => {
64+
const result = classifyReachability(
65+
facts({ endpoint: { kind: "status", status: 200 } }),
66+
checkedAt,
67+
);
68+
expect(result).toMatchObject({ status: "reachable", hostname: "env.example.test" });
69+
expect(result.status === "reachable" && connectReachableMcpUrl(result)).toBe(
70+
"https://env.example.test/mcp",
71+
);
72+
});
73+
6374
it("waits on a connector that has not connected while the edge answers", () => {
6475
expect(
6576
classifyReachability(facts({ connector: notConnected, edgeReachable: true }), checkedAt),

‎apps/server/src/cloud/ConnectReachability.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export function classifyReachability(
8888
checkedAt,
8989
readyConnections: connector.readyConnections,
9090
protocol: connector.protocol,
91+
...(connector.hostname ? { hostname: connector.hostname } : {}),
9192
};
9293
}
9394
// The edge test is TCP only. With QUIC connections up, a 502 from a working tunnel, or

‎apps/web/src/components/settings/ConnectionsSettings.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import {
130130
import {
131131
CloudLinkRow,
132132
CloudRemoteEnvironmentRows,
133+
PrimaryMcpUrlMenuItem,
133134
SavedBackendListRow,
134135
} from "./SavedEnvironmentRows";
135136
import { AddEnvironmentDialog } from "./AddEnvironmentDialog";
@@ -1069,6 +1070,7 @@ export function ConnectionsSettings() {
10691070
environmentId={primaryEnvironmentId}
10701071
serverConfig={primaryServerConfig}
10711072
/>
1073+
<PrimaryMcpUrlMenuItem />
10721074
</MenuPopup>
10731075
</Menu>
10741076
) : null

‎apps/web/src/components/settings/SavedEnvironmentRows.tsx‎

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
AuthRelayWriteScope,
1212
type EnvironmentId,
1313
connectReachabilityHelpUrl,
14+
connectReachableMcpUrl,
1415
formatConnectReachable,
1516
resolveEnvironmentMachineKind,
1617
} from "@t3tools/contracts";
@@ -48,6 +49,7 @@ import {
4849
supportsServerUpdateThreadContinuation,
4950
} from "~/versionSkew";
5051
import { hasCloudPublicConfig } from "~/cloud/publicConfig";
52+
import { usePrimaryCloudLinkState } from "~/cloud/primaryCloudLinkState";
5153
import { useCloudLinkController } from "~/cloud/useCloudLinkController";
5254
import { environmentCatalog } from "~/connection/catalog";
5355
import { readEnvironmentScope } from "~/state/session";
@@ -105,6 +107,45 @@ function savedBackendStatus(environment: EnvironmentPresentation): {
105107
}
106108
}
107109

110+
function useCopyMcpUrl() {
111+
return useCopyToClipboard<{ url: string }>({
112+
target: "MCP URL",
113+
onCopy: ({ url }) => {
114+
toastManager.add({
115+
type: "success",
116+
title: "MCP URL copied",
117+
description: `Add it to an agent, e.g. claude mcp add --transport http t3 ${url}`,
118+
});
119+
},
120+
onError: (error) => {
121+
toastManager.add(
122+
stackedThreadToast({
123+
type: "error",
124+
title: "Could not copy MCP URL",
125+
description: error.message,
126+
}),
127+
);
128+
},
129+
}).copyToClipboard;
130+
}
131+
132+
/**
133+
* This machine's T3 Connect MCP URL, from the host its running tunnel answered on. Shown only
134+
* after a passing check, so it never hands out an address nothing serves.
135+
*/
136+
export function PrimaryMcpUrlMenuItem() {
137+
const { data } = usePrimaryCloudLinkState();
138+
const copyMcpUrl = useCopyMcpUrl();
139+
const reachability =
140+
data && data.managedTunnelActive !== false && data.linkRevoked !== true
141+
? data.reachability
142+
: undefined;
143+
const mcpUrl = reachability?.status === "reachable" ? connectReachableMcpUrl(reachability) : null;
144+
return mcpUrl ? (
145+
<MenuItem onClick={() => copyMcpUrl(mcpUrl, { url: mcpUrl })}>Copy MCP URL</MenuItem>
146+
) : null;
147+
}
148+
108149
export function SavedBackendListRow({
109150
environment,
110151
removingEnvironmentId,
@@ -144,25 +185,7 @@ export function SavedBackendListRow({
144185
const copyTraceId = (traceId: string) => {
145186
copyTraceIdToClipboard(traceId, { traceId });
146187
};
147-
const { copyToClipboard: copyMcpUrl } = useCopyToClipboard<{ url: string }>({
148-
target: "MCP URL",
149-
onCopy: ({ url }) => {
150-
toastManager.add({
151-
type: "success",
152-
title: "MCP URL copied",
153-
description: `Add it to an agent, e.g. claude mcp add --transport http t3 ${url}`,
154-
});
155-
},
156-
onError: (error) => {
157-
toastManager.add(
158-
stackedThreadToast({
159-
type: "error",
160-
title: "Could not copy MCP URL",
161-
description: error.message,
162-
}),
163-
);
164-
},
165-
});
188+
const copyMcpUrl = useCopyMcpUrl();
166189
const versionMismatch = resolveServerConfigVersionMismatch(environment.serverConfig);
167190
const serverUpdateState = useAtomValue(serverEnvironment.updateStateAtom(environmentId));
168191
const resumingServerUpdate =

‎docs/user/outside-agents.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ https://<environment-address>/mcp
1919
The copied URL uses the route this device is connected over, so an agent on the
2020
same device can reach it.
2121

22+
For the machine you are on, open the menu next to its name at the top of
23+
**Settings → Connections** instead. Once T3 Connect has checked that other
24+
devices can reach it, **Copy MCP URL** there gives the T3 Connect address its
25+
tunnel is serving. `t3 connect status` prints the same URL. A saved environment
26+
with the same name is a different environment, often an older install whose
27+
tunnel is gone.
28+
2229
- **An agent on your own computers** can use `localhost` on the host, T3
2330
Connect, or any `https` address, such as
2431
[Tailscale HTTPS](./remote-access.md#tailscale-https). Signing in sends the

‎packages/contracts/src/environmentHttp.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ export const EnvironmentConnectReachability = Schema.Union([
429429
/** Null when cloudflared did not report a count. */
430430
readyConnections: Schema.NullOr(Schema.Int),
431431
protocol: Schema.NullOr(Schema.String),
432+
/** The tunnel hostname that answered. Older servers leave it out. */
433+
hostname: Schema.optional(Schema.String),
432434
}),
433435
Schema.Struct({
434436
status: Schema.Literal("unreachable"),
@@ -453,6 +455,17 @@ export function formatConnectReachable(
453455
].join(" · ");
454456
}
455457

458+
/**
459+
* The MCP URL outside agents use to reach this environment through T3 Connect. It comes from
460+
* the host the running tunnel answered on, since a saved T3 Connect entry with the same name
461+
* can belong to an older environment whose tunnel is gone.
462+
*/
463+
export function connectReachableMcpUrl(
464+
result: Extract<EnvironmentConnectReachability, { status: "reachable" }>,
465+
): string | null {
466+
return result.hostname ? `https://${result.hostname}/mcp` : null;
467+
}
468+
456469
/**
457470
* Sections of docs/user/t3-connect-troubleshooting.md. Each is the GitHub anchor of a
458471
* heading there; the test fails when a heading is renamed without updating this list.

0 commit comments

Comments
 (0)