From 9196c1ddaf936c5b97b4dc3e91f1bc8d16b2f1d5 Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Wed, 20 Nov 2024 18:09:16 -0800 Subject: [PATCH 1/7] update sdk --- client/package.json | 2 +- package-lock.json | 18 +++++++++--------- server/package.json | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client/package.json b/client/package.json index 9720f0b2f..2fe32b86a 100644 --- a/client/package.json +++ b/client/package.json @@ -21,7 +21,7 @@ "preview": "vite preview" }, "dependencies": { - "@modelcontextprotocol/sdk": "0.5.0", + "@modelcontextprotocol/sdk": "0.7.0", "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-label": "^2.1.0", "@radix-ui/react-select": "^2.1.2", diff --git a/package-lock.json b/package-lock.json index aadcba169..83c2c0f6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@modelcontextprotocol/inspector", - "version": "0.1.4", + "version": "0.1.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@modelcontextprotocol/inspector", - "version": "0.1.4", + "version": "0.1.7", "license": "MIT", "workspaces": [ "client", @@ -27,10 +27,10 @@ }, "client": { "name": "@modelcontextprotocol/inspector-client", - "version": "0.1.0", + "version": "0.1.7", "license": "MIT", "dependencies": { - "@modelcontextprotocol/sdk": "0.5.0", + "@modelcontextprotocol/sdk": "0.7.0", "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-label": "^2.1.0", "@radix-ui/react-select": "^2.1.2", @@ -866,9 +866,9 @@ "link": true }, "node_modules/@modelcontextprotocol/sdk": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-0.5.0.tgz", - "integrity": "sha512-RXgulUX6ewvxjAG0kOpLMEdXXWkzWgaoCGaA2CwNW7cQCIphjpJhjpHSiaPdVCnisjRF/0Cm9KWHUuIoeiAblQ==", + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-0.7.0.tgz", + "integrity": "sha512-YlnQf8//eDHClUM607vb/6+GHmCdMnIfOkN2pcpexN4go9sYHm2JfNnqc5ILS7M8enUlwe9dQO9886l3NO3rUw==", "dependencies": { "content-type": "^1.0.5", "raw-body": "^3.0.0", @@ -5867,10 +5867,10 @@ }, "server": { "name": "@modelcontextprotocol/inspector-server", - "version": "0.1.0", + "version": "0.1.7", "license": "MIT", "dependencies": { - "@modelcontextprotocol/sdk": "0.5.0", + "@modelcontextprotocol/sdk": "0.7.0", "cors": "^2.8.5", "eventsource": "^2.0.2", "express": "^4.21.0", diff --git a/server/package.json b/server/package.json index fd43209c4..1061a7942 100644 --- a/server/package.json +++ b/server/package.json @@ -27,7 +27,7 @@ "typescript": "^5.6.2" }, "dependencies": { - "@modelcontextprotocol/sdk": "0.5.0", + "@modelcontextprotocol/sdk": "0.7.0", "cors": "^2.8.5", "eventsource": "^2.0.2", "express": "^4.21.0", From 22bf78720b76b8df33c57be777d180df37b945bb Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Wed, 20 Nov 2024 18:11:37 -0800 Subject: [PATCH 2/7] show server stderr in inspector UI --- client/src/App.tsx | 29 ++++++++++++++++++++++++++--- client/src/components/Sidebar.tsx | 22 ++++++++++++++++++++++ client/src/lib/notificationTypes.ts | 19 +++++++++++++++++++ server/src/index.ts | 19 ++++++++++++++++++- 4 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 client/src/lib/notificationTypes.ts diff --git a/client/src/App.tsx b/client/src/App.tsx index 5df8f4e14..58f965606 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -12,17 +12,26 @@ import { ListPromptsResultSchema, ListResourcesResultSchema, ListResourceTemplatesResultSchema, + Request, ListRootsRequestSchema, ListToolsResultSchema, ProgressNotificationSchema, ReadResourceResultSchema, Resource, ResourceTemplate, + Result, Root, ServerNotification, Tool, } from "@modelcontextprotocol/sdk/types.js"; import { useCallback, useEffect, useRef, useState } from "react"; + +import { + StderrNotificationSchema, + StdErrNotification, + Notification, +} from "./lib/notificationTypes"; + // Add dark mode class based on system preference if (window.matchMedia("(prefers-color-scheme: dark)").matches) { document.documentElement.classList.add("dark"); @@ -87,6 +96,9 @@ const App = () => { >([]); const [mcpClient, setMcpClient] = useState(null); const [notifications, setNotifications] = useState([]); + const [stdErrNotifications, setStdErrNotifications] = useState< + StdErrNotification[] + >([]); const [roots, setRoots] = useState([]); const [env, setEnv] = useState>({}); @@ -383,7 +395,7 @@ const App = () => { const connectMcpServer = async () => { try { - const client = new Client( + const client = new Client( { name: "mcp-inspector", version: "0.0.1", @@ -411,8 +423,6 @@ const App = () => { } const clientTransport = new SSEClientTransport(backendUrl); - await client.connect(clientTransport); - client.setNotificationHandler( ProgressNotificationSchema, (notification) => { @@ -423,6 +433,18 @@ const App = () => { }, ); + client.setNotificationHandler( + StderrNotificationSchema, + (notification) => { + setStdErrNotifications((prevErrorNotifications) => [ + ...prevErrorNotifications, + notification, + ]); + }, + ); + + await client.connect(clientTransport); + client.setRequestHandler(CreateMessageRequestSchema, (request) => { return new Promise((resolve, reject) => { setPendingSampleRequests((prev) => [ @@ -459,6 +481,7 @@ const App = () => { env={env} setEnv={setEnv} onConnect={connectMcpServer} + stdErrNotifications={stdErrNotifications} />
diff --git a/client/src/components/Sidebar.tsx b/client/src/components/Sidebar.tsx index ba73c38c0..7d8a781be 100644 --- a/client/src/components/Sidebar.tsx +++ b/client/src/components/Sidebar.tsx @@ -10,6 +10,7 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; +import { StdErrNotification } from "@/lib/notificationTypes"; interface SidebarProps { connectionStatus: "disconnected" | "connected" | "error"; @@ -24,6 +25,7 @@ interface SidebarProps { env: Record; setEnv: (env: Record) => void; onConnect: () => void; + stdErrNotifications: StdErrNotification[]; } const Sidebar = ({ @@ -39,6 +41,7 @@ const Sidebar = ({ env, setEnv, onConnect, + stdErrNotifications, }: SidebarProps) => { const [showEnvVars, setShowEnvVars] = useState(false); @@ -187,6 +190,25 @@ const Sidebar = ({ : "Disconnected"}
+ {stdErrNotifications.length > 0 && ( + <> +
+

+ Error output from MCP server +

+
+ {stdErrNotifications.map((notification, index) => ( +
+ {notification.params.content} +
+ ))} +
+
+ + )}
diff --git a/client/src/lib/notificationTypes.ts b/client/src/lib/notificationTypes.ts new file mode 100644 index 000000000..3d7f97ac8 --- /dev/null +++ b/client/src/lib/notificationTypes.ts @@ -0,0 +1,19 @@ +import { + ClientNotificationSchema, + NotificationSchema as BaseNotificationSchema, +} from "@modelcontextprotocol/sdk/types.js"; +import { z } from "zod"; + +export const StderrNotificationSchema = BaseNotificationSchema.extend({ + method: z.literal("notifications/stderr"), + params: z.object({ + content: z.string(), + }), +}); + +export const NotificationSchema = ClientNotificationSchema.or( + StderrNotificationSchema, +); + +export type StdErrNotification = z.infer; +export type Notification = z.infer; diff --git a/server/src/index.ts b/server/src/index.ts index 59399e8b1..980687522 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -42,7 +42,12 @@ const createTransport = async (query: express.Request["query"]) => { console.log( `Stdio transport: command=${command}, args=${args}, env=${JSON.stringify(env)}`, ); - const transport = new StdioClientTransport({ command, args, env }); + const transport = new StdioClientTransport({ + command, + args, + env, + stderr: "pipe", + }); await transport.start(); console.log("Spawned stdio transport"); return transport; @@ -75,6 +80,18 @@ app.get("/sse", async (req, res) => { await webAppTransport.start(); + if (backingServerTransport.stderr) { + backingServerTransport.stderr.on("data", (chunk) => { + webAppTransport.send({ + jsonrpc: "2.0", + method: "notifications/stderr", + params: { + content: chunk.toString(), + }, + }); + }); + } + mcpProxy({ transportToClient: webAppTransport, transportToServer: backingServerTransport, From 7e4b276f7f960d6fb23999f235b7fc97fc17b727 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Thu, 21 Nov 2024 10:29:28 +0000 Subject: [PATCH 3/7] Bump versions --- client/package.json | 2 +- package-lock.json | 12 ++++++------ package.json | 6 +++--- server/package.json | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client/package.json b/client/package.json index 2fe32b86a..805797867 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "@modelcontextprotocol/inspector-client", - "version": "0.1.7", + "version": "0.2.0", "description": "Client-side application for the Model Context Protocol inspector", "license": "MIT", "author": "Anthropic, PBC (https://anthropic.com)", diff --git a/package-lock.json b/package-lock.json index 83c2c0f6b..bf2b4e8d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,20 +1,20 @@ { "name": "@modelcontextprotocol/inspector", - "version": "0.1.7", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@modelcontextprotocol/inspector", - "version": "0.1.7", + "version": "0.2.0", "license": "MIT", "workspaces": [ "client", "server" ], "dependencies": { - "@modelcontextprotocol/inspector-client": "0.1.0", - "@modelcontextprotocol/inspector-server": "0.1.0", + "@modelcontextprotocol/inspector-client": "0.2.0", + "@modelcontextprotocol/inspector-server": "0.2.0", "concurrently": "^9.0.1" }, "bin": { @@ -27,7 +27,7 @@ }, "client": { "name": "@modelcontextprotocol/inspector-client", - "version": "0.1.7", + "version": "0.2.0", "license": "MIT", "dependencies": { "@modelcontextprotocol/sdk": "0.7.0", @@ -5867,7 +5867,7 @@ }, "server": { "name": "@modelcontextprotocol/inspector-server", - "version": "0.1.7", + "version": "0.2.0", "license": "MIT", "dependencies": { "@modelcontextprotocol/sdk": "0.7.0", diff --git a/package.json b/package.json index d1eaccb33..f69ae6770 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@modelcontextprotocol/inspector", - "version": "0.1.7", + "version": "0.2.0", "description": "Model Context Protocol inspector", "license": "MIT", "author": "Anthropic, PBC (https://anthropic.com)", @@ -32,8 +32,8 @@ "prettier-fix": "prettier --write ." }, "dependencies": { - "@modelcontextprotocol/inspector-client": "0.1.0", - "@modelcontextprotocol/inspector-server": "0.1.0", + "@modelcontextprotocol/inspector-client": "0.2.0", + "@modelcontextprotocol/inspector-server": "0.2.0", "concurrently": "^9.0.1" }, "devDependencies": { diff --git a/server/package.json b/server/package.json index 1061a7942..3389ca5c7 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "name": "@modelcontextprotocol/inspector-server", - "version": "0.1.7", + "version": "0.2.0", "description": "Server-side application for the Model Context Protocol inspector", "license": "MIT", "author": "Anthropic, PBC (https://anthropic.com)", From dac692e63878d638849370872534d852d983ebb3 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Thu, 21 Nov 2024 10:29:36 +0000 Subject: [PATCH 4/7] Fix type errors in server --- server/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/index.ts b/server/src/index.ts index 980687522..9a200eb00 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -1,8 +1,8 @@ #!/usr/bin/env node -import { parseArgs } from "node:util"; import cors from "cors"; import EventSource from "eventsource"; +import { parseArgs } from "node:util"; import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"; import { @@ -80,8 +80,8 @@ app.get("/sse", async (req, res) => { await webAppTransport.start(); - if (backingServerTransport.stderr) { - backingServerTransport.stderr.on("data", (chunk) => { + if (backingServerTransport instanceof StdioClientTransport) { + backingServerTransport.stderr!.on("data", (chunk) => { webAppTransport.send({ jsonrpc: "2.0", method: "notifications/stderr", @@ -138,4 +138,4 @@ app.get("/config", (req, res) => { }); const PORT = process.env.PORT || 3000; -app.listen(PORT, () => {}); +app.listen(PORT, () => { }); From 360d090ac981eaf7bae3d9e81d9e83cd36666b02 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Thu, 21 Nov 2024 10:31:01 +0000 Subject: [PATCH 5/7] Fix inconsistent capitalization --- client/src/App.tsx | 4 ++-- client/src/lib/notificationTypes.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/src/App.tsx b/client/src/App.tsx index 0054fff85..b2132c3ed 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -29,7 +29,7 @@ import { useCallback, useEffect, useRef, useState } from "react"; import { Notification, StdErrNotification, - StderrNotificationSchema, + StdErrNotificationSchema } from "./lib/notificationTypes"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; @@ -430,7 +430,7 @@ const App = () => { ); client.setNotificationHandler( - StderrNotificationSchema, + StdErrNotificationSchema, (notification) => { setStdErrNotifications((prevErrorNotifications) => [ ...prevErrorNotifications, diff --git a/client/src/lib/notificationTypes.ts b/client/src/lib/notificationTypes.ts index 3d7f97ac8..7aa651828 100644 --- a/client/src/lib/notificationTypes.ts +++ b/client/src/lib/notificationTypes.ts @@ -1,10 +1,10 @@ import { - ClientNotificationSchema, NotificationSchema as BaseNotificationSchema, + ClientNotificationSchema, } from "@modelcontextprotocol/sdk/types.js"; import { z } from "zod"; -export const StderrNotificationSchema = BaseNotificationSchema.extend({ +export const StdErrNotificationSchema = BaseNotificationSchema.extend({ method: z.literal("notifications/stderr"), params: z.object({ content: z.string(), @@ -12,8 +12,8 @@ export const StderrNotificationSchema = BaseNotificationSchema.extend({ }); export const NotificationSchema = ClientNotificationSchema.or( - StderrNotificationSchema, + StdErrNotificationSchema, ); -export type StdErrNotification = z.infer; +export type StdErrNotification = z.infer; export type Notification = z.infer; From 56ec9befd9fcc944633e2451174890fc1cd8b3d8 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Thu, 21 Nov 2024 10:40:10 +0000 Subject: [PATCH 6/7] Add `publish-all` script --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f69ae6770..17e928698 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "start-client": "cd client && npm run preview", "start": "./bin/cli.js", "prepare": "npm run build", - "prettier-fix": "prettier --write ." + "prettier-fix": "prettier --write .", + "publish-all": "npm publish --workspaces --access public && npm publish --access public" }, "dependencies": { "@modelcontextprotocol/inspector-client": "0.2.0", From 2e4eedc6efb0883369803a2a3167149b677e8131 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Thu, 21 Nov 2024 10:41:25 +0000 Subject: [PATCH 7/7] Add publish workflow --- .github/workflows/main.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 383f4c1aa..2665e9d98 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,6 +4,8 @@ on: - main pull_request: + release: + types: [published] jobs: build: @@ -21,3 +23,30 @@ jobs: # - run: npm ci - run: npm install --no-package-lock - run: npm run build + + publish: + runs-on: ubuntu-latest + if: github.event_name == 'release' + environment: release + needs: build + + permissions: + contents: read + id-token: write + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: npm + registry-url: "https://registry.npmjs.org" + + # Working around https://github.com/npm/cli/issues/4828 + # - run: npm ci + - run: npm install --no-package-lock + + # TODO: Add --provenance once the repo is public + - run: npm run publish-all + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}