Skip to content

Commit 021e6a4

Browse files
authored
Merge branch 'main' into fix/header
2 parents 3510e1a + 2c527ca commit 021e6a4

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ The MCP inspector is a developer tool for testing and debugging MCP servers.
1010

1111
- Node.js: ^22.7.5
1212

13+
### Quick Start (UI mode)
14+
15+
To get up and running right away with the UI, just execute the following:
16+
17+
```bash
18+
npx @modelcontextprotocol/inspector
19+
```
20+
21+
The server will start up and the UI will be accessible at `http://localhost:6274`.
22+
1323
### From an MCP server repository
1424

1525
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`:

server/src/index.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ app.use((req, res, next) => {
8686
next();
8787
});
8888

89-
const webAppTransports: Map<string, Transport> = new Map<string, Transport>(); // Transports by sessionId
89+
const webAppTransports: Map<string, Transport> = new Map<string, Transport>(); // Web app transports by web app sessionId
90+
const serverTransports: Map<string, Transport> = new Map<string, Transport>(); // Server Transports by web app sessionId
9091

9192
const createTransport = async (req: express.Request): Promise<Transport> => {
9293
const query = req.query;
@@ -154,8 +155,6 @@ const createTransport = async (req: express.Request): Promise<Transport> => {
154155
}
155156
};
156157

157-
let backingServerTransport: Transport | undefined;
158-
159158
app.get("/mcp", async (req, res) => {
160159
const sessionId = req.headers["mcp-session-id"] as string;
161160
console.log(`Received GET message for sessionId ${sessionId}`);
@@ -178,12 +177,12 @@ app.get("/mcp", async (req, res) => {
178177
app.post("/mcp", async (req, res) => {
179178
const sessionId = req.headers["mcp-session-id"] as string | undefined;
180179
console.log(`Received POST message for sessionId ${sessionId}`);
180+
let serverTransport: Transport | undefined;
181181
if (!sessionId) {
182182
try {
183183
console.log("New streamable-http connection");
184184
try {
185-
await backingServerTransport?.close();
186-
backingServerTransport = await createTransport(req);
185+
serverTransport = await createTransport(req);
187186
} catch (error) {
188187
if (error instanceof SseError && error.code === 401) {
189188
console.error(
@@ -197,12 +196,13 @@ app.post("/mcp", async (req, res) => {
197196
throw error;
198197
}
199198

200-
console.log("Connected MCP client to backing server transport");
199+
console.log("Connected MCP client to server transport");
201200

202201
const webAppTransport = new StreamableHTTPServerTransport({
203202
sessionIdGenerator: randomUUID,
204203
onsessioninitialized: (sessionId) => {
205204
webAppTransports.set(sessionId, webAppTransport);
205+
serverTransports.set(sessionId, serverTransport!);
206206
console.log("Created streamable web app transport " + sessionId);
207207
},
208208
});
@@ -211,7 +211,7 @@ app.post("/mcp", async (req, res) => {
211211

212212
mcpProxy({
213213
transportToClient: webAppTransport,
214-
transportToServer: backingServerTransport,
214+
transportToServer: serverTransport,
215215
});
216216

217217
await (webAppTransport as StreamableHTTPServerTransport).handleRequest(
@@ -246,10 +246,9 @@ app.post("/mcp", async (req, res) => {
246246
app.get("/stdio", async (req, res) => {
247247
try {
248248
console.log("New connection");
249-
249+
let serverTransport: Transport | undefined;
250250
try {
251-
await backingServerTransport?.close();
252-
backingServerTransport = await createTransport(req);
251+
serverTransport = await createTransport(req);
253252
} catch (error) {
254253
if (error instanceof SseError && error.code === 401) {
255254
console.error(
@@ -267,26 +266,24 @@ app.get("/stdio", async (req, res) => {
267266

268267
const webAppTransport = new SSEServerTransport("/message", res);
269268
webAppTransports.set(webAppTransport.sessionId, webAppTransport);
270-
271-
console.log("Created web app transport");
269+
serverTransports.set(webAppTransport.sessionId, serverTransport);
270+
console.log("Created client/server transports");
272271

273272
await webAppTransport.start();
274-
(backingServerTransport as StdioClientTransport).stderr!.on(
275-
"data",
276-
(chunk) => {
277-
webAppTransport.send({
278-
jsonrpc: "2.0",
279-
method: "notifications/stderr",
280-
params: {
281-
content: chunk.toString(),
282-
},
283-
});
284-
},
285-
);
273+
274+
(serverTransport as StdioClientTransport).stderr!.on("data", (chunk) => {
275+
webAppTransport.send({
276+
jsonrpc: "2.0",
277+
method: "notifications/stderr",
278+
params: {
279+
content: chunk.toString(),
280+
},
281+
});
282+
});
286283

287284
mcpProxy({
288285
transportToClient: webAppTransport,
289-
transportToServer: backingServerTransport,
286+
transportToServer: serverTransport,
290287
});
291288

292289
console.log("Set up MCP proxy");
@@ -301,10 +298,9 @@ app.get("/sse", async (req, res) => {
301298
console.log(
302299
"New SSE connection. NOTE: The sse transport is deprecated and has been replaced by streamable-http",
303300
);
304-
301+
let serverTransport: Transport | undefined;
305302
try {
306-
await backingServerTransport?.close();
307-
backingServerTransport = await createTransport(req);
303+
serverTransport = await createTransport(req);
308304
} catch (error) {
309305
if (error instanceof SseError && error.code === 401) {
310306
console.error(
@@ -322,13 +318,15 @@ app.get("/sse", async (req, res) => {
322318

323319
const webAppTransport = new SSEServerTransport("/message", res);
324320
webAppTransports.set(webAppTransport.sessionId, webAppTransport);
325-
console.log("Created web app transport");
321+
console.log("Created client transport");
322+
serverTransports.set(webAppTransport.sessionId, serverTransport);
323+
console.log("Created server transport");
326324

327325
await webAppTransport.start();
328326

329327
mcpProxy({
330328
transportToClient: webAppTransport,
331-
transportToServer: backingServerTransport,
329+
transportToServer: serverTransport,
332330
});
333331

334332
console.log("Set up MCP proxy");

0 commit comments

Comments
 (0)