@modelcontextprotocol/inspector 1.0.0 → 2.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +199 -351
  2. package/clients/cli/build/index.js +13218 -0
  3. package/clients/launcher/build/index.js +90 -0
  4. package/clients/launcher/build/parse-launcher-argv.js +29 -0
  5. package/clients/tui/build/chunk-MCKGQKYU.js +15 -0
  6. package/clients/tui/build/index.js +14573 -0
  7. package/clients/tui/build/undici-HXPKCIY3.js +25789 -0
  8. package/clients/web/build/chunk-MCKGQKYU.js +15 -0
  9. package/clients/web/build/index.js +4322 -0
  10. package/clients/web/build/undici-HXPKCIY3.js +25789 -0
  11. package/clients/web/dist/assets/css-DfBGKsUM.js +1 -0
  12. package/clients/web/dist/assets/index-Cbtmmw0V.js +300 -0
  13. package/clients/web/dist/assets/index-CiUpWldH.css +1 -0
  14. package/clients/web/dist/assets/json-rfaH9Mx5.js +1 -0
  15. package/clients/web/dist/assets/markdown-PVXc4EJ0.js +1 -0
  16. package/clients/web/dist/assets/markup-Bk4keGDK.js +1 -0
  17. package/clients/web/dist/assets/markup-DPsXihXF.js +1 -0
  18. package/clients/web/dist/assets/prism-light-B8tIwqDr.js +6 -0
  19. package/clients/web/dist/assets/tomorrow-COrD2Qnh.js +1 -0
  20. package/clients/web/dist/assets/yaml-B78V9E0m.js +1 -0
  21. package/clients/web/dist/icons.svg +24 -0
  22. package/clients/web/dist/index.html +17 -0
  23. package/package.json +96 -80
  24. package/scripts/install-clients.mjs +65 -0
  25. package/LICENSE +0 -216
  26. package/cli/build/cli.js +0 -277
  27. package/cli/build/client/connection.js +0 -38
  28. package/cli/build/client/index.js +0 -6
  29. package/cli/build/client/prompts.js +0 -43
  30. package/cli/build/client/resources.js +0 -36
  31. package/cli/build/client/tools.js +0 -87
  32. package/cli/build/client/types.js +0 -1
  33. package/cli/build/error-handler.js +0 -18
  34. package/cli/build/index.js +0 -257
  35. package/cli/build/transport.js +0 -65
  36. package/cli/build/utils/awaitable-log.js +0 -7
  37. package/client/bin/client.js +0 -62
  38. package/client/bin/start.js +0 -350
  39. package/client/dist/assets/OAuthCallback-D56s1eS_.js +0 -55
  40. package/client/dist/assets/OAuthDebugCallback-CdGJkhXe.js +0 -64
  41. package/client/dist/assets/index-BlUSNvoM.css +0 -2738
  42. package/client/dist/assets/index-DjSLdS7f.js +0 -66698
  43. package/client/dist/index.html +0 -14
  44. package/server/build/index.js +0 -886
  45. package/server/build/mcpProxy.js +0 -121
  46. package/server/build/static/sandbox_proxy.html +0 -197
  47. package/server/static/sandbox_proxy.html +0 -197
  48. /package/{client/dist/mcp.svg → clients/web/dist/assets/MCP-CWGQJYyH.svg} +0 -0
@@ -1,350 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import open from "open";
4
- import { resolve, dirname } from "path";
5
- import { spawnPromise, spawn } from "spawn-rx";
6
- import { fileURLToPath } from "url";
7
- import { randomBytes } from "crypto";
8
-
9
- const __dirname = dirname(fileURLToPath(import.meta.url));
10
- const DEFAULT_MCP_PROXY_LISTEN_PORT = "6277";
11
-
12
- function delay(ms) {
13
- return new Promise((resolve) => setTimeout(resolve, ms, true));
14
- }
15
-
16
- function getClientUrl(port, authDisabled, sessionToken, serverPort) {
17
- const host = process.env.HOST || "localhost";
18
- const baseUrl = `http://${host}:${port}`;
19
-
20
- const params = new URLSearchParams();
21
- if (serverPort && serverPort !== DEFAULT_MCP_PROXY_LISTEN_PORT) {
22
- params.set("MCP_PROXY_PORT", serverPort);
23
- }
24
- if (!authDisabled) {
25
- params.set("MCP_PROXY_AUTH_TOKEN", sessionToken);
26
- }
27
- return params.size > 0 ? `${baseUrl}/?${params.toString()}` : baseUrl;
28
- }
29
-
30
- async function startDevServer(serverOptions) {
31
- const {
32
- SERVER_PORT,
33
- CLIENT_PORT,
34
- sessionToken,
35
- envVars,
36
- abort,
37
- transport,
38
- serverUrl,
39
- } = serverOptions;
40
- const serverCommand = "npx";
41
- const serverArgs = ["tsx", "watch", "--clear-screen=false", "src/index.ts"];
42
- const isWindows = process.platform === "win32";
43
-
44
- const spawnOptions = {
45
- cwd: resolve(__dirname, "../..", "server"),
46
- env: {
47
- ...process.env,
48
- SERVER_PORT,
49
- CLIENT_PORT,
50
- MCP_PROXY_AUTH_TOKEN: sessionToken,
51
- MCP_ENV_VARS: JSON.stringify(envVars),
52
- ...(transport ? { MCP_TRANSPORT: transport } : {}),
53
- ...(serverUrl ? { MCP_SERVER_URL: serverUrl } : {}),
54
- },
55
- signal: abort.signal,
56
- echoOutput: true,
57
- };
58
-
59
- // For Windows, we need to ignore stdin to simulate < NUL
60
- // spawn-rx's 'stdin' option expects an Observable, not 'ignore'
61
- // Use Node's stdio option instead
62
- if (isWindows) {
63
- spawnOptions.stdio = ["ignore", "pipe", "pipe"];
64
- }
65
-
66
- const server = spawn(serverCommand, serverArgs, spawnOptions);
67
-
68
- // Give server time to start
69
- const serverOk = await Promise.race([
70
- new Promise((resolve) => {
71
- server.subscribe({
72
- complete: () => resolve(false),
73
- error: () => resolve(false),
74
- next: () => {}, // We're using echoOutput
75
- });
76
- }),
77
- delay(3000).then(() => true),
78
- ]);
79
-
80
- return { server, serverOk };
81
- }
82
-
83
- async function startProdServer(serverOptions) {
84
- const {
85
- SERVER_PORT,
86
- CLIENT_PORT,
87
- sessionToken,
88
- envVars,
89
- abort,
90
- command,
91
- mcpServerArgs,
92
- transport,
93
- serverUrl,
94
- } = serverOptions;
95
- const inspectorServerPath = resolve(
96
- __dirname,
97
- "../..",
98
- "server",
99
- "build",
100
- "index.js",
101
- );
102
-
103
- const server = spawnPromise(
104
- "node",
105
- [
106
- inspectorServerPath,
107
- ...(command ? [`--command=${command}`] : []),
108
- ...(mcpServerArgs && mcpServerArgs.length > 0
109
- ? [`--args=${mcpServerArgs.join(" ")}`]
110
- : []),
111
- ...(transport ? [`--transport=${transport}`] : []),
112
- ...(serverUrl ? [`--server-url=${serverUrl}`] : []),
113
- ],
114
- {
115
- env: {
116
- ...process.env,
117
- SERVER_PORT,
118
- CLIENT_PORT,
119
- MCP_PROXY_AUTH_TOKEN: sessionToken,
120
- MCP_ENV_VARS: JSON.stringify(envVars),
121
- },
122
- signal: abort.signal,
123
- echoOutput: true,
124
- },
125
- );
126
-
127
- // Make sure server started before starting client
128
- const serverOk = await Promise.race([server, delay(2 * 1000)]);
129
-
130
- return { server, serverOk };
131
- }
132
-
133
- async function startDevClient(clientOptions) {
134
- const {
135
- CLIENT_PORT,
136
- SERVER_PORT,
137
- authDisabled,
138
- sessionToken,
139
- abort,
140
- cancelled,
141
- } = clientOptions;
142
- const clientCommand = "npx";
143
- const host = process.env.HOST || "localhost";
144
- const clientArgs = ["vite", "--port", CLIENT_PORT, "--host", host];
145
- const isWindows = process.platform === "win32";
146
-
147
- const spawnOptions = {
148
- cwd: resolve(__dirname, ".."),
149
- env: { ...process.env, CLIENT_PORT },
150
- signal: abort.signal,
151
- echoOutput: true,
152
- };
153
-
154
- // For Windows, we need to ignore stdin to prevent hanging
155
- if (isWindows) {
156
- spawnOptions.stdio = ["ignore", "pipe", "pipe"];
157
- }
158
-
159
- const client = spawn(clientCommand, clientArgs, spawnOptions);
160
-
161
- const url = getClientUrl(
162
- CLIENT_PORT,
163
- authDisabled,
164
- sessionToken,
165
- SERVER_PORT,
166
- );
167
-
168
- // Give vite time to start before opening or logging the URL
169
- setTimeout(() => {
170
- console.log(`\n🚀 MCP Inspector is up and running at:\n ${url}\n`);
171
- if (process.env.MCP_AUTO_OPEN_ENABLED !== "false") {
172
- console.log("🌐 Opening browser...");
173
- open(url);
174
- }
175
- }, 3000);
176
-
177
- await new Promise((resolve) => {
178
- client.subscribe({
179
- complete: resolve,
180
- error: (err) => {
181
- if (!cancelled || process.env.DEBUG) {
182
- console.error("Client error:", err);
183
- }
184
- resolve(null);
185
- },
186
- next: () => {}, // We're using echoOutput
187
- });
188
- });
189
- }
190
-
191
- async function startProdClient(clientOptions) {
192
- const {
193
- CLIENT_PORT,
194
- SERVER_PORT,
195
- authDisabled,
196
- sessionToken,
197
- abort,
198
- cancelled,
199
- } = clientOptions;
200
- const inspectorClientPath = resolve(
201
- __dirname,
202
- "../..",
203
- "client",
204
- "bin",
205
- "client.js",
206
- );
207
-
208
- const url = getClientUrl(
209
- CLIENT_PORT,
210
- authDisabled,
211
- sessionToken,
212
- SERVER_PORT,
213
- );
214
-
215
- await spawnPromise("node", [inspectorClientPath], {
216
- env: {
217
- ...process.env,
218
- CLIENT_PORT,
219
- INSPECTOR_URL: url,
220
- },
221
- signal: abort.signal,
222
- echoOutput: true,
223
- });
224
- }
225
-
226
- async function main() {
227
- // Parse command line arguments
228
- const args = process.argv.slice(2);
229
- const envVars = {};
230
- const mcpServerArgs = [];
231
- let command = null;
232
- let parsingFlags = true;
233
- let isDev = false;
234
- let transport = null;
235
- let serverUrl = null;
236
-
237
- for (let i = 0; i < args.length; i++) {
238
- const arg = args[i];
239
-
240
- if (parsingFlags && arg === "--") {
241
- parsingFlags = false;
242
- continue;
243
- }
244
-
245
- if (parsingFlags && arg === "--dev") {
246
- isDev = true;
247
- continue;
248
- }
249
-
250
- if (parsingFlags && arg === "--transport" && i + 1 < args.length) {
251
- transport = args[++i];
252
- continue;
253
- }
254
-
255
- if (parsingFlags && arg === "--server-url" && i + 1 < args.length) {
256
- serverUrl = args[++i];
257
- continue;
258
- }
259
-
260
- if (parsingFlags && arg === "-e" && i + 1 < args.length) {
261
- const envVar = args[++i];
262
- const equalsIndex = envVar.indexOf("=");
263
-
264
- if (equalsIndex !== -1) {
265
- const key = envVar.substring(0, equalsIndex);
266
- const value = envVar.substring(equalsIndex + 1);
267
- envVars[key] = value;
268
- } else {
269
- envVars[envVar] = "";
270
- }
271
- } else if (!command && !isDev) {
272
- command = arg;
273
- } else if (!isDev) {
274
- mcpServerArgs.push(arg);
275
- }
276
- }
277
-
278
- const CLIENT_PORT = process.env.CLIENT_PORT ?? "6274";
279
- const SERVER_PORT = process.env.SERVER_PORT ?? DEFAULT_MCP_PROXY_LISTEN_PORT;
280
-
281
- console.log(
282
- isDev
283
- ? "Starting MCP inspector in development mode..."
284
- : "Starting MCP inspector...",
285
- );
286
-
287
- // Use provided token from environment or generate a new one
288
- const sessionToken =
289
- process.env.MCP_PROXY_AUTH_TOKEN || randomBytes(32).toString("hex");
290
- const authDisabled = !!process.env.DANGEROUSLY_OMIT_AUTH;
291
-
292
- const abort = new AbortController();
293
-
294
- let cancelled = false;
295
- process.on("SIGINT", () => {
296
- cancelled = true;
297
- abort.abort();
298
- });
299
-
300
- let server, serverOk;
301
-
302
- try {
303
- const serverOptions = {
304
- SERVER_PORT,
305
- CLIENT_PORT,
306
- sessionToken,
307
- envVars,
308
- abort,
309
- command,
310
- mcpServerArgs,
311
- transport,
312
- serverUrl,
313
- };
314
-
315
- const result = isDev
316
- ? await startDevServer(serverOptions)
317
- : await startProdServer(serverOptions);
318
-
319
- server = result.server;
320
- serverOk = result.serverOk;
321
- } catch (error) {}
322
-
323
- if (serverOk) {
324
- try {
325
- const clientOptions = {
326
- CLIENT_PORT,
327
- SERVER_PORT,
328
- authDisabled,
329
- sessionToken,
330
- abort,
331
- cancelled,
332
- };
333
-
334
- await (isDev
335
- ? startDevClient(clientOptions)
336
- : startProdClient(clientOptions));
337
- } catch (e) {
338
- if (!cancelled || process.env.DEBUG) throw e;
339
- }
340
- }
341
-
342
- return 0;
343
- }
344
-
345
- main()
346
- .then((_) => process.exit(0))
347
- .catch((e) => {
348
- console.error(e);
349
- process.exit(1);
350
- });
@@ -1,55 +0,0 @@
1
- import { u as useToast, r as reactExports, j as jsxRuntimeExports, p as parseOAuthCallbackParams, g as generateOAuthErrorDescription, S as SESSION_KEYS, I as InspectorOAuthClientProvider, a as auth } from "./index-DjSLdS7f.js";
2
- const OAuthCallback = ({ onConnect }) => {
3
- const { toast } = useToast();
4
- const hasProcessedRef = reactExports.useRef(false);
5
- reactExports.useEffect(() => {
6
- const handleCallback = async () => {
7
- if (hasProcessedRef.current) {
8
- return;
9
- }
10
- hasProcessedRef.current = true;
11
- const notifyError = (description) => void toast({
12
- title: "OAuth Authorization Error",
13
- description,
14
- variant: "destructive"
15
- });
16
- const params = parseOAuthCallbackParams(window.location.search);
17
- if (!params.successful) {
18
- return notifyError(generateOAuthErrorDescription(params));
19
- }
20
- const serverUrl = sessionStorage.getItem(SESSION_KEYS.SERVER_URL);
21
- if (!serverUrl) {
22
- return notifyError("Missing Server URL");
23
- }
24
- let result;
25
- try {
26
- const serverAuthProvider = new InspectorOAuthClientProvider(serverUrl);
27
- result = await auth(serverAuthProvider, {
28
- serverUrl,
29
- authorizationCode: params.code
30
- });
31
- } catch (error) {
32
- console.error("OAuth callback error:", error);
33
- return notifyError(`Unexpected error occurred: ${error}`);
34
- }
35
- if (result !== "AUTHORIZED") {
36
- return notifyError(
37
- `Expected to be authorized after providing auth code, got: ${result}`
38
- );
39
- }
40
- toast({
41
- title: "Success",
42
- description: "Successfully authenticated with OAuth",
43
- variant: "default"
44
- });
45
- onConnect(serverUrl);
46
- };
47
- handleCallback().finally(() => {
48
- window.history.replaceState({}, document.title, "/");
49
- });
50
- }, [toast, onConnect]);
51
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-screen", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-lg text-gray-500", children: "Processing OAuth callback..." }) });
52
- };
53
- export {
54
- OAuthCallback as default
55
- };
@@ -1,64 +0,0 @@
1
- import { r as reactExports, S as SESSION_KEYS, p as parseOAuthCallbackParams, j as jsxRuntimeExports, g as generateOAuthErrorDescription } from "./index-DjSLdS7f.js";
2
- const OAuthDebugCallback = ({ onConnect }) => {
3
- reactExports.useEffect(() => {
4
- let isProcessed = false;
5
- const handleCallback = async () => {
6
- if (isProcessed) {
7
- return;
8
- }
9
- isProcessed = true;
10
- const params = parseOAuthCallbackParams(window.location.search);
11
- if (!params.successful) {
12
- const errorMsg = generateOAuthErrorDescription(params);
13
- onConnect({ errorMsg });
14
- return;
15
- }
16
- const serverUrl = sessionStorage.getItem(SESSION_KEYS.SERVER_URL);
17
- const storedState = sessionStorage.getItem(
18
- SESSION_KEYS.AUTH_DEBUGGER_STATE
19
- );
20
- let restoredState = null;
21
- if (storedState) {
22
- try {
23
- restoredState = JSON.parse(storedState);
24
- if (restoredState && typeof restoredState.resource === "string") {
25
- restoredState.resource = new URL(restoredState.resource);
26
- }
27
- if (restoredState && typeof restoredState.authorizationUrl === "string") {
28
- restoredState.authorizationUrl = new URL(
29
- restoredState.authorizationUrl
30
- );
31
- }
32
- sessionStorage.removeItem(SESSION_KEYS.AUTH_DEBUGGER_STATE);
33
- } catch (e) {
34
- console.error("Failed to parse stored auth state:", e);
35
- }
36
- }
37
- if (!serverUrl) {
38
- return;
39
- }
40
- if (!params.code) {
41
- onConnect({ errorMsg: "Missing authorization code" });
42
- return;
43
- }
44
- onConnect({ authorizationCode: params.code, restoredState });
45
- };
46
- handleCallback().finally(() => {
47
- if (sessionStorage.getItem(SESSION_KEYS.SERVER_URL)) {
48
- window.history.replaceState({}, document.title, "/");
49
- }
50
- });
51
- return () => {
52
- isProcessed = true;
53
- };
54
- }, [onConnect]);
55
- const callbackParams = parseOAuthCallbackParams(window.location.search);
56
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex items-center justify-center h-screen", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-4 p-4 bg-secondary rounded-md max-w-md", children: [
57
- /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "mb-2 text-sm", children: "Please copy this authorization code and return to the Auth Debugger:" }),
58
- /* @__PURE__ */ jsxRuntimeExports.jsx("code", { className: "block p-2 bg-muted rounded-sm overflow-x-auto text-xs", children: callbackParams.successful && "code" in callbackParams ? callbackParams.code : `No code found: ${callbackParams.error}, ${callbackParams.error_description}` }),
59
- /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "mt-4 text-xs text-muted-foreground", children: "Close this tab and paste the code in the OAuth flow to complete authentication." })
60
- ] }) });
61
- };
62
- export {
63
- OAuthDebugCallback as default
64
- };