Merge pull request #61 from modelcontextprotocol/ashwin/npx

make inspector runnable via npx
This commit is contained in:
ashwin-ant
2024-11-19 13:27:57 -08:00
committed by GitHub
7 changed files with 41 additions and 18 deletions

View File

@@ -6,20 +6,24 @@ import concurrently from "concurrently";
const __dirname = dirname(fileURLToPath(import.meta.url)); const __dirname = dirname(fileURLToPath(import.meta.url));
// Paths to the server and client entry points // Get command line arguments
const serverPath = join(__dirname, "../server/build/index.js"); const [, , command, ...mcpServerArgs] = process.argv;
const clientPath = join(__dirname, "../client/bin/cli.js");
const inspectorServerPath = join(__dirname, "../server/build/index.js");
// Path to the client entry point
const inspectorClientPath = join(__dirname, "../client/bin/cli.js");
console.log("Starting MCP inspector..."); console.log("Starting MCP inspector...");
const { result } = concurrently( const { result } = concurrently(
[ [
{ {
command: `node ${serverPath}`, command: `node ${inspectorServerPath}${command ? ` --env ${command}` : ""}${mcpServerArgs.length ? ` --args "${mcpServerArgs.join(" ")}"` : ""}`,
name: "server", name: "server",
}, },
{ {
command: `node ${clientPath}`, command: `node ${inspectorClientPath}`,
name: "client", name: "client",
}, },
], ],

View File

@@ -1,7 +1,6 @@
{ {
"name": "@modelcontextprotocol/inspector-client", "name": "@modelcontextprotocol/inspector-client",
"version": "0.1.0", "version": "0.1.5",
"private": true,
"description": "Client-side application for the Model Context Protocol inspector", "description": "Client-side application for the Model Context Protocol inspector",
"license": "MIT", "license": "MIT",
"author": "Anthropic, PBC (https://anthropic.com)", "author": "Anthropic, PBC (https://anthropic.com)",

View File

@@ -186,9 +186,13 @@ const App = () => {
}, [args]); }, [args]);
useEffect(() => { useEffect(() => {
fetch("http://localhost:3000/default-environment") fetch("http://localhost:3000/config")
.then((response) => response.json()) .then((response) => response.json())
.then((data) => setEnv(data)) .then((data) => {
setEnv(data.defaultEnvironment);
setCommand(data.defaultCommand);
setArgs(data.defaultArgs);
})
.catch((error) => .catch((error) =>
console.error("Error fetching default environment:", error), console.error("Error fetching default environment:", error),
); );

6
package-lock.json generated
View File

@@ -1,18 +1,20 @@
{ {
"name": "@modelcontextprotocol/inspector", "name": "@modelcontextprotocol/inspector",
"version": "0.1.0", "version": "0.1.4",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@modelcontextprotocol/inspector", "name": "@modelcontextprotocol/inspector",
"version": "0.1.0", "version": "0.1.4",
"license": "MIT", "license": "MIT",
"workspaces": [ "workspaces": [
"client", "client",
"server" "server"
], ],
"dependencies": { "dependencies": {
"@modelcontextprotocol/inspector-client": "0.1.0",
"@modelcontextprotocol/inspector-server": "0.1.0",
"concurrently": "^9.0.1" "concurrently": "^9.0.1"
}, },
"bin": { "bin": {

View File

@@ -1,7 +1,6 @@
{ {
"name": "@modelcontextprotocol/inspector", "name": "@modelcontextprotocol/inspector",
"version": "0.1.0", "version": "0.1.5",
"private": true,
"description": "Model Context Protocol inspector", "description": "Model Context Protocol inspector",
"license": "MIT", "license": "MIT",
"author": "Anthropic, PBC (https://anthropic.com)", "author": "Anthropic, PBC (https://anthropic.com)",
@@ -33,6 +32,8 @@
"prettier-fix": "prettier --write ." "prettier-fix": "prettier --write ."
}, },
"dependencies": { "dependencies": {
"@modelcontextprotocol/inspector-client": "0.1.0",
"@modelcontextprotocol/inspector-server": "0.1.0",
"concurrently": "^9.0.1" "concurrently": "^9.0.1"
}, },
"devDependencies": { "devDependencies": {

View File

@@ -1,7 +1,6 @@
{ {
"name": "@modelcontextprotocol/inspector-server", "name": "@modelcontextprotocol/inspector-server",
"version": "0.1.0", "version": "0.1.5",
"private": true,
"description": "Server-side application for the Model Context Protocol inspector", "description": "Server-side application for the Model Context Protocol inspector",
"license": "MIT", "license": "MIT",
"author": "Anthropic, PBC (https://anthropic.com)", "author": "Anthropic, PBC (https://anthropic.com)",

View File

@@ -1,5 +1,6 @@
#!/usr/bin/env node #!/usr/bin/env node
import { parseArgs } from "node:util";
import cors from "cors"; import cors from "cors";
import EventSource from "eventsource"; import EventSource from "eventsource";
@@ -16,6 +17,14 @@ import mcpProxy from "./mcpProxy.js";
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).EventSource = EventSource; (global as any).EventSource = EventSource;
const { values } = parseArgs({
args: process.argv.slice(2),
options: {
env: { type: "string", default: "" },
args: { type: "string", default: "" },
},
});
const app = express(); const app = express();
app.use(cors()); app.use(cors());
@@ -97,11 +106,16 @@ app.post("/message", async (req, res) => {
} }
}); });
app.get("/default-environment", (req, res) => { app.get("/config", (req, res) => {
try { try {
res.json(getDefaultEnvironment()); const defaultEnvironment = getDefaultEnvironment();
res.json({
defaultEnvironment,
defaultCommand: values.env,
defaultArgs: values.args,
});
} catch (error) { } catch (error) {
console.error("Error in /default-environment route:", error); console.error("Error in /config route:", error);
res.status(500).json(error); res.status(500).json(error);
} }
}); });