Fix transport type propagation from CLI to web client

- Add --transport and --server-url support to client/bin/start.js
- Pass transport configuration through server to client via /config endpoint
- Update client App.tsx to use defaultTransport and defaultServerUrl from server
- Ensure SSE and HTTP transport configs work properly from CLI
This commit is contained in:
Felix Weinberger 2025-08-05 19:38:44 +01:00
commit 7ea47c0caa
No known key found for this signature in database
3 changed files with 41 additions and 2 deletions

View file

@ -28,8 +28,15 @@ function getClientUrl(port, authDisabled, sessionToken, serverPort) {
}
async function startDevServer(serverOptions) {
const { SERVER_PORT, CLIENT_PORT, sessionToken, envVars, abort } =
serverOptions;
const {
SERVER_PORT,
CLIENT_PORT,
sessionToken,
envVars,
abort,
transport,
serverUrl,
} = serverOptions;
const serverCommand = "npx";
const serverArgs = ["tsx", "watch", "--clear-screen=false", "src/index.ts"];
const isWindows = process.platform === "win32";
@ -42,6 +49,8 @@ async function startDevServer(serverOptions) {
CLIENT_PORT,
MCP_PROXY_AUTH_TOKEN: sessionToken,
MCP_ENV_VARS: JSON.stringify(envVars),
...(transport ? { MCP_TRANSPORT: transport } : {}),
...(serverUrl ? { MCP_SERVER_URL: serverUrl } : {}),
},
signal: abort.signal,
echoOutput: true,
@ -78,6 +87,8 @@ async function startProdServer(serverOptions) {
abort,
command,
mcpServerArgs,
transport,
serverUrl,
} = serverOptions;
const inspectorServerPath = resolve(
__dirname,
@ -95,6 +106,8 @@ async function startProdServer(serverOptions) {
...(mcpServerArgs && mcpServerArgs.length > 0
? [`--args=${mcpServerArgs.join(" ")}`]
: []),
...(transport ? [`--transport=${transport}`] : []),
...(serverUrl ? [`--server-url=${serverUrl}`] : []),
],
{
env: {
@ -208,6 +221,8 @@ async function main() {
let command = null;
let parsingFlags = true;
let isDev = false;
let transport = null;
let serverUrl = null;
for (let i = 0; i < args.length; i++) {
const arg = args[i];
@ -222,6 +237,16 @@ async function main() {
continue;
}
if (parsingFlags && arg === "--transport" && i + 1 < args.length) {
transport = args[++i];
continue;
}
if (parsingFlags && arg === "--server-url" && i + 1 < args.length) {
serverUrl = args[++i];
continue;
}
if (parsingFlags && arg === "-e" && i + 1 < args.length) {
const envVar = args[++i];
const equalsIndex = envVar.indexOf("=");
@ -273,6 +298,8 @@ async function main() {
abort,
command,
mcpServerArgs,
transport,
serverUrl,
};
const result = isDev

View file

@ -455,6 +455,14 @@ const App = () => {
if (data.defaultArgs) {
setArgs(data.defaultArgs);
}
if (data.defaultTransport) {
setTransportType(
data.defaultTransport as "stdio" | "sse" | "streamable-http",
);
}
if (data.defaultServerUrl) {
setSseUrl(data.defaultServerUrl);
}
})
.catch((error) =>
console.error("Error fetching default environment:", error),

View file

@ -40,6 +40,8 @@ const { values } = parseArgs({
env: { type: "string", default: "" },
args: { type: "string", default: "" },
command: { type: "string", default: "" },
transport: { type: "string", default: "" },
"server-url": { type: "string", default: "" },
},
});
@ -523,6 +525,8 @@ app.get("/config", originValidationMiddleware, authMiddleware, (req, res) => {
defaultEnvironment,
defaultCommand: values.command,
defaultArgs: values.args,
defaultTransport: values.transport,
defaultServerUrl: values["server-url"],
});
} catch (error) {
console.error("Error in /config route:", error);