@@ -7,7 +7,7 @@ import { fileURLToPath } from "url";
77const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
88
99function delay ( ms ) {
10- return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
10+ return new Promise ( ( resolve ) => setTimeout ( resolve , ms , true ) ) ;
1111}
1212
1313async function main ( ) {
@@ -73,42 +73,40 @@ async function main() {
7373 cancelled = true ;
7474 abort . abort ( ) ;
7575 } ) ;
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 ;
10877 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+ }
112110 }
113111
114112 return 0 ;
0 commit comments