refactor: move browser auto-open logic to client process

Simplifies the startup flow by consolidating browser opening
in the client script rather than the start script for prod.

We were duplicating a lot of logging, making it easy for
logs to go out of sync - this is a proposal to consolidate:

- server only logs info about itself
- client only logs info about itself

To reduce the number of places we print connection information
to the user.
This commit is contained in:
Felix Weinberger 2025-06-27 14:46:40 +01:00
commit 042e7a2aa7
No known key found for this signature in database
2 changed files with 14 additions and 33 deletions

View file

@ -1,5 +1,6 @@
#!/usr/bin/env node
import open from "open";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
import handler from "serve-handler";
@ -42,9 +43,12 @@ const server = http.createServer((request, response) => {
const port = parseInt(process.env.CLIENT_PORT || "6274", 10);
const host = process.env.HOST || "localhost";
server.on("listening", () => {
console.log(
`🔍 MCP Inspector is up and running at http://${host}:${port} 🚀`,
);
const url = process.env.INSPECTOR_URL || `http://${host}:${port}`;
console.log(`\n🚀 MCP Inspector is up and running at:\n ${url}\n`);
if (process.env.MCP_AUTO_OPEN_ENABLED !== "false") {
console.log(`🌐 Opening browser...`);
open(url);
}
});
server.on("error", (err) => {
if (err.message.includes(`EADDRINUSE`)) {

View file

@ -187,17 +187,12 @@ async function startProdClient(clientOptions) {
SERVER_PORT,
);
// Handle auto-open and logging
if (!cancelled) {
console.log(`\n🚀 MCP Inspector is up and running at:\n ${url}\n`);
if (process.env.MCP_AUTO_OPEN_ENABLED !== "false") {
console.log(`\n🌐 Opening browser...:\n`);
open(url);
}
}
await spawnPromise("node", [inspectorClientPath], {
env: { ...process.env, CLIENT_PORT: CLIENT_PORT },
env: {
...process.env,
CLIENT_PORT: CLIENT_PORT,
INSPECTOR_URL: url,
},
signal: abort.signal,
echoOutput: true,
});