Merge pull request #604 from cliffhall/fix-startup

fix startup of webclient through cli
This commit is contained in:
Cliff Hall 2025-07-10 15:42:55 -04:00 • committed by GitHub
commit 42a1bac6ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,28 +50,15 @@ function delay(ms: number): Promise<void> {
} }
async function runWebClient(args: Args): Promise<void> { async function runWebClient(args: Args): Promise<void> {
const inspectorServerPath = resolve(
__dirname,
"../../",
"server",
"build",
"index.js",
);
// Path to the client entry point // Path to the client entry point
const inspectorClientPath = resolve( const inspectorClientPath = resolve(
__dirname, __dirname,
"../../", "../../",
"client", "client",
"bin", "bin",
"client.js", "start.js",
); );
const CLIENT_PORT: string = process.env.CLIENT_PORT ?? "6274";
const SERVER_PORT: string = process.env.SERVER_PORT ?? "6277";
console.log("Starting MCP inspector...");
const abort = new AbortController(); const abort = new AbortController();
let cancelled: boolean = false; let cancelled: boolean = false;
process.on("SIGINT", () => { process.on("SIGINT", () => {
@ -79,42 +66,13 @@ async function runWebClient(args: Args): Promise<void> {
abort.abort(); abort.abort();
}); });
let server: ReturnType<typeof spawnPromise>;
let serverOk: unknown;
try { try {
server = spawnPromise( await spawnPromise("node", [inspectorClientPath], {
"node", signal: abort.signal,
[ echoOutput: true,
inspectorServerPath, });
...(args.command ? [`--env`, args.command] : []), } catch (e) {
...(args.args ? [`--args=${args.args.join(" ")}`] : []), if (!cancelled || process.env.DEBUG) throw e;
],
{
env: {
...process.env,
PORT: SERVER_PORT,
MCP_ENV_VARS: JSON.stringify(args.envArgs),
},
signal: abort.signal,
echoOutput: true,
},
);
// Make sure server started before starting client
serverOk = await Promise.race([server, delay(2 * 1000)]);
} catch (error) {}
if (serverOk) {
try {
await spawnPromise("node", [inspectorClientPath], {
env: { ...process.env, PORT: CLIENT_PORT },
signal: abort.signal,
echoOutput: true,
});
} catch (e) {
if (!cancelled || process.env.DEBUG) throw e;
}
} }
} }