@@ -47,7 +47,8 @@ class MCPConnection {
47
47
} ;
48
48
49
49
constructor ( public options : MCPOptions ) {
50
- this . transport = this . constructTransport ( options ) ;
50
+ // Don't construct transport in constructor to avoid blocking
51
+ this . transport = { } as Transport ; // Will be set in connectClient
51
52
52
53
this . client = new Client (
53
54
{
@@ -132,7 +133,8 @@ class MCPConnection {
132
133
} ) ;
133
134
} ) ,
134
135
( async ( ) => {
135
- this . transport = this . constructTransport ( this . options ) ;
136
+ this . transport = await this . constructTransportAsync ( this . options ) ;
137
+
136
138
try {
137
139
await this . client . connect ( this . transport ) ;
138
140
} catch ( error ) {
@@ -295,7 +297,9 @@ class MCPConnection {
295
297
} ;
296
298
}
297
299
298
- private constructTransport ( options : MCPOptions ) : Transport {
300
+ private async constructTransportAsync (
301
+ options : MCPOptions ,
302
+ ) : Promise < Transport > {
299
303
switch ( options . transport . type ) {
300
304
case "stdio" :
301
305
const env : Record < string , string > = options . transport . env
@@ -309,7 +313,7 @@ class MCPConnection {
309
313
// For non-Windows platforms, try to get the PATH from user shell
310
314
if ( process . platform !== "win32" ) {
311
315
try {
312
- const shellEnvPath = getEnvPathFromUserShell ( ) ;
316
+ const shellEnvPath = await getEnvPathFromUserShell ( ) ;
313
317
if ( shellEnvPath && shellEnvPath !== process . env . PATH ) {
314
318
env . PATH = shellEnvPath ;
315
319
}
0 commit comments