Skip to content

Commit 3c5c384

Browse files
committed
feat(client): initialize via search params
1 parent 3e41520 commit 3c5c384

File tree

3 files changed

+64
-18
lines changed

3 files changed

+64
-18
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ Example server configuration file:
9393
}
9494
```
9595

96+
You can also set the initial `transport` type, `serverUrl`, `serverCommand`, and `serverArgs` via query params, for example:
97+
98+
```
99+
http://localhost:6274/?transport=sse&serverUrl=http://localhost:8787/sse
100+
http://localhost:6274/?transport=streamable-http&serverUrl=http://localhost:8787/mcp
101+
http://localhost:6274/?transport=stdio&serverCommand=npx&serverArgs=arg1%20arg2
102+
```
103+
104+
Note that if both the query param and the corresponding localStorage item are set, the query param will take precedence.
105+
96106
### From this repository
97107

98108
If you're working on the inspector itself:

client/src/App.tsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ import Sidebar from "./components/Sidebar";
5151
import ToolsTab from "./components/ToolsTab";
5252
import { DEFAULT_INSPECTOR_CONFIG } from "./lib/constants";
5353
import { InspectorConfig } from "./lib/configurationTypes";
54-
import { getMCPProxyAddress } from "./utils/configUtils";
54+
import {
55+
getMCPProxyAddress,
56+
getInitialSseUrl,
57+
getInitialTransportType,
58+
getInitialCommand,
59+
getInitialArgs,
60+
} from "./utils/configUtils";
5561

5662
const CONFIG_LOCAL_STORAGE_KEY = "inspectorConfig_v1";
5763

@@ -71,26 +77,13 @@ const App = () => {
7177
prompts: null,
7278
tools: null,
7379
});
74-
const [command, setCommand] = useState<string>(() => {
75-
return localStorage.getItem("lastCommand") || "mcp-server-everything";
76-
});
77-
const [args, setArgs] = useState<string>(() => {
78-
return localStorage.getItem("lastArgs") || "";
79-
});
80+
const [command, setCommand] = useState<string>(getInitialCommand);
81+
const [args, setArgs] = useState<string>(getInitialArgs);
8082

81-
const [sseUrl, setSseUrl] = useState<string>(() => {
82-
return localStorage.getItem("lastSseUrl") || "http://localhost:3001/sse";
83-
});
83+
const [sseUrl, setSseUrl] = useState<string>(getInitialSseUrl);
8484
const [transportType, setTransportType] = useState<
8585
"stdio" | "sse" | "streamable-http"
86-
>(() => {
87-
return (
88-
(localStorage.getItem("lastTransportType") as
89-
| "stdio"
90-
| "sse"
91-
| "streamable-http") || "stdio"
92-
);
93-
});
86+
>(getInitialTransportType);
9487
const [logLevel, setLogLevel] = useState<LoggingLevel>("debug");
9588
const [notifications, setNotifications] = useState<ServerNotification[]>([]);
9689
const [stdErrNotifications, setStdErrNotifications] = useState<

client/src/utils/configUtils.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,46 @@ export const getMCPServerRequestMaxTotalTimeout = (
2424
): number => {
2525
return config.MCP_REQUEST_MAX_TOTAL_TIMEOUT.value as number;
2626
};
27+
28+
const getSearchParam = (key: string): string | null => {
29+
try {
30+
const url = new URL(window.location.href);
31+
return url.searchParams.get(key);
32+
} catch {
33+
return null;
34+
}
35+
};
36+
37+
export const getInitialTransportType = ():
38+
| "stdio"
39+
| "sse"
40+
| "streamable-http" => {
41+
const param = getSearchParam("transport");
42+
if (param === "stdio" || param === "sse" || param === "streamable-http") {
43+
return param;
44+
}
45+
return (
46+
(localStorage.getItem("lastTransportType") as
47+
| "stdio"
48+
| "sse"
49+
| "streamable-http") || "stdio"
50+
);
51+
};
52+
53+
export const getInitialSseUrl = (): string => {
54+
const param = getSearchParam("serverUrl");
55+
if (param) return param;
56+
return localStorage.getItem("lastSseUrl") || "http://localhost:3001/sse";
57+
};
58+
59+
export const getInitialCommand = (): string => {
60+
const param = getSearchParam("serverCommand");
61+
if (param) return param;
62+
return localStorage.getItem("lastCommand") || "mcp-server-everything";
63+
};
64+
65+
export const getInitialArgs = (): string => {
66+
const param = getSearchParam("serverArgs");
67+
if (param) return param;
68+
return localStorage.getItem("lastArgs") || "";
69+
};

0 commit comments

Comments
 (0)