@@ -392,6 +392,41 @@ describe("AcpMcpStdioBridge", () => {
392392 } ) ,
393393 ) ;
394394
395+ it . effect ( "answers a server ping that arrives before the tool result on its SSE stream" , ( ) =>
396+ Effect . gen ( function * ( ) {
397+ const sent : Array < { id ?: unknown ; method ?: string ; result ?: unknown } > = [ ] ;
398+ const result = yield * mcpToolSession ( {
399+ endpoint : "http://127.0.0.1:1/mcp" ,
400+ authorization : "Bearer bridge-test" ,
401+ clientName : "t3-code-acp-cli" ,
402+ fetchImplementation : async ( _url , init ) => {
403+ if ( init ?. method === "DELETE" ) return new Response ( null , { status : 204 } ) ;
404+ const message = JSON . parse ( String ( init ?. body ) ) as ( typeof sent ) [ number ] ;
405+ sent . push ( message ) ;
406+ if ( message . method === "initialize" ) {
407+ return Response . json (
408+ { jsonrpc : "2.0" , id : message . id , result : { protocolVersion : "2025-06-18" } } ,
409+ { headers : { "mcp-session-id" : "session-42" } } ,
410+ ) ;
411+ }
412+ if ( message . method !== "tools/call" ) return new Response ( null , { status : 202 } ) ;
413+ const ping = { jsonrpc : "2.0" , id : "server-ping" , method : "ping" } ;
414+ const reply = { jsonrpc : "2.0" , id : message . id , result : { content : [ ] } } ;
415+ return new Response (
416+ `data: ${ JSON . stringify ( ping ) } \n\ndata: ${ JSON . stringify ( reply ) } \n\n` ,
417+ { headers : { "content-type" : "text/event-stream" } } ,
418+ ) ;
419+ } ,
420+ } ) . pipe (
421+ Effect . flatMap ( ( session ) => session . call ( "orchestrator_capabilities" , { } ) ) ,
422+ Effect . scoped ,
423+ ) ;
424+
425+ expect ( result ) . toEqual ( { content : [ ] } ) ;
426+ expect ( sent ) . toContainEqual ( { jsonrpc : "2.0" , id : "server-ping" , result : { } } ) ;
427+ } ) ,
428+ ) ;
429+
395430 it . effect ( "aborts the pending fetch when the stdio bridge is interrupted" , ( ) =>
396431 Effect . gen ( function * ( ) {
397432 const started = yield * Deferred . make < AbortSignal | undefined > ( ) ;
0 commit comments