@modelcontextprotocol/inspector 0.2.2 → 0.2.3

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.
package/README.md CHANGED
@@ -2,18 +2,47 @@
2
2
 
3
3
  The MCP inspector is a developer tool for testing and debugging MCP servers.
4
4
 
5
- It can be run easily from `npx`. For example, in a folder where there's a built JavaScript server at `build/index.js`:
5
+ ![MCP Inspector Screenshot](mcp-inspector.png)
6
6
 
7
- ```
7
+ ## Running the Inspector
8
+
9
+ ### From an MCP server repository
10
+
11
+ To inspect an MCP server implementation, there's no need to clone this repo. Instead, use `npx`. For example, if your server is built at `build/index.js`:
12
+
13
+ ```bash
8
14
  npx @modelcontextprotocol/inspector build/index.js
9
15
  ```
10
16
 
11
- You can also pass arguments along to the server:
17
+ You can also pass arguments along which will get passed as arguments to your MCP server:
12
18
 
13
19
  ```
14
20
  npx @modelcontextprotocol/inspector build/index.js arg1 arg2 ...
15
21
  ```
16
22
 
23
+ The inspector runs both a client UI (default port 5173) and an MCP proxy server (default port 3000). Open the client UI in your browser to use the inspector. You can customize the ports if needed:
24
+
25
+ ```bash
26
+ CLIENT_PORT=8080 SERVER_PORT=9000 npx @modelcontextprotocol/inspector build/index.js
27
+ ```
28
+
29
+ ### From this repository
30
+
31
+ If you're working on the inspector itself:
32
+
33
+ Development mode:
34
+
35
+ ```bash
36
+ npm run dev
37
+ ```
38
+
39
+ Production mode:
40
+
41
+ ```bash
42
+ npm run build
43
+ npm start
44
+ ```
45
+
17
46
  ## License
18
47
 
19
48
  This project is licensed under the MIT License—see the [LICENSE](LICENSE) file for details.
package/bin/cli.js CHANGED
@@ -1,65 +1,82 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { join, dirname } from "path";
3
+ import { resolve, dirname } from "path";
4
+ import { spawnPromise } from "spawn-rx";
4
5
  import { fileURLToPath } from "url";
5
- import concurrently from "concurrently";
6
6
 
7
7
  const __dirname = dirname(fileURLToPath(import.meta.url));
8
8
 
9
- // Get command line arguments
10
- const [, , command, ...mcpServerArgs] = process.argv;
9
+ function delay(ms) {
10
+ return new Promise((resolve) => setTimeout(resolve, ms));
11
+ }
12
+
13
+ async function main() {
14
+ // Get command line arguments
15
+ const [, , command, ...mcpServerArgs] = process.argv;
16
+
17
+ const inspectorServerPath = resolve(
18
+ __dirname,
19
+ "..",
20
+ "server",
21
+ "build",
22
+ "index.js",
23
+ );
24
+
25
+ // Path to the client entry point
26
+ const inspectorClientPath = resolve(
27
+ __dirname,
28
+ "..",
29
+ "client",
30
+ "bin",
31
+ "cli.js",
32
+ );
33
+
34
+ const CLIENT_PORT = process.env.CLIENT_PORT ?? "5173";
35
+ const SERVER_PORT = process.env.SERVER_PORT ?? "3000";
11
36
 
12
- const inspectorServerPath = join(__dirname, "../server/build/index.js");
37
+ console.log("Starting MCP inspector...");
13
38
 
14
- // Path to the client entry point
15
- const inspectorClientPath = join(__dirname, "../client/bin/cli.js");
39
+ const abort = new AbortController();
16
40
 
17
- console.log("Starting MCP inspector...");
41
+ let cancelled = false;
42
+ process.on("SIGINT", () => {
43
+ cancelled = true;
44
+ abort.abort();
45
+ });
18
46
 
19
- function escapeArg(arg) {
20
- if (arg.includes(" ") || arg.includes("'") || arg.includes('"')) {
21
- return `\\"${arg.replace(/"/g, '\\\\\\"')}\\"`;
47
+ const server = spawnPromise(
48
+ "node",
49
+ [
50
+ inspectorServerPath,
51
+ ...(command ? [`--env`, command] : []),
52
+ ...(mcpServerArgs ? ["--args", mcpServerArgs.join(" ")] : []),
53
+ ],
54
+ { env: { ...process.env, PORT: SERVER_PORT }, signal: abort.signal },
55
+ );
56
+
57
+ const client = spawnPromise("node", [inspectorClientPath], {
58
+ env: { ...process.env, PORT: CLIENT_PORT },
59
+ signal: abort.signal,
60
+ });
61
+
62
+ // Make sure our server/client didn't immediately fail
63
+ await Promise.any([server, client, delay(2 * 1000)]);
64
+ console.log(
65
+ `\n🔍 MCP Inspector is up and running at http://localhost:${CLIENT_PORT} 🚀`,
66
+ );
67
+
68
+ try {
69
+ await Promise.any([server, client]);
70
+ } catch (e) {
71
+ if (!cancelled || process.env.DEBUG) throw e;
22
72
  }
23
- return arg;
73
+
74
+ return 0;
24
75
  }
25
76
 
26
- const serverCommand = [
27
- `node`,
28
- inspectorServerPath,
29
- command ? `--env ${escapeArg(command)}` : "",
30
- mcpServerArgs.length
31
- ? `--args="${mcpServerArgs.map(escapeArg).join(" ")}"`
32
- : "",
33
- ]
34
- .filter(Boolean)
35
- .join(" ");
36
-
37
- const CLIENT_PORT = process.env.CLIENT_PORT ?? "";
38
- const SERVER_PORT = process.env.SERVER_PORT ?? "";
39
-
40
- const { result } = concurrently(
41
- [
42
- {
43
- command: `PORT=${SERVER_PORT} ${serverCommand}`,
44
- name: "server",
45
- },
46
- {
47
- command: `PORT=${CLIENT_PORT} node ${inspectorClientPath}`,
48
- name: "client",
49
- },
50
- ],
51
- {
52
- prefix: "name",
53
- killOthers: ["failure", "success"],
54
- restartTries: 3,
55
- },
56
- );
57
-
58
- console.log(
59
- `\n🔍 MCP Inspector is up and running at http://localhost:${CLIENT_PORT || 5173} 🚀`,
60
- );
61
-
62
- result.catch((err) => {
63
- console.error("An error occurred:", err);
64
- process.exit(1);
65
- });
77
+ main()
78
+ .then((_) => process.exit(0))
79
+ .catch((e) => {
80
+ console.error(e);
81
+ process.exit(1);
82
+ });