Merge branch 'main' into fix/header
This commit is contained in:
commit
021e6a423b
2 changed files with 38 additions and 30 deletions
10
README.md
10
README.md
|
|
@ -10,6 +10,16 @@ The MCP inspector is a developer tool for testing and debugging MCP servers.
|
||||||
|
|
||||||
- Node.js: ^22.7.5
|
- Node.js: ^22.7.5
|
||||||
|
|
||||||
|
### Quick Start (UI mode)
|
||||||
|
|
||||||
|
To get up and running right away with the UI, just execute the following:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npx @modelcontextprotocol/inspector
|
||||||
|
```
|
||||||
|
|
||||||
|
The server will start up and the UI will be accessible at `http://localhost:6274`.
|
||||||
|
|
||||||
### From an MCP server repository
|
### From an MCP server repository
|
||||||
|
|
||||||
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`:
|
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`:
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,8 @@ app.use((req, res, next) => {
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
const webAppTransports: Map<string, Transport> = new Map<string, Transport>(); // Transports by sessionId
|
const webAppTransports: Map<string, Transport> = new Map<string, Transport>(); // Web app transports by web app sessionId
|
||||||
|
const serverTransports: Map<string, Transport> = new Map<string, Transport>(); // Server Transports by web app sessionId
|
||||||
|
|
||||||
const createTransport = async (req: express.Request): Promise<Transport> => {
|
const createTransport = async (req: express.Request): Promise<Transport> => {
|
||||||
const query = req.query;
|
const query = req.query;
|
||||||
|
|
@ -154,8 +155,6 @@ const createTransport = async (req: express.Request): Promise<Transport> => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let backingServerTransport: Transport | undefined;
|
|
||||||
|
|
||||||
app.get("/mcp", async (req, res) => {
|
app.get("/mcp", async (req, res) => {
|
||||||
const sessionId = req.headers["mcp-session-id"] as string;
|
const sessionId = req.headers["mcp-session-id"] as string;
|
||||||
console.log(`Received GET message for sessionId ${sessionId}`);
|
console.log(`Received GET message for sessionId ${sessionId}`);
|
||||||
|
|
@ -178,12 +177,12 @@ app.get("/mcp", async (req, res) => {
|
||||||
app.post("/mcp", async (req, res) => {
|
app.post("/mcp", async (req, res) => {
|
||||||
const sessionId = req.headers["mcp-session-id"] as string | undefined;
|
const sessionId = req.headers["mcp-session-id"] as string | undefined;
|
||||||
console.log(`Received POST message for sessionId ${sessionId}`);
|
console.log(`Received POST message for sessionId ${sessionId}`);
|
||||||
|
let serverTransport: Transport | undefined;
|
||||||
if (!sessionId) {
|
if (!sessionId) {
|
||||||
try {
|
try {
|
||||||
console.log("New streamable-http connection");
|
console.log("New streamable-http connection");
|
||||||
try {
|
try {
|
||||||
await backingServerTransport?.close();
|
serverTransport = await createTransport(req);
|
||||||
backingServerTransport = await createTransport(req);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof SseError && error.code === 401) {
|
if (error instanceof SseError && error.code === 401) {
|
||||||
console.error(
|
console.error(
|
||||||
|
|
@ -197,12 +196,13 @@ app.post("/mcp", async (req, res) => {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Connected MCP client to backing server transport");
|
console.log("Connected MCP client to server transport");
|
||||||
|
|
||||||
const webAppTransport = new StreamableHTTPServerTransport({
|
const webAppTransport = new StreamableHTTPServerTransport({
|
||||||
sessionIdGenerator: randomUUID,
|
sessionIdGenerator: randomUUID,
|
||||||
onsessioninitialized: (sessionId) => {
|
onsessioninitialized: (sessionId) => {
|
||||||
webAppTransports.set(sessionId, webAppTransport);
|
webAppTransports.set(sessionId, webAppTransport);
|
||||||
|
serverTransports.set(sessionId, serverTransport!);
|
||||||
console.log("Created streamable web app transport " + sessionId);
|
console.log("Created streamable web app transport " + sessionId);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -211,7 +211,7 @@ app.post("/mcp", async (req, res) => {
|
||||||
|
|
||||||
mcpProxy({
|
mcpProxy({
|
||||||
transportToClient: webAppTransport,
|
transportToClient: webAppTransport,
|
||||||
transportToServer: backingServerTransport,
|
transportToServer: serverTransport,
|
||||||
});
|
});
|
||||||
|
|
||||||
await (webAppTransport as StreamableHTTPServerTransport).handleRequest(
|
await (webAppTransport as StreamableHTTPServerTransport).handleRequest(
|
||||||
|
|
@ -246,10 +246,9 @@ app.post("/mcp", async (req, res) => {
|
||||||
app.get("/stdio", async (req, res) => {
|
app.get("/stdio", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
console.log("New connection");
|
console.log("New connection");
|
||||||
|
let serverTransport: Transport | undefined;
|
||||||
try {
|
try {
|
||||||
await backingServerTransport?.close();
|
serverTransport = await createTransport(req);
|
||||||
backingServerTransport = await createTransport(req);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof SseError && error.code === 401) {
|
if (error instanceof SseError && error.code === 401) {
|
||||||
console.error(
|
console.error(
|
||||||
|
|
@ -267,26 +266,24 @@ app.get("/stdio", async (req, res) => {
|
||||||
|
|
||||||
const webAppTransport = new SSEServerTransport("/message", res);
|
const webAppTransport = new SSEServerTransport("/message", res);
|
||||||
webAppTransports.set(webAppTransport.sessionId, webAppTransport);
|
webAppTransports.set(webAppTransport.sessionId, webAppTransport);
|
||||||
|
serverTransports.set(webAppTransport.sessionId, serverTransport);
|
||||||
console.log("Created web app transport");
|
console.log("Created client/server transports");
|
||||||
|
|
||||||
await webAppTransport.start();
|
await webAppTransport.start();
|
||||||
(backingServerTransport as StdioClientTransport).stderr!.on(
|
|
||||||
"data",
|
(serverTransport as StdioClientTransport).stderr!.on("data", (chunk) => {
|
||||||
(chunk) => {
|
webAppTransport.send({
|
||||||
webAppTransport.send({
|
jsonrpc: "2.0",
|
||||||
jsonrpc: "2.0",
|
method: "notifications/stderr",
|
||||||
method: "notifications/stderr",
|
params: {
|
||||||
params: {
|
content: chunk.toString(),
|
||||||
content: chunk.toString(),
|
},
|
||||||
},
|
});
|
||||||
});
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
mcpProxy({
|
mcpProxy({
|
||||||
transportToClient: webAppTransport,
|
transportToClient: webAppTransport,
|
||||||
transportToServer: backingServerTransport,
|
transportToServer: serverTransport,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Set up MCP proxy");
|
console.log("Set up MCP proxy");
|
||||||
|
|
@ -301,10 +298,9 @@ app.get("/sse", async (req, res) => {
|
||||||
console.log(
|
console.log(
|
||||||
"New SSE connection. NOTE: The sse transport is deprecated and has been replaced by streamable-http",
|
"New SSE connection. NOTE: The sse transport is deprecated and has been replaced by streamable-http",
|
||||||
);
|
);
|
||||||
|
let serverTransport: Transport | undefined;
|
||||||
try {
|
try {
|
||||||
await backingServerTransport?.close();
|
serverTransport = await createTransport(req);
|
||||||
backingServerTransport = await createTransport(req);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof SseError && error.code === 401) {
|
if (error instanceof SseError && error.code === 401) {
|
||||||
console.error(
|
console.error(
|
||||||
|
|
@ -322,13 +318,15 @@ app.get("/sse", async (req, res) => {
|
||||||
|
|
||||||
const webAppTransport = new SSEServerTransport("/message", res);
|
const webAppTransport = new SSEServerTransport("/message", res);
|
||||||
webAppTransports.set(webAppTransport.sessionId, webAppTransport);
|
webAppTransports.set(webAppTransport.sessionId, webAppTransport);
|
||||||
console.log("Created web app transport");
|
console.log("Created client transport");
|
||||||
|
serverTransports.set(webAppTransport.sessionId, serverTransport);
|
||||||
|
console.log("Created server transport");
|
||||||
|
|
||||||
await webAppTransport.start();
|
await webAppTransport.start();
|
||||||
|
|
||||||
mcpProxy({
|
mcpProxy({
|
||||||
transportToClient: webAppTransport,
|
transportToClient: webAppTransport,
|
||||||
transportToServer: backingServerTransport,
|
transportToServer: serverTransport,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Set up MCP proxy");
|
console.log("Set up MCP proxy");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue