@@ -7,7 +7,7 @@ import { fileURLToPath } from "url";
7
7
const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
8
8
9
9
function delay ( ms ) {
10
- return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
10
+ return new Promise ( ( resolve ) => setTimeout ( resolve , ms , true ) ) ;
11
11
}
12
12
13
13
async function main ( ) {
@@ -73,42 +73,40 @@ async function main() {
73
73
cancelled = true ;
74
74
abort . abort ( ) ;
75
75
} ) ;
76
-
77
- const server = spawnPromise (
78
- "node" ,
79
- [
80
- inspectorServerPath ,
81
- ...( command ? [ `--env` , command ] : [ ] ) ,
82
- ...( mcpServerArgs ? [ `--args=${ mcpServerArgs . join ( " " ) } ` ] : [ ] ) ,
83
- ] ,
84
- {
85
- env : {
86
- ...process . env ,
87
- PORT : SERVER_PORT ,
88
- MCP_ENV_VARS : JSON . stringify ( envVars ) ,
89
- } ,
90
- signal : abort . signal ,
91
- echoOutput : true ,
92
- } ,
93
- ) ;
94
-
95
- const client = spawnPromise ( "node" , [ inspectorClientPath ] , {
96
- env : { ...process . env , PORT : CLIENT_PORT } ,
97
- signal : abort . signal ,
98
- echoOutput : true ,
99
- } ) ;
100
-
101
- // Make sure our server/client didn't immediately fail
102
- await Promise . any ( [ server , client , delay ( 2 * 1000 ) ] ) ;
103
- const portParam = SERVER_PORT === "3000" ? "" : `?proxyPort=${ SERVER_PORT } ` ;
104
- console . log (
105
- `\n🔍 MCP Inspector is up and running at http://127.0.0.1:${ CLIENT_PORT } ${ portParam } 🚀` ,
106
- ) ;
107
-
76
+ let server , serverOk ;
108
77
try {
109
- await Promise . any ( [ server , client ] ) ;
110
- } catch ( e ) {
111
- if ( ! cancelled || process . env . DEBUG ) throw e ;
78
+ server = spawnPromise (
79
+ "node" ,
80
+ [
81
+ inspectorServerPath ,
82
+ ...( command ? [ `--env` , command ] : [ ] ) ,
83
+ ...( mcpServerArgs ? [ `--args=${ mcpServerArgs . join ( " " ) } ` ] : [ ] ) ,
84
+ ] ,
85
+ {
86
+ env : {
87
+ ...process . env ,
88
+ PORT : SERVER_PORT ,
89
+ MCP_ENV_VARS : JSON . stringify ( envVars ) ,
90
+ } ,
91
+ signal : abort . signal ,
92
+ echoOutput : true ,
93
+ } ,
94
+ ) ;
95
+
96
+ // Make sure server started before starting client
97
+ serverOk = await Promise . race ( [ server , delay ( 2 * 1000 ) ] ) ;
98
+ } catch ( error ) { }
99
+
100
+ if ( serverOk ) {
101
+ try {
102
+ await spawnPromise ( "node" , [ inspectorClientPath ] , {
103
+ env : { ...process . env , PORT : CLIENT_PORT } ,
104
+ signal : abort . signal ,
105
+ echoOutput : true ,
106
+ } ) ;
107
+ } catch ( e ) {
108
+ if ( ! cancelled || process . env . DEBUG ) throw e ;
109
+ }
112
110
}
113
111
114
112
return 0 ;
0 commit comments