@@ -20,6 +20,8 @@ import {
2020 hasSavedBearerRoute ,
2121 connectionStatusText ,
2222 environmentMcpUrl ,
23+ localEnvironmentMcpUrl ,
24+ type ConnectionCatalogEntry ,
2325} from "@t3tools/client-runtime/connection" ;
2426import * as Option from "effect/Option" ;
2527
@@ -50,6 +52,7 @@ import {
5052import { hasCloudPublicConfig } from "~/cloud/publicConfig" ;
5153import { isElectron } from "~/env" ;
5254import { useCloudLinkController } from "~/cloud/useCloudLinkController" ;
55+ import { usePrimaryCloudLinkState } from "~/cloud/cloudLinkState" ;
5356import { useManagedTunnelUsage } from "~/cloud/managedRelayState" ;
5457import { useT3ConnectAccountPage } from "../clerk/T3ConnectAccountPages" ;
5558import { TunnelLimitAlert , TunnelUsageMeter } from "../cloud/TunnelUsage" ;
@@ -107,6 +110,28 @@ function savedBackendStatus(environment: EnvironmentPresentation): {
107110 }
108111}
109112
113+ function useCopyMcpUrl ( ) {
114+ return useCopyToClipboard < { url : string } > ( {
115+ target : "MCP URL" ,
116+ onCopy : ( { url } ) => {
117+ toastManager . add ( {
118+ type : "success" ,
119+ title : "MCP URL copied" ,
120+ description : `Add it to an agent, e.g. claude mcp add --transport http t3 ${ url } ` ,
121+ } ) ;
122+ } ,
123+ onError : ( error ) => {
124+ toastManager . add (
125+ stackedThreadToast ( {
126+ type : "error" ,
127+ title : "Could not copy MCP URL" ,
128+ description : error . message ,
129+ } ) ,
130+ ) ;
131+ } ,
132+ } ) ;
133+ }
134+
110135export function SavedBackendListRow ( {
111136 environment,
112137 removingEnvironmentId,
@@ -146,25 +171,7 @@ export function SavedBackendListRow({
146171 const copyTraceId = ( traceId : string ) => {
147172 copyTraceIdToClipboard ( traceId , { traceId } ) ;
148173 } ;
149- const { copyToClipboard : copyMcpUrl } = useCopyToClipboard < { url : string } > ( {
150- target : "MCP URL" ,
151- onCopy : ( { url } ) => {
152- toastManager . add ( {
153- type : "success" ,
154- title : "MCP URL copied" ,
155- description : `Add it to an agent, e.g. claude mcp add --transport http t3 ${ url } ` ,
156- } ) ;
157- } ,
158- onError : ( error ) => {
159- toastManager . add (
160- stackedThreadToast ( {
161- type : "error" ,
162- title : "Could not copy MCP URL" ,
163- description : error . message ,
164- } ) ,
165- ) ;
166- } ,
167- } ) ;
174+ const { copyToClipboard : copyMcpUrl } = useCopyMcpUrl ( ) ;
168175 const versionMismatch = resolveServerConfigVersionMismatch ( environment . serverConfig ) ;
169176 const serverUpdateState = useAtomValue ( serverEnvironment . updateStateAtom ( environmentId ) ) ;
170177 const resumingServerUpdate =
@@ -433,6 +440,33 @@ export function SavedBackendListRow({
433440 ) ;
434441}
435442
443+ /** Copying the host's own MCP address, for hosted agents or agents on this machine. */
444+ export function LocalEnvironmentMcpUrlRow ( { entry } : { readonly entry : ConnectionCatalogEntry } ) {
445+ const cloudLink = usePrimaryCloudLinkState ( ) ;
446+ const { copyToClipboard : copyMcpUrl } = useCopyMcpUrl ( ) ;
447+ const mcpUrl = localEnvironmentMcpUrl ( {
448+ entry,
449+ tunnelHttpBaseUrl : cloudLink . data ?. managedTunnelHttpBaseUrl ,
450+ } ) ;
451+ if ( mcpUrl === null ) return null ;
452+ const hosted = cloudLink . data ?. managedTunnelHttpBaseUrl != null ;
453+ return (
454+ < SettingsRow
455+ { ...searchableSetting ( "mcp-url" ) }
456+ description = {
457+ hosted
458+ ? `Give this URL to a hosted agent, such as ChatGPT: ${ mcpUrl } `
459+ : `Give this URL to an agent outside T3 Code: ${ mcpUrl } `
460+ }
461+ control = {
462+ < Button size = "sm" variant = "outline" onClick = { ( ) => copyMcpUrl ( mcpUrl , { url : mcpUrl } ) } >
463+ Copy
464+ </ Button >
465+ }
466+ />
467+ ) ;
468+ }
469+
436470function CloudLinkSwitch ( {
437471 checked,
438472 disabled,
0 commit comments