@mcpjam/inspector 0.2.4 → 0.3.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.
@@ -5,8 +5,8 @@
5
5
  <link rel="icon" type="image/svg+xml" href="/mcp_jam.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>MCPJam Inspector</title>
8
- <script type="module" crossorigin src="/assets/index-CLxTHffA.js"></script>
9
- <link rel="stylesheet" crossorigin href="/assets/index-ebsMqCvj.css">
8
+ <script type="module" crossorigin src="/assets/index-kMl05fui.js"></script>
9
+ <link rel="stylesheet" crossorigin href="/assets/index-De3JSks9.css">
10
10
  </head>
11
11
  <body>
12
12
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpjam/inspector",
3
- "version": "0.2.4",
3
+ "version": "0.3.1",
4
4
  "description": "MCPJam inspector",
5
5
  "license": "Apache-2.0",
6
6
  "author": "MCPJam (https://mcpjam.com)",
@@ -34,6 +34,7 @@
34
34
  "start-client": "cd client && npm run preview",
35
35
  "test": "npm run prettier-check && cd client && npm test",
36
36
  "test-cli": "cd cli && npm run test",
37
+ "run-package": "node cli/build/cli.js",
37
38
  "prettier-fix": "prettier --write .",
38
39
  "prettier-check": "prettier --check .",
39
40
  "prepare": "npm run build",
@@ -58,7 +59,7 @@
58
59
  "@types/node": "^22.15.21",
59
60
  "@types/shell-quote": "^1.7.5",
60
61
  "jest-fixed-jsdom": "^0.0.9",
61
- "prettier": "3.3.3",
62
+ "prettier": "^3.3.3",
62
63
  "rimraf": "^6.0.1",
63
64
  "typescript": "^5.8.3"
64
65
  }
@@ -36,6 +36,7 @@ app.use((req, res, next) => {
36
36
  next();
37
37
  });
38
38
  const webAppTransports = new Map(); // Transports by sessionId
39
+ const backingServerTransports = new Map();
39
40
  const createTransport = async (req) => {
40
41
  const query = req.query;
41
42
  const transportType = query.transportType;
@@ -102,7 +103,6 @@ const createTransport = async (req) => {
102
103
  throw new Error("Invalid transport type specified");
103
104
  }
104
105
  };
105
- let backingServerTransport;
106
106
  app.get("/mcp", async (req, res) => {
107
107
  const sessionId = req.headers["mcp-session-id"];
108
108
  console.log(`📥 Received GET message for sessionId ${sessionId}`);
@@ -127,8 +127,8 @@ app.post("/mcp", async (req, res) => {
127
127
  if (!sessionId) {
128
128
  try {
129
129
  console.log("🔄 New streamable-http connection");
130
+ let backingServerTransport;
130
131
  try {
131
- await backingServerTransport?.close();
132
132
  backingServerTransport = await createTransport(req);
133
133
  }
134
134
  catch (error) {
@@ -139,19 +139,25 @@ app.post("/mcp", async (req, res) => {
139
139
  }
140
140
  throw error;
141
141
  }
142
- console.log("✨ Connected MCP client to backing server transport");
143
142
  const webAppTransport = new StreamableHTTPServerTransport({
144
143
  sessionIdGenerator: randomUUID,
145
- onsessioninitialized: (sessionId) => {
146
- webAppTransports.set(sessionId, webAppTransport);
147
- console.log("✨ Created streamable web app transport " + sessionId);
144
+ onsessioninitialized: (newSessionId) => {
145
+ console.log("✨ Created streamable web app transport " + newSessionId);
146
+ webAppTransports.set(newSessionId, webAppTransport);
147
+ backingServerTransports.set(newSessionId, backingServerTransport);
148
+ console.log(`✨ Connected MCP client to backing server transport for session ${newSessionId}`);
149
+ mcpProxy({
150
+ transportToClient: webAppTransport,
151
+ transportToServer: backingServerTransport,
152
+ });
153
+ webAppTransport.onclose = () => {
154
+ console.log(`🧹 Cleaning up transports for session ${newSessionId}`);
155
+ webAppTransports.delete(newSessionId);
156
+ backingServerTransports.delete(newSessionId);
157
+ };
148
158
  },
149
159
  });
150
160
  await webAppTransport.start();
151
- mcpProxy({
152
- transportToClient: webAppTransport,
153
- transportToServer: backingServerTransport,
154
- });
155
161
  await webAppTransport.handleRequest(req, res, req.body);
156
162
  }
157
163
  catch (error) {
@@ -177,10 +183,35 @@ app.post("/mcp", async (req, res) => {
177
183
  });
178
184
  app.get("/stdio", async (req, res) => {
179
185
  try {
180
- console.log("🔄 New connection");
186
+ console.log("🔄 New stdio/sse connection");
187
+ const webAppTransport = new SSEServerTransport("/message", res);
188
+ const sessionId = webAppTransport.sessionId;
189
+ webAppTransports.set(sessionId, webAppTransport);
181
190
  try {
182
- await backingServerTransport?.close();
183
- backingServerTransport = await createTransport(req);
191
+ const backingServerTransport = await createTransport(req);
192
+ backingServerTransports.set(sessionId, backingServerTransport);
193
+ webAppTransport.onclose = () => {
194
+ console.log(`🧹 Cleaning up transports for session ${sessionId}`);
195
+ webAppTransports.delete(sessionId);
196
+ backingServerTransports.delete(sessionId);
197
+ };
198
+ await webAppTransport.start();
199
+ if (backingServerTransport instanceof StdioClientTransport) {
200
+ backingServerTransport.stderr.on("data", (chunk) => {
201
+ webAppTransport.send({
202
+ jsonrpc: "2.0",
203
+ method: "stderr",
204
+ params: {
205
+ data: chunk.toString(),
206
+ },
207
+ });
208
+ });
209
+ }
210
+ mcpProxy({
211
+ transportToClient: webAppTransport,
212
+ transportToServer: backingServerTransport,
213
+ });
214
+ console.log(`✨ Connected MCP client to backing server transport for session ${sessionId}`);
184
215
  }
185
216
  catch (error) {
186
217
  if (error instanceof SseError && error.code === 401) {
@@ -190,33 +221,32 @@ app.get("/stdio", async (req, res) => {
190
221
  }
191
222
  throw error;
192
223
  }
193
- const webAppTransport = new SSEServerTransport("/message", res);
194
- webAppTransports.set(webAppTransport.sessionId, webAppTransport);
195
- await webAppTransport.start();
196
- backingServerTransport.stderr.on("data", (chunk) => {
197
- webAppTransport.send({
198
- jsonrpc: "2.0",
199
- method: "notifications/stderr",
200
- params: {
201
- content: chunk.toString(),
202
- },
203
- });
204
- });
205
- mcpProxy({
206
- transportToClient: webAppTransport,
207
- transportToServer: backingServerTransport,
208
- });
209
224
  }
210
225
  catch (error) {
211
226
  console.error("❌ Error in /stdio route:", error);
212
- res.status(500).json(error);
227
+ // Can't send a 500 response if headers already sent (which they are for SSE)
213
228
  }
214
229
  });
215
230
  app.get("/sse", async (req, res) => {
216
231
  try {
232
+ console.log("🔄 New sse connection");
233
+ const webAppTransport = new SSEServerTransport("/message", res);
234
+ const sessionId = webAppTransport.sessionId;
235
+ webAppTransports.set(sessionId, webAppTransport);
217
236
  try {
218
- await backingServerTransport?.close();
219
- backingServerTransport = await createTransport(req);
237
+ const backingServerTransport = await createTransport(req);
238
+ backingServerTransports.set(sessionId, backingServerTransport);
239
+ webAppTransport.onclose = () => {
240
+ console.log(`🧹 Cleaning up transports for session ${sessionId}`);
241
+ webAppTransports.delete(sessionId);
242
+ backingServerTransports.delete(sessionId);
243
+ };
244
+ await webAppTransport.start();
245
+ mcpProxy({
246
+ transportToClient: webAppTransport,
247
+ transportToServer: backingServerTransport,
248
+ });
249
+ console.log(`✨ Connected MCP client to backing server transport for session ${sessionId}`);
220
250
  }
221
251
  catch (error) {
222
252
  if (error instanceof SseError && error.code === 401) {
@@ -226,17 +256,10 @@ app.get("/sse", async (req, res) => {
226
256
  }
227
257
  throw error;
228
258
  }
229
- const webAppTransport = new SSEServerTransport("/message", res);
230
- webAppTransports.set(webAppTransport.sessionId, webAppTransport);
231
- await webAppTransport.start();
232
- mcpProxy({
233
- transportToClient: webAppTransport,
234
- transportToServer: backingServerTransport,
235
- });
236
259
  }
237
260
  catch (error) {
238
261
  console.error("❌ Error in /sse route:", error);
239
- res.status(500).json(error);
262
+ // Can't send a 500 response if headers already sent (which they are for SSE)
240
263
  }
241
264
  });
242
265
  app.post("/message", async (req, res) => {