fix: pass proxy port via URL params when non-default
- Update client to read MCP_PROXY_PORT from URL parameters - Update server to include port in displayed URL when non-default - Update start scripts to pass SERVER_PORT to client - Use DEFAULT_MCP_PROXY_LISTEN_PORT constant instead of magic numbers This fixes the issue where the client couldn't connect to the proxy when SERVER_PORT was set to a non-default value.
This commit is contained in:
parent
eb5be0d853
commit
9fcfd89326
1 changed files with 77 additions and 23 deletions
|
|
@ -21,6 +21,7 @@ import { findActualExecutable } from "spawn-rx";
|
|||
import mcpProxy from "./mcpProxy.js";
|
||||
import { randomUUID, randomBytes, timingSafeEqual } from "node:crypto";
|
||||
|
||||
const DEFAULT_MCP_PROXY_LISTEN_PORT = "6277";
|
||||
const SSE_HEADERS_PASSTHROUGH = ["authorization"];
|
||||
const STREAMABLE_HTTP_HEADERS_PASSTHROUGH = [
|
||||
"authorization",
|
||||
|
|
@ -528,7 +529,10 @@ app.get("/config", originValidationMiddleware, authMiddleware, (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
const PORT = parseInt(process.env.SERVER_PORT || "6277", 10);
|
||||
const PORT = parseInt(
|
||||
process.env.SERVER_PORT || DEFAULT_MCP_PROXY_LISTEN_PORT,
|
||||
10,
|
||||
);
|
||||
const HOST = process.env.HOST || "localhost";
|
||||
|
||||
const server = app.listen(PORT, HOST);
|
||||
|
|
@ -543,7 +547,17 @@ server.on("listening", () => {
|
|||
// Display clickable URL with pre-filled token
|
||||
const clientPort = process.env.CLIENT_PORT || "6274";
|
||||
const clientHost = process.env.HOST || "localhost";
|
||||
const clientUrl = `http://${clientHost}:${clientPort}/?MCP_PROXY_AUTH_TOKEN=${sessionToken}`;
|
||||
|
||||
// Build URL with query parameters
|
||||
const params = new URLSearchParams();
|
||||
params.set("MCP_PROXY_AUTH_TOKEN", sessionToken);
|
||||
|
||||
// Add server port if it's not the default
|
||||
if (PORT !== parseInt(DEFAULT_MCP_PROXY_LISTEN_PORT, 10)) {
|
||||
params.set("MCP_PROXY_PORT", PORT.toString());
|
||||
}
|
||||
|
||||
const clientUrl = `http://${clientHost}:${clientPort}/?${params.toString()}`;
|
||||
console.log(
|
||||
`\n🔗 Open inspector with token pre-filled:\n ${clientUrl}\n`,
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue