Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion client/bin/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms, true));
}

function getClientUrl(port, authDisabled, sessionToken, serverPort) {
function getClientUrl(
port,
authDisabled,
sessionToken,
serverPort,
upstreamSocks5Proxy,
) {
const host = process.env.HOST || "localhost";
const baseUrl = `http://${host}:${port}`;

Expand All @@ -24,6 +30,9 @@ function getClientUrl(port, authDisabled, sessionToken, serverPort) {
if (!authDisabled) {
params.set("MCP_PROXY_AUTH_TOKEN", sessionToken);
}
if (upstreamSocks5Proxy) {
params.set("MCP_UPSTREAM_SOCKS5_PROXY", upstreamSocks5Proxy);
}
return params.size > 0 ? `${baseUrl}/?${params.toString()}` : baseUrl;
}

Expand All @@ -36,6 +45,7 @@ async function startDevServer(serverOptions) {
abort,
transport,
serverUrl,
upstreamSocks5Proxy,
} = serverOptions;
const serverCommand = "npx";
const serverArgs = ["tsx", "watch", "--clear-screen=false", "src/index.ts"];
Expand All @@ -51,6 +61,9 @@ async function startDevServer(serverOptions) {
MCP_ENV_VARS: JSON.stringify(envVars),
...(transport ? { MCP_TRANSPORT: transport } : {}),
...(serverUrl ? { MCP_SERVER_URL: serverUrl } : {}),
...(upstreamSocks5Proxy
? { MCP_UPSTREAM_SOCKS5_PROXY: upstreamSocks5Proxy }
: {}),
},
signal: abort.signal,
echoOutput: true,
Expand Down Expand Up @@ -91,6 +104,7 @@ async function startProdServer(serverOptions) {
mcpServerArgs,
transport,
serverUrl,
upstreamSocks5Proxy,
} = serverOptions;
const inspectorServerPath = resolve(
__dirname,
Expand All @@ -110,6 +124,7 @@ async function startProdServer(serverOptions) {
: []),
...(transport ? [`--transport=${transport}`] : []),
...(serverUrl ? [`--server-url=${serverUrl}`] : []),
...(upstreamSocks5Proxy ? [`--socks5=${upstreamSocks5Proxy}`] : []),
],
{
env: {
Expand Down Expand Up @@ -138,6 +153,7 @@ async function startDevClient(clientOptions) {
sessionToken,
abort,
cancelled,
upstreamSocks5Proxy,
} = clientOptions;
const clientCommand = "npx";
const host = process.env.HOST || "localhost";
Expand All @@ -163,6 +179,7 @@ async function startDevClient(clientOptions) {
authDisabled,
sessionToken,
SERVER_PORT,
upstreamSocks5Proxy,
);

// Give vite time to start before opening or logging the URL
Expand Down Expand Up @@ -196,6 +213,7 @@ async function startProdClient(clientOptions) {
sessionToken,
abort,
cancelled,
upstreamSocks5Proxy,
} = clientOptions;
const inspectorClientPath = resolve(
__dirname,
Expand All @@ -210,6 +228,7 @@ async function startProdClient(clientOptions) {
authDisabled,
sessionToken,
SERVER_PORT,
upstreamSocks5Proxy,
);

await spawnPromise("node", [inspectorClientPath], {
Expand All @@ -233,6 +252,7 @@ async function main() {
let isDev = false;
let transport = null;
let serverUrl = null;
let upstreamSocks5Proxy = process.env.MCP_UPSTREAM_SOCKS5_PROXY || null;

for (let i = 0; i < args.length; i++) {
const arg = args[i];
Expand All @@ -257,6 +277,11 @@ async function main() {
continue;
}

if (parsingFlags && arg === "--socks5" && i + 1 < args.length) {
upstreamSocks5Proxy = args[++i];
continue;
}

if (parsingFlags && arg === "-e" && i + 1 < args.length) {
const envVar = args[++i];
const equalsIndex = envVar.indexOf("=");
Expand Down Expand Up @@ -310,6 +335,7 @@ async function main() {
mcpServerArgs,
transport,
serverUrl,
upstreamSocks5Proxy,
};

const result = isDev
Expand All @@ -329,6 +355,7 @@ async function main() {
sessionToken,
abort,
cancelled,
upstreamSocks5Proxy,
};

await (isDev
Expand Down
15 changes: 15 additions & 0 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,21 @@ const App = () => {
if (data.defaultServerUrl) {
setSseUrl(data.defaultServerUrl);
}
if (data.defaultUpstreamSocks5Proxy) {
setConfig((prev) => {
if (prev.MCP_UPSTREAM_SOCKS5_PROXY.value) {
return prev;
}

return {
...prev,
MCP_UPSTREAM_SOCKS5_PROXY: {
...prev.MCP_UPSTREAM_SOCKS5_PROXY,
value: data.defaultUpstreamSocks5Proxy,
},
};
});
}
})
.catch((error) =>
console.error("Error fetching default environment:", error),
Expand Down
5 changes: 5 additions & 0 deletions client/src/lib/configurationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export type InspectorConfig = {
*/
MCP_PROXY_AUTH_TOKEN: ConfigItem;

/**
* Optional SOCKS5 proxy URL used by the Inspector proxy server when connecting to upstream SSE or Streamable HTTP MCP servers.
*/
MCP_UPSTREAM_SOCKS5_PROXY: ConfigItem;

/**
* Default Time-to-Live (TTL) in milliseconds for newly created tasks.
*/
Expand Down
7 changes: 7 additions & 0 deletions client/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export const DEFAULT_INSPECTOR_CONFIG: InspectorConfig = {
value: "",
is_session_item: true,
},
MCP_UPSTREAM_SOCKS5_PROXY: {
label: "Upstream SOCKS5 Proxy",
description:
"Optional SOCKS5 proxy for the Inspector proxy server when it connects to upstream SSE or Streamable HTTP MCP servers. Example: socks5://127.0.0.1:1080",
value: "",
is_session_item: false,
},
MCP_TASK_TTL: {
label: "Task TTL",
description:
Expand Down
14 changes: 14 additions & 0 deletions client/src/lib/hooks/useConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ export function useConnection({
}

let mcpProxyServerUrl;
const upstreamSocks5Proxy = config.MCP_UPSTREAM_SOCKS5_PROXY
.value as string;
switch (transportType) {
case "stdio": {
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/stdio`);
Expand Down Expand Up @@ -680,6 +682,12 @@ export function useConnection({
case "sse": {
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/sse`);
mcpProxyServerUrl.searchParams.append("url", sseUrl);
if (upstreamSocks5Proxy) {
mcpProxyServerUrl.searchParams.append(
"socks5",
upstreamSocks5Proxy,
);
}

const proxyFullAddressSSE = config.MCP_PROXY_FULL_ADDRESS
.value as string;
Expand Down Expand Up @@ -711,6 +719,12 @@ export function useConnection({
case "streamable-http":
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/mcp`);
mcpProxyServerUrl.searchParams.append("url", sseUrl);
if (upstreamSocks5Proxy) {
mcpProxyServerUrl.searchParams.append(
"socks5",
upstreamSocks5Proxy,
);
}
transportOptions = {
authProvider: serverAuthProvider,
eventSourceInit: {
Expand Down
66 changes: 63 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
"node-fetch": "^3.3.2",
"open": "^10.2.0",
"shell-quote": "^1.8.3",
"socks-proxy-agent": "^10.0.0",
"spawn-rx": "^5.1.2",
"tailwind-merge": "^3.6.0",
"ts-node": "^10.9.2",
"zod": "^3.25.76"
},
Expand Down
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@modelcontextprotocol/sdk": "^1.25.2",
"cors": "^2.8.5",
"express": "^5.1.0",
"socks-proxy-agent": "^10.0.0",
"shell-quote": "^1.8.3",
"shx": "^0.3.4",
"spawn-rx": "^5.1.2",
Expand Down
Loading