Skip to content

Commit 5028496

Browse files
authored
Merge pull request #517 from kentcdodds/patch-1
make auth token configurable via env var
2 parents 3acc6d8 + 5c15e50 commit 5028496

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ If you need to disable authentication (NOT RECOMMENDED), you can set the `DANGER
166166
DANGEROUSLY_OMIT_AUTH=true npm start
167167
```
168168

169+
You can also set the token via the `MCP_PROXY_AUTH_TOKEN` environment variable when starting the server:
170+
171+
```bash
172+
MCP_PROXY_AUTH_TOKEN=$(openssl rand -hex 32) npm start
173+
```
174+
169175
#### Local-only Binding
170176

171177
By default, both the MCP Inspector proxy server and client bind only to `localhost` to prevent network access. This ensures they are not accessible from other devices on the network. If you need to bind to all interfaces for development purposes, you can override this with the `HOST` environment variable:

client/bin/start.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function startDevServer(serverOptions) {
4040
...process.env,
4141
SERVER_PORT,
4242
CLIENT_PORT,
43-
MCP_PROXY_TOKEN: sessionToken,
43+
MCP_PROXY_AUTH_TOKEN: sessionToken,
4444
MCP_ENV_VARS: JSON.stringify(envVars),
4545
},
4646
signal: abort.signal,
@@ -99,7 +99,7 @@ async function startProdServer(serverOptions) {
9999
...process.env,
100100
SERVER_PORT,
101101
CLIENT_PORT,
102-
MCP_PROXY_TOKEN: sessionToken,
102+
MCP_PROXY_AUTH_TOKEN: sessionToken,
103103
MCP_ENV_VARS: JSON.stringify(envVars),
104104
},
105105
signal: abort.signal,
@@ -247,8 +247,9 @@ async function main() {
247247
: "Starting MCP inspector...",
248248
);
249249

250-
// Generate session token for authentication
251-
const sessionToken = randomBytes(32).toString("hex");
250+
// Use provided token from environment or generate a new one
251+
const sessionToken =
252+
process.env.MCP_PROXY_AUTH_TOKEN || randomBytes(32).toString("hex");
252253
const authDisabled = !!process.env.DANGEROUSLY_OMIT_AUTH;
253254

254255
const abort = new AbortController();

server/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const serverTransports: Map<string, Transport> = new Map<string, Transport>(); /
9292

9393
// Use provided token from environment or generate a new one
9494
const sessionToken =
95-
process.env.MCP_PROXY_TOKEN || randomBytes(32).toString("hex");
95+
process.env.MCP_PROXY_AUTH_TOKEN || randomBytes(32).toString("hex");
9696
const authDisabled = !!process.env.DANGEROUSLY_OMIT_AUTH;
9797

9898
// Origin validation middleware to prevent DNS rebinding attacks

0 commit comments

Comments
 (0)