@@ -25,7 +25,7 @@ import { Bus } from "@/bus"
2525import { TuiEvent } from "@/cli/cmd/tui/event"
2626import open from "open"
2727import { Effect , Exit , Layer , Option , Context , Stream } from "effect"
28- import { EffectLogger } from "@/effect/logger "
28+ import { EffectBridge } from "@/effect/bridge "
2929import { InstanceState } from "@/effect/instance-state"
3030import { ChildProcess , ChildProcessSpawner } from "effect/unstable/process"
3131import * as CrossSpawnSpawner from "@/effect/cross-spawn-spawner"
@@ -471,25 +471,24 @@ export namespace MCP {
471471 Effect . catch ( ( ) => Effect . succeed ( [ ] as number [ ] ) ) ,
472472 )
473473
474- function watch ( s : State , name : string , client : MCPClient , timeout ?: number ) {
474+ function watch ( s : State , name : string , client : MCPClient , bridge : EffectBridge . Shape , timeout ?: number ) {
475475 client . setNotificationHandler ( ToolListChangedNotificationSchema , async ( ) => {
476476 log . info ( "tools list changed notification received" , { server : name } )
477477 if ( s . clients [ name ] !== client || s . status [ name ] ?. status !== "connected" ) return
478478
479- const listed = await Effect . runPromise ( defs ( name , client , timeout ) . pipe ( Effect . provide ( EffectLogger . layer ) ) )
479+ const listed = await bridge . promise ( defs ( name , client , timeout ) )
480480 if ( ! listed ) return
481481 if ( s . clients [ name ] !== client || s . status [ name ] ?. status !== "connected" ) return
482482
483483 s . defs [ name ] = listed
484- await Effect . runPromise (
485- bus . publish ( ToolsChanged , { server : name } ) . pipe ( Effect . ignore , Effect . provide ( EffectLogger . layer ) ) ,
486- )
484+ await bridge . promise ( bus . publish ( ToolsChanged , { server : name } ) . pipe ( Effect . ignore ) )
487485 } )
488486 }
489487
490488 const state = yield * InstanceState . make < State > (
491489 Effect . fn ( "MCP.state" ) ( function * ( ) {
492490 const cfg = yield * cfgSvc . get ( )
491+ const bridge = yield * EffectBridge . make ( )
493492 const config = cfg . mcp ?? { }
494493 const s : State = {
495494 status : { } ,
@@ -518,7 +517,7 @@ export namespace MCP {
518517 if ( result . mcpClient ) {
519518 s . clients [ key ] = result . mcpClient
520519 s . defs [ key ] = result . defs !
521- watch ( s , key , result . mcpClient , mcp . timeout )
520+ watch ( s , key , result . mcpClient , bridge , mcp . timeout )
522521 }
523522 } ) ,
524523 { concurrency : "unbounded" } ,
@@ -565,11 +564,12 @@ export namespace MCP {
565564 listed : MCPToolDef [ ] ,
566565 timeout ?: number ,
567566 ) {
567+ const bridge = yield * EffectBridge . make ( )
568568 yield * closeClient ( s , name )
569569 s . status [ name ] = { status : "connected" }
570570 s . clients [ name ] = client
571571 s . defs [ name ] = listed
572- watch ( s , name , client , timeout )
572+ watch ( s , name , client , bridge , timeout )
573573 return s . status [ name ]
574574 } )
575575
0 commit comments