11// @effect -diagnostics nodeBuiltinImport:off -- Executes the shipped Pi extension at its native JavaScript boundary.
22import * as NodeModule from "node:module" ;
3+ import * as NodePath from "node:path" ;
34import * as NodeVM from "node:vm" ;
45import { PI_T3_MCP_EXTENSION_SOURCE } from "./mcpExtensionSource.ts" ;
56
@@ -39,22 +40,32 @@ export async function loadMcpBridge(
3940 readonly toolSearchAvailable ?: boolean ;
4041 readonly toolSearchDisabled ?: boolean ;
4142 readonly allowsTool ?: ( name : string ) => boolean ;
43+ readonly runtimeMode ?: string ;
4244 } = { } ,
4345) {
4446 const handlers = new Map < string , AgentStartHook > ( ) ;
4547 const tools : RegisteredTool [ ] = [ ] ;
4648 const requests : Array < { readonly method : string ; readonly params ?: unknown } > = [ ] ;
4749 let activeTools = [ "read" ] ;
50+ let bridgeSourcePath = "/fixture/pi-t3-extension.ts" ;
4851 const transports : Array < {
4952 readonly url : string ;
5053 readonly authorization : string ;
5154 readonly signal : AbortSignal | undefined ;
5255 } > = [ ] ;
5356 const servers : Array < { readonly name : string ; readonly config : Record < string , unknown > } > = [ ] ;
5457 const catalog = [
55- { name : "orchestrator_capabilities" , description : "Discover available providers and models." } ,
58+ {
59+ name : "orchestrator_capabilities" ,
60+ description : "Discover available providers and models." ,
61+ annotations : { readOnlyHint : true } ,
62+ } ,
5663 { name : "delegate_task" , description : "Delegate work to another agent." } ,
57- { name : "task_status" , description : "Check delegated work." } ,
64+ {
65+ name : "task_status" ,
66+ description : "Check delegated work." ,
67+ annotations : { readOnlyHint : false } ,
68+ } ,
5869 { name : "preview_snapshot" , description : "Inspect the collaborative browser." } ,
5970 ] . map ( ( tool ) => ( {
6071 ...tool ,
@@ -69,9 +80,15 @@ export async function loadMcpBridge(
6980 ) ;
7081 await NodeVM . runInNewContext ( `${ source } \nt3McpExtension(pi)` , {
7182 process : {
72- env : { T3_MCP_URL : "http://fixture.invalid/mcp" , T3_MCP_BEARER_TOKEN : "fixture-token" } ,
83+ env : {
84+ T3_MCP_URL : "http://fixture.invalid/mcp" ,
85+ T3_MCP_BEARER_TOKEN : "fixture-token" ,
86+ T3_PI_MCP_EXTENSION_PATH : "/fixture/pi-t3-extension.ts" ,
87+ T3_PI_RUNTIME_MODE : options . runtimeMode ,
88+ } ,
7389 } ,
7490 AbortSignal,
91+ NodePath,
7592 Type : { Unsafe : ( schema : unknown ) => schema } ,
7693 fetch : async (
7794 url : string ,
@@ -111,12 +128,14 @@ export async function loadMcpBridge(
111128 setActiveTools : ( names : string [ ] ) => {
112129 activeTools = names . filter ( ( name ) => options . allowsTool ?.( name ) ?? true ) ;
113130 } ,
114- getAllTools : ( ) =>
115- options . toolSearchAvailable &&
131+ getAllTools : ( ) => [
132+ ...tools . map ( ( tool ) => ( { name : tool . name , sourceInfo : { path : bridgeSourcePath } } ) ) ,
133+ ...( options . toolSearchAvailable &&
116134 ! options . toolSearchDisabled &&
117135 ( options . allowsTool ?.( "tool_search" ) ?? true )
118136 ? [ { name : "tool_search" , sourceInfo : { path : "builtin:tool-search" } } ]
119- : [ ] ,
137+ : [ ] ) ,
138+ ] ,
120139 ...( options . modern
121140 ? {
122141 registerMcpServer : ( name : string , config : Record < string , unknown > ) =>
@@ -129,6 +148,9 @@ export async function loadMcpBridge(
129148 return {
130149 handlers,
131150 tools,
151+ setBridgeSourcePath : ( path : string ) => {
152+ bridgeSourcePath = path ;
153+ } ,
132154 requests,
133155 servers,
134156 transports,
0 commit comments