@@ -857,37 +857,40 @@ export async function connectMCPServer(
857857 config : ResolvedMCPServerConfig ,
858858 options : MCPConnectOptions = { } ,
859859) : Promise < MCPConnectResult > {
860- return isHttpServer ( config )
860+ const telemetry = options . telemetry ?? NOOP_TELEMETRY ;
861+ const result = await ( isHttpServer ( config )
861862 ? connectHttp ( config , options )
862- : connectStdio ( config , options ) ;
863+ : connectStdio ( config , options ) ) ;
864+ // One enum-only event per outward connection outcome. Internal HTTP
865+ // auth-recovery re-dials stay inside connectHttp, so this wrapper fires
866+ // exactly once per connectMCPServer call. Server name, URL, and error
867+ // text never leave the process.
868+ captureMcpConnect ( telemetry , {
869+ transport : isHttpServer ( config ) ? "http" : "stdio" ,
870+ result : classifyMcpConnectOutcome ( result ) ,
871+ } ) ;
872+ return result ;
863873}
864874
865875export async function connectMCPServers (
866876 configs : ResolvedMCPServerConfig [ ] ,
867877 onWarning : ( message : string ) => void ,
868878 options : MCPConnectOptions = { } ,
869879) : Promise < MCPClient [ ] > {
870- const telemetry = options . telemetry ?? NOOP_TELEMETRY ;
880+ // Telemetry flows through options into connectMCPServer, which captures
881+ // one mcp_connect per config.
871882 const results = await Promise . all (
872883 configs . map ( ( c ) => connectMCPServer ( c , options ) ) ,
873884 ) ;
874885 const clients : MCPClient [ ] = [ ] ;
875- for ( let index = 0 ; index < results . length ; index += 1 ) {
876- const result = results [ index ] ;
877- if ( result === undefined ) continue ;
886+ for ( const result of results ) {
878887 if ( result . ok ) clients . push ( result . client ) ;
879888 else
880889 onWarning (
881890 `[mcp] Warning: failed to connect to MCP server "${ result . serverName } ": ${ result . error } ` ,
882891 ) ;
883- // One enum-only event per server: the transport that was dialed and the
884- // outcome enum. Server name, URL, and error text never leave the process.
885- const config = configs [ index ] ;
886- captureMcpConnect ( telemetry , {
887- transport :
888- config !== undefined && isHttpServer ( config ) ? "http" : "stdio" ,
889- result : classifyMcpConnectOutcome ( result ) ,
890- } ) ;
892+ // No emit here: connectMCPServer already captured one enum-only
893+ // mcp_connect per config. Emitting again would double-count.
891894 }
892895 return clients ;
893896}
0 commit comments