Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ function routesList(routes: ReadonlyArray<ConnectionRoute>) {
serverConfig: null,
refusedRouteIds: [],
};
return <EnvironmentRoutesList environment={environment} onAddRoute={() => undefined} />;
return (
<EnvironmentRoutesList
environment={environment}
relayHttpBaseUrl={undefined}
onAddRoute={() => undefined}
onCopyMcpUrl={() => undefined}
/>
);
}

it("shows a route added after a reorder was saved, once another route is removed", async () => {
Expand Down
31 changes: 30 additions & 1 deletion apps/web/src/components/settings/EnvironmentRoutesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import {
connectionRouteAddress,
connectionRouteId,
connectionRouteLabelText,
connectionRouteMcpUrl,
connectionRoutes,
isLearned,
pendingRouteOrder,
} from "@t3tools/client-runtime/connection";
import { GripVerticalIcon, PlusIcon, XIcon } from "lucide-react";
import { CopyIcon, GripVerticalIcon, PlusIcon, XIcon } from "lucide-react";
import { T, useGT, useMessages } from "gt-react";
import { useState } from "react";

Expand All @@ -40,10 +41,14 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";

export function EnvironmentRoutesList({
environment,
relayHttpBaseUrl,
onAddRoute,
onCopyMcpUrl,
}: {
readonly environment: EnvironmentPresentation;
readonly relayHttpBaseUrl: string | undefined;
readonly onAddRoute: () => void;
readonly onCopyMcpUrl: (url: string) => void;
}) {
const saved = connectionRoutes(environment.entry);
const savedIds = saved.map((route) => connectionRouteId(route.target));
Expand Down Expand Up @@ -120,8 +125,10 @@ export function EnvironmentRoutesList({
route={route}
position={index + 1}
inUse={connectionRouteId(route.target) === activeRouteId}
mcpUrl={connectionRouteMcpUrl(route, relayHttpBaseUrl)}
refused={environment.refusedRouteIds.includes(connectionRouteId(route.target))}
removable={routes.length > 1 && !isLearned(route)}
onCopyMcpUrl={onCopyMcpUrl}
onRemove={() => void confirmRemove(route)}
/>
))}
Expand All @@ -142,15 +149,19 @@ function SortableRouteRow({
route,
position,
inUse,
mcpUrl,
refused,
removable,
onCopyMcpUrl,
onRemove,
}: {
readonly route: ConnectionRoute;
readonly position: number;
readonly inUse: boolean;
readonly mcpUrl: string | null;
readonly refused: boolean;
readonly removable: boolean;
readonly onCopyMcpUrl: (url: string) => void;
readonly onRemove: () => void;
}) {
const gt = useGT();
Expand Down Expand Up @@ -203,6 +214,24 @@ function SortableRouteRow({
</p>
) : null}
</div>
{mcpUrl !== null ? (
<Tooltip>
<TooltipTrigger
render={
<Button
type="button"
variant="ghost-muted"
size="icon-xs"
aria-label={gt("Copy {route} MCP URL", { route: label })}
onClick={() => onCopyMcpUrl(mcpUrl)}
/>
}
>
<CopyIcon className="size-3" />
</TooltipTrigger>
<TooltipPopup side="top">{gt("Copy MCP URL")}</TooltipPopup>
</Tooltip>
) : null}
<button
type="button"
ref={setActivatorNodeRef}
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/components/settings/SavedEnvironmentRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@ export function SavedBackendListRow({
const diagnosis = resumingServerUpdate ? null : currentDiagnosis;
const prepared = usePreparedConnection(environmentId);
const connectedTarget = isConnected && prepared._tag === "Some" ? prepared.value.target : null;
const relayHttpBaseUrl = discoveredRelayHttpBaseUrl ?? lastRelayHttpBaseUrl;
const mcpUrl = environmentMcpUrl({
entry: environment.entry,
relayHttpBaseUrl: discoveredRelayHttpBaseUrl ?? lastRelayHttpBaseUrl,
relayHttpBaseUrl,
connectedTarget,
});
const machineKind = resolveEnvironmentMachineKind(
Expand Down Expand Up @@ -362,7 +363,9 @@ export function SavedBackendListRow({
{routesOpen && (
<EnvironmentRoutesList
environment={environment}
relayHttpBaseUrl={relayHttpBaseUrl}
onAddRoute={() => onAddRoute(environment)}
onCopyMcpUrl={(url) => copyMcpUrl(url, { url })}
/>
)}
{permissionsOpen && (
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -8249,6 +8249,8 @@
"bd788c3bdf99d29e": "Route {route} entfernen?\n{address}",
"2d22ff842ebd95f5": "Routen zu {environment}, bevorzugte zuerst",
"c44f306568c17f1f": "automatisch gefunden",
"f41ec19eb4cba8b1": "MCP-URL der Route {route} kopieren",
"32f5a22aa78ece11": "MCP-URL kopieren",
"f6e62d06f525c520": "{route} verschieben, Position {position}",
"136b22b496135313": "Route {route} entfernen",
"ead3fcfb887f845b": "Route hinzufügen",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8257,6 +8257,8 @@
"bd788c3bdf99d29e": "Remove {route} route?\n{address}",
"2d22ff842ebd95f5": "Routes to {environment}, preferred first",
"c44f306568c17f1f": "found automatically",
"f41ec19eb4cba8b1": "Copy {route} MCP URL",
"32f5a22aa78ece11": "Copy MCP URL",
"f6e62d06f525c520": "Reorder {route}, position {position}",
"136b22b496135313": "Remove {route} route",
"ead3fcfb887f845b": "Add route",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -8247,6 +8247,8 @@
"bd788c3bdf99d29e": "¿Quitar la ruta {route}?\n{address}",
"2d22ff842ebd95f5": "Rutas a {environment}, la preferida primero",
"c44f306568c17f1f": "encontrada automáticamente",
"f41ec19eb4cba8b1": "Copiar URL de MCP de la ruta {route}",
"32f5a22aa78ece11": "Copiar URL de MCP",
"f6e62d06f525c520": "Reordenar {route}, posición {position}",
"136b22b496135313": "Quitar la ruta {route}",
"ead3fcfb887f845b": "Añadir ruta",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -8248,6 +8248,8 @@
"bd788c3bdf99d29e": "Supprimer la route {route} ?\n{address}",
"2d22ff842ebd95f5": "Routes vers {environment}, par ordre de préférence",
"c44f306568c17f1f": "trouvée automatiquement",
"f41ec19eb4cba8b1": "Copier l’URL MCP de la route {route}",
"32f5a22aa78ece11": "Copier l’URL MCP",
"f6e62d06f525c520": "Réordonner {route}, position {position}",
"136b22b496135313": "Supprimer la route {route}",
"ead3fcfb887f845b": "Ajouter une route",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -8205,6 +8205,8 @@
"bd788c3bdf99d29e": "ルート {route} を削除しますか?\n{address}",
"2d22ff842ebd95f5": "{environment} へのルート (優先順)",
"c44f306568c17f1f": "自動検出",
"f41ec19eb4cba8b1": "ルート {route} の MCP URL をコピー",
"32f5a22aa78ece11": "MCP URL をコピー",
"f6e62d06f525c520": "{route} を並べ替え、位置 {position}",
"136b22b496135313": "ルート {route} を削除",
"ead3fcfb887f845b": "ルートを追加",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -8208,6 +8208,8 @@
"bd788c3bdf99d29e": "{route} 경로를 제거할까요?\n{address}",
"2d22ff842ebd95f5": "{environment}(으)로 가는 경로, 우선순위 순",
"c44f306568c17f1f": "자동으로 찾음",
"f41ec19eb4cba8b1": "{route} 경로의 MCP URL 복사",
"32f5a22aa78ece11": "MCP URL 복사",
"f6e62d06f525c520": "{route} 순서 변경, {position}번째",
"136b22b496135313": "{route} 경로 제거",
"ead3fcfb887f845b": "경로 추가",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -8247,6 +8247,8 @@
"bd788c3bdf99d29e": "Remover a rota {route}?\n{address}",
"2d22ff842ebd95f5": "Rotas para {environment}, preferida primeiro",
"c44f306568c17f1f": "encontrada automaticamente",
"f41ec19eb4cba8b1": "Copiar URL do MCP da rota {route}",
"32f5a22aa78ece11": "Copiar URL do MCP",
"f6e62d06f525c520": "Reordenar {route}, posição {position}",
"136b22b496135313": "Remover a rota {route}",
"ead3fcfb887f845b": "Adicionar rota",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -8249,6 +8249,8 @@
"bd788c3bdf99d29e": "Удалить маршрут {route}?\n{address}",
"2d22ff842ebd95f5": "Маршруты к {environment}, предпочтительные первыми",
"c44f306568c17f1f": "найден автоматически",
"f41ec19eb4cba8b1": "Копировать URL MCP маршрута {route}",
"32f5a22aa78ece11": "Копировать URL MCP",
"f6e62d06f525c520": "Переместить {route}, позиция {position}",
"136b22b496135313": "Удалить маршрут {route}",
"ead3fcfb887f845b": "Добавить маршрут",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -8255,6 +8255,8 @@
"bd788c3bdf99d29e": "Ta bort rutten {route}?\n{address}",
"2d22ff842ebd95f5": "Rutter till {environment}, föredragen först",
"c44f306568c17f1f": "hittad automatiskt",
"f41ec19eb4cba8b1": "Kopiera MCP-URL för rutten {route}",
"32f5a22aa78ece11": "Kopiera MCP-URL",
"f6e62d06f525c520": "Ändra ordning på {route}, position {position}",
"136b22b496135313": "Ta bort rutten {route}",
"ead3fcfb887f845b": "Lägg till rutt",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -8265,6 +8265,8 @@
"bd788c3bdf99d29e": "移除 {route} 线路?\n{address}",
"2d22ff842ebd95f5": "连接 {environment} 的线路,优先线路在前",
"c44f306568c17f1f": "自动发现",
"f41ec19eb4cba8b1": "复制 {route} 线路的 MCP URL",
"32f5a22aa78ece11": "复制 MCP URL",
"f6e62d06f525c520": "重新排序 {route},位置 {position}",
"136b22b496135313": "移除 {route} 线路",
"ead3fcfb887f845b": "添加线路",
Expand Down
4 changes: 3 additions & 1 deletion docs/user/outside-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ https://<environment-address>/mcp

When T3 Connect serves the environment, the copied URL is its T3 Connect
address, which agents can reach from anywhere. Otherwise it uses the route this
device is connected over, so an agent on the same device can reach it.
device is connected over, so an agent on the same device can reach it. To copy
another address, open the environment's routes and use the copy button on that
route.

- **An agent on your own computers** can use `localhost` on the host, T3
Connect, or any `https` address, such as
Expand Down
30 changes: 30 additions & 0 deletions packages/client-runtime/src/connection/presentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import {
BearerConnectionTarget,
ConnectionTransientError,
RelayConnectionTarget,
SshConnectionTarget,
type SupervisorConnectionState,
} from "./model.ts";
import {
connectionRouteMcpUrl,
connectionStatusText,
connectionStatusTitle,
environmentMcpUrl,
Expand Down Expand Up @@ -120,6 +122,34 @@ describe("connection presentation", () => {
).toBe("https://tunnel.example.test/mcp");
});

it("gives each route its own MCP URL, or none when it has no stable address", () => {
const bearer: ConnectionRoute = { target: ENTRY.target, profile: ENTRY.profile };
const relay: ConnectionRoute = {
target: new RelayConnectionTarget({
environmentId: TARGET.environmentId,
label: TARGET.label,
}),
profile: Option.none(),
};
const ssh: ConnectionRoute = {
target: new SshConnectionTarget({
environmentId: TARGET.environmentId,
label: TARGET.label,
connectionId: "ssh",
}),
profile: Option.none(),
};

expect(connectionRouteMcpUrl(bearer, "https://tunnel.example.test")).toBe(
"https://environment.example.test/mcp",
);
expect(connectionRouteMcpUrl(relay, "https://tunnel.example.test")).toBe(
"https://tunnel.example.test/mcp",
);
expect(connectionRouteMcpUrl(relay, undefined)).toBeNull();
expect(connectionRouteMcpUrl(ssh, "https://tunnel.example.test")).toBeNull();
});

it("distinguishes initial connection, reconnect, and retry errors", () => {
expect(presentConnectionState(supervisorState({ phase: "connecting", attempt: 1 }))).toEqual({
phase: "connecting",
Expand Down
16 changes: 13 additions & 3 deletions packages/client-runtime/src/connection/presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mFallback, msg } from "gt-i18n";
import type { MFunctionType } from "gt-i18n/types";

import { type MarkedText, resolveMarkedText } from "../errors/translatable.ts";
import type { ConnectionCatalogEntry } from "./catalog.ts";
import type { ConnectionCatalogEntry, ConnectionRoute } from "./catalog.ts";
import type { ConnectionTarget, SupervisorConnectionState } from "./model.ts";
import { connectionRouteId, connectionRoutes, routeHttpBaseUrl } from "./routes.ts";

Expand Down Expand Up @@ -165,13 +165,23 @@ export function environmentMcpUrl(input: {
(route) => connectionRouteId(route.target) === connectedRouteId,
);
for (const route of connectedRoute ? [connectedRoute, ...routes] : routes) {
const httpBaseUrl = routeHttpBaseUrl(route);
const mcpUrl = httpBaseUrl === null ? null : mcpUrlFromBase(httpBaseUrl);
const mcpUrl = connectionRouteMcpUrl(route, input.relayHttpBaseUrl);
if (mcpUrl !== null) return mcpUrl;
}
return null;
}

export function connectionRouteMcpUrl(
route: ConnectionRoute,
relayHttpBaseUrl: string | undefined,
): string | null {
const httpBaseUrl =
route.target._tag === "RelayConnectionTarget"
? (relayHttpBaseUrl ?? null)
: routeHttpBaseUrl(route);
return httpBaseUrl === null ? null : mcpUrlFromBase(httpBaseUrl);
}

function mcpUrlFromBase(httpBaseUrl: string): string | null {
let url: URL;
try {
Expand Down
Loading