Skip to content

Commit 886ac5f

Browse files
authored
Merge pull request modelcontextprotocol#81 from modelcontextprotocol/ashwin/serverport
Respect custom server port
2 parents 722df4d + f876b1e commit 886ac5f

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

bin/cli.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ async function main() {
6161

6262
// Make sure our server/client didn't immediately fail
6363
await Promise.any([server, client, delay(2 * 1000)]);
64+
const portParam = SERVER_PORT === "3000" ? "" : `?proxyPort=${SERVER_PORT}`;
6465
console.log(
65-
`\n🔍 MCP Inspector is up and running at http://localhost:${CLIENT_PORT} 🚀`,
66+
`\n🔍 MCP Inspector is up and running at http://localhost:${CLIENT_PORT}${portParam} 🚀`,
6667
);
6768

6869
try {

client/src/App.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ import ToolsTab from "./components/ToolsTab";
5757

5858
const DEFAULT_REQUEST_TIMEOUT_MSEC = 10000;
5959

60+
const params = new URLSearchParams(window.location.search);
61+
const PROXY_PORT = params.get("proxyPort") ?? "3000";
62+
const PROXY_SERVER_URL = `http://localhost:${PROXY_PORT}`;
63+
6064
const App = () => {
6165
const [connectionStatus, setConnectionStatus] = useState<
6266
"disconnected" | "connected" | "error"
@@ -82,7 +86,8 @@ const App = () => {
8286
const [args, setArgs] = useState<string>(() => {
8387
return localStorage.getItem("lastArgs") || "";
8488
});
85-
const [url, setUrl] = useState<string>("http://localhost:3001/sse");
89+
90+
const [sseUrl, setSseUrl] = useState<string>("http://localhost:3001/sse");
8691
const [transportType, setTransportType] = useState<"stdio" | "sse">("stdio");
8792
const [requestHistory, setRequestHistory] = useState<
8893
{ request: string; response?: string }[]
@@ -191,7 +196,7 @@ const App = () => {
191196
}, [args]);
192197

193198
useEffect(() => {
194-
fetch("http://localhost:3000/config")
199+
fetch(`${PROXY_SERVER_URL}/config`)
195200
.then((response) => response.json())
196201
.then((data) => {
197202
setEnv(data.defaultEnvironment);
@@ -404,15 +409,15 @@ const App = () => {
404409
},
405410
);
406411

407-
const backendUrl = new URL("http://localhost:3000/sse");
412+
const backendUrl = new URL(`${PROXY_SERVER_URL}/sse`);
408413

409414
backendUrl.searchParams.append("transportType", transportType);
410415
if (transportType === "stdio") {
411416
backendUrl.searchParams.append("command", command);
412417
backendUrl.searchParams.append("args", args);
413418
backendUrl.searchParams.append("env", JSON.stringify(env));
414419
} else {
415-
backendUrl.searchParams.append("url", url);
420+
backendUrl.searchParams.append("url", sseUrl);
416421
}
417422

418423
const clientTransport = new SSEClientTransport(backendUrl);
@@ -469,8 +474,8 @@ const App = () => {
469474
setCommand={setCommand}
470475
args={args}
471476
setArgs={setArgs}
472-
url={url}
473-
setUrl={setUrl}
477+
sseUrl={sseUrl}
478+
setSseUrl={setSseUrl}
474479
env={env}
475480
setEnv={setEnv}
476481
onConnect={connectMcpServer}

client/src/components/Sidebar.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ interface SidebarProps {
2222
setCommand: (command: string) => void;
2323
args: string;
2424
setArgs: (args: string) => void;
25-
url: string;
26-
setUrl: (url: string) => void;
25+
sseUrl: string;
26+
setSseUrl: (url: string) => void;
2727
env: Record<string, string>;
2828
setEnv: (env: Record<string, string>) => void;
2929
onConnect: () => void;
@@ -38,8 +38,8 @@ const Sidebar = ({
3838
setCommand,
3939
args,
4040
setArgs,
41-
url,
42-
setUrl,
41+
sseUrl,
42+
setSseUrl,
4343
env,
4444
setEnv,
4545
onConnect,
@@ -75,6 +75,7 @@ const Sidebar = ({
7575
</SelectContent>
7676
</Select>
7777
</div>
78+
7879
{transportType === "stdio" ? (
7980
<>
8081
<div className="space-y-2">
@@ -99,8 +100,8 @@ const Sidebar = ({
99100
<label className="text-sm font-medium">URL</label>
100101
<Input
101102
placeholder="URL"
102-
value={url}
103-
onChange={(e) => setUrl(e.target.value)}
103+
value={sseUrl}
104+
onChange={(e) => setSseUrl(e.target.value)}
104105
/>
105106
</div>
106107
)}

0 commit comments

Comments
 (0)