Skip to content

Commit b97acb9

Browse files
authored
Merge pull request modelcontextprotocol#61 from modelcontextprotocol/ashwin/npx
make inspector runnable via npx
2 parents b096f3f + 1b06e50 commit b97acb9

File tree

7 files changed

+41
-18
lines changed

7 files changed

+41
-18
lines changed

bin/cli.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@ import concurrently from "concurrently";
66

77
const __dirname = dirname(fileURLToPath(import.meta.url));
88

9-
// Paths to the server and client entry points
10-
const serverPath = join(__dirname, "../server/build/index.js");
11-
const clientPath = join(__dirname, "../client/bin/cli.js");
9+
// Get command line arguments
10+
const [, , command, ...mcpServerArgs] = process.argv;
11+
12+
const inspectorServerPath = join(__dirname, "../server/build/index.js");
13+
14+
// Path to the client entry point
15+
const inspectorClientPath = join(__dirname, "../client/bin/cli.js");
1216

1317
console.log("Starting MCP inspector...");
1418

1519
const { result } = concurrently(
1620
[
1721
{
18-
command: `node ${serverPath}`,
22+
command: `node ${inspectorServerPath}${command ? ` --env ${command}` : ""}${mcpServerArgs.length ? ` --args "${mcpServerArgs.join(" ")}"` : ""}`,
1923
name: "server",
2024
},
2125
{
22-
command: `node ${clientPath}`,
26+
command: `node ${inspectorClientPath}`,
2327
name: "client",
2428
},
2529
],

client/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "@modelcontextprotocol/inspector-client",
3-
"version": "0.1.0",
4-
"private": true,
3+
"version": "0.1.5",
54
"description": "Client-side application for the Model Context Protocol inspector",
65
"license": "MIT",
76
"author": "Anthropic, PBC (https://anthropic.com)",

client/src/App.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,13 @@ const App = () => {
186186
}, [args]);
187187

188188
useEffect(() => {
189-
fetch("http://localhost:3000/default-environment")
189+
fetch("http://localhost:3000/config")
190190
.then((response) => response.json())
191-
.then((data) => setEnv(data))
191+
.then((data) => {
192+
setEnv(data.defaultEnvironment);
193+
setCommand(data.defaultCommand);
194+
setArgs(data.defaultArgs);
195+
})
192196
.catch((error) =>
193197
console.error("Error fetching default environment:", error),
194198
);

package-lock.json

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "@modelcontextprotocol/inspector",
3-
"version": "0.1.0",
4-
"private": true,
3+
"version": "0.1.5",
54
"description": "Model Context Protocol inspector",
65
"license": "MIT",
76
"author": "Anthropic, PBC (https://anthropic.com)",
@@ -33,6 +32,8 @@
3332
"prettier-fix": "prettier --write ."
3433
},
3534
"dependencies": {
35+
"@modelcontextprotocol/inspector-client": "0.1.0",
36+
"@modelcontextprotocol/inspector-server": "0.1.0",
3637
"concurrently": "^9.0.1"
3738
},
3839
"devDependencies": {

server/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "@modelcontextprotocol/inspector-server",
3-
"version": "0.1.0",
4-
"private": true,
3+
"version": "0.1.5",
54
"description": "Server-side application for the Model Context Protocol inspector",
65
"license": "MIT",
76
"author": "Anthropic, PBC (https://anthropic.com)",

server/src/index.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22

3+
import { parseArgs } from "node:util";
34
import cors from "cors";
45
import EventSource from "eventsource";
56

@@ -16,6 +17,14 @@ import mcpProxy from "./mcpProxy.js";
1617
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1718
(global as any).EventSource = EventSource;
1819

20+
const { values } = parseArgs({
21+
args: process.argv.slice(2),
22+
options: {
23+
env: { type: "string", default: "" },
24+
args: { type: "string", default: "" },
25+
},
26+
});
27+
1928
const app = express();
2029
app.use(cors());
2130

@@ -97,11 +106,16 @@ app.post("/message", async (req, res) => {
97106
}
98107
});
99108

100-
app.get("/default-environment", (req, res) => {
109+
app.get("/config", (req, res) => {
101110
try {
102-
res.json(getDefaultEnvironment());
111+
const defaultEnvironment = getDefaultEnvironment();
112+
res.json({
113+
defaultEnvironment,
114+
defaultCommand: values.env,
115+
defaultArgs: values.args,
116+
});
103117
} catch (error) {
104-
console.error("Error in /default-environment route:", error);
118+
console.error("Error in /config route:", error);
105119
res.status(500).json(error);
106120
}
107121
});

0 commit comments

Comments
 (0)