11#!/usr/bin/env node
22
33import { createServer } from 'http'
4+ import { randomBytes } from 'node:crypto'
45import { styleText } from 'node:util'
56import { execa } from 'execa'
67import getPort from 'get-port'
@@ -20,16 +21,38 @@ const clientPort = await getPort({
2021 exclude : [ process . env . PORT , serverPort ] . filter ( Boolean ) . map ( Number ) ,
2122} )
2223
24+ const sessionToken = randomBytes ( 32 ) . toString ( 'hex' )
2325// Spawn mcp-inspector as a sidecar process
2426const inspectorProcess = execa ( 'mcp-inspector' , [ ] , {
2527 env : {
2628 ...process . env ,
2729 SERVER_PORT : serverPort ,
2830 CLIENT_PORT : clientPort ,
31+ MCP_PROXY_AUTH_TOKEN : sessionToken ,
32+ ALLOWED_ORIGINS : [
33+ `http://localhost:${ clientPort } ` ,
34+ `http://127.0.0.1:${ clientPort } ` ,
35+ `http://localhost:${ process . env . PORT } ` ,
36+ `http://127.0.0.1:${ process . env . PORT } ` ,
37+ ] . join ( ',' ) ,
2938 } ,
3039 stdio : [ 'inherit' , 'pipe' , 'inherit' ] , // capture stdout
3140} )
3241
42+ /*
43+ Starting MCP inspector...
44+
45+ ⚙️ Proxy server listening on 127.0.0.1:10000
46+
47+ 🔑 Session token: 5c96a97c78de97283c838754ea89a74283d5ce87692dbe4a4903c416ae64fc6b
48+ Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth
49+
50+ 🔗 Open inspector with token pre-filled:
51+ http://localhost:9000/?MCP_PROXY_AUTH_TOKEN=5c96a97c78de97283c838754ea89a74283d5ce87692dbe4a4903c416ae64fc6b
52+ (Auto-open is disabled when authentication is enabled)
53+
54+ */
55+
3356// Wait for the inspector to be up before starting the proxy server
3457function waitForInspectorReady ( ) {
3558 return new Promise ( ( resolve ) => {
@@ -68,6 +91,7 @@ const server = createServer((req, res) => {
6891 url . searchParams . set ( 'transport' , transport )
6992 url . searchParams . set ( 'serverCommand' , command )
7093 url . searchParams . set ( 'serverArgs' , args )
94+ url . searchParams . set ( 'MCP_PROXY_AUTH_TOKEN' , sessionToken )
7195 url . searchParams . set (
7296 'MCP_PROXY_FULL_ADDRESS' ,
7397 `http://localhost:${ serverPort } ` ,
0 commit comments