Skip to content

Commit 042e7a2

Browse files
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.
1 parent ae1aeb3 commit 042e7a2

File tree

3 files changed

+14
-33
lines changed

3 files changed

+14
-33
lines changed

client/bin/client.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22

3+
import open from "open";
34
import { join, dirname } from "path";
45
import { fileURLToPath } from "url";
56
import handler from "serve-handler";
@@ -42,9 +43,12 @@ const server = http.createServer((request, response) => {
4243
const port = parseInt(process.env.CLIENT_PORT || "6274", 10);
4344
const host = process.env.HOST || "localhost";
4445
server.on("listening", () => {
45-
console.log(
46-
`🔍 MCP Inspector is up and running at http://${host}:${port} 🚀`,
47-
);
46+
const url = process.env.INSPECTOR_URL || `http://${host}:${port}`;
47+
console.log(`\n🚀 MCP Inspector is up and running at:\n ${url}\n`);
48+
if (process.env.MCP_AUTO_OPEN_ENABLED !== "false") {
49+
console.log(`🌐 Opening browser...`);
50+
open(url);
51+
}
4852
});
4953
server.on("error", (err) => {
5054
if (err.message.includes(`EADDRINUSE`)) {

client/bin/start.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,12 @@ async function startProdClient(clientOptions) {
187187
SERVER_PORT,
188188
);
189189

190-
// Handle auto-open and logging
191-
if (!cancelled) {
192-
console.log(`\n🚀 MCP Inspector is up and running at:\n ${url}\n`);
193-
if (process.env.MCP_AUTO_OPEN_ENABLED !== "false") {
194-
console.log(`\n🌐 Opening browser...:\n`);
195-
open(url);
196-
}
197-
}
198-
199190
await spawnPromise("node", [inspectorClientPath], {
200-
env: { ...process.env, CLIENT_PORT: CLIENT_PORT },
191+
env: {
192+
...process.env,
193+
CLIENT_PORT: CLIENT_PORT,
194+
INSPECTOR_URL: url,
195+
},
201196
signal: abort.signal,
202197
echoOutput: true,
203198
});

server/src/index.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -539,27 +539,9 @@ const server = app.listen(PORT, HOST);
539539
server.on("listening", () => {
540540
console.log(`⚙️ Proxy server listening on ${HOST}:${PORT}`);
541541
if (!authDisabled) {
542-
console.log(`🔑 Session token: ${sessionToken}`);
543542
console.log(
544-
`Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth`,
545-
);
546-
547-
// Display clickable URL with pre-filled token
548-
const clientPort = process.env.CLIENT_PORT || "6274";
549-
const clientHost = process.env.HOST || "localhost";
550-
551-
// Build URL with query parameters
552-
const params = new URLSearchParams();
553-
params.set("MCP_PROXY_AUTH_TOKEN", sessionToken);
554-
555-
// Add server port if it's not the default
556-
if (PORT !== parseInt(DEFAULT_MCP_PROXY_LISTEN_PORT, 10)) {
557-
params.set("MCP_PROXY_PORT", PORT.toString());
558-
}
559-
560-
const clientUrl = `http://${clientHost}:${clientPort}/?${params.toString()}`;
561-
console.log(
562-
`\n🔗 Open inspector with token pre-filled:\n ${clientUrl}\n`,
543+
`🔑 Session token: ${sessionToken}\n ` +
544+
`Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth`,
563545
);
564546
} else {
565547
console.log(

0 commit comments

Comments
 (0)