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
|
||||
|
||||
### 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
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
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 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) => {
|
||||
const sessionId = req.headers["mcp-session-id"] as string;
|
||||
console.log(`Received GET message for sessionId ${sessionId}`);
|
||||
|
|
@ -178,12 +177,12 @@ app.get("/mcp", async (req, res) => {
|
|||
app.post("/mcp", async (req, res) => {
|
||||
const sessionId = req.headers["mcp-session-id"] as string | undefined;
|
||||
console.log(`Received POST message for sessionId ${sessionId}`);
|
||||
let serverTransport: Transport | undefined;
|
||||
if (!sessionId) {
|
||||
try {
|
||||
console.log("New streamable-http connection");
|
||||
try {
|
||||
await backingServerTransport?.close();
|
||||
backingServerTransport = await createTransport(req);
|
||||
serverTransport = await createTransport(req);
|
||||
} catch (error) {
|
||||
if (error instanceof SseError && error.code === 401) {
|
||||
console.error(
|
||||
|
|
@ -197,12 +196,13 @@ app.post("/mcp", async (req, res) => {
|
|||
throw error;
|
||||
}
|
||||
|
||||
console.log("Connected MCP client to backing server transport");
|
||||
console.log("Connected MCP client to server transport");
|
||||
|
||||
const webAppTransport = new StreamableHTTPServerTransport({
|
||||
sessionIdGenerator: randomUUID,
|
||||
onsessioninitialized: (sessionId) => {
|
||||
webAppTransports.set(sessionId, webAppTransport);
|
||||
serverTransports.set(sessionId, serverTransport!);
|
||||
console.log("Created streamable web app transport " + sessionId);
|
||||
},
|
||||
});
|
||||
|
|
@ -211,7 +211,7 @@ app.post("/mcp", async (req, res) => {
|
|||
|
||||
mcpProxy({
|
||||
transportToClient: webAppTransport,
|
||||
transportToServer: backingServerTransport,
|
||||
transportToServer: serverTransport,
|
||||
});
|
||||
|
||||
await (webAppTransport as StreamableHTTPServerTransport).handleRequest(
|
||||
|
|
@ -246,10 +246,9 @@ app.post("/mcp", async (req, res) => {
|
|||
app.get("/stdio", async (req, res) => {
|
||||
try {
|
||||
console.log("New connection");
|
||||
|
||||
let serverTransport: Transport | undefined;
|
||||
try {
|
||||
await backingServerTransport?.close();
|
||||
backingServerTransport = await createTransport(req);
|
||||
serverTransport = await createTransport(req);
|
||||
} catch (error) {
|
||||
if (error instanceof SseError && error.code === 401) {
|
||||
console.error(
|
||||
|
|
@ -267,26 +266,24 @@ app.get("/stdio", async (req, res) => {
|
|||
|
||||
const webAppTransport = new SSEServerTransport("/message", res);
|
||||
webAppTransports.set(webAppTransport.sessionId, webAppTransport);
|
||||
|
||||
console.log("Created web app transport");
|
||||
serverTransports.set(webAppTransport.sessionId, serverTransport);
|
||||
console.log("Created client/server transports");
|
||||
|
||||
await webAppTransport.start();
|
||||
(backingServerTransport as StdioClientTransport).stderr!.on(
|
||||
"data",
|
||||
(chunk) => {
|
||||
webAppTransport.send({
|
||||
jsonrpc: "2.0",
|
||||
method: "notifications/stderr",
|
||||
params: {
|
||||
content: chunk.toString(),
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
(serverTransport as StdioClientTransport).stderr!.on("data", (chunk) => {
|
||||
webAppTransport.send({
|
||||
jsonrpc: "2.0",
|
||||
method: "notifications/stderr",
|
||||
params: {
|
||||
content: chunk.toString(),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
mcpProxy({
|
||||
transportToClient: webAppTransport,
|
||||
transportToServer: backingServerTransport,
|
||||
transportToServer: serverTransport,
|
||||
});
|
||||
|
||||
console.log("Set up MCP proxy");
|
||||
|
|
@ -301,10 +298,9 @@ app.get("/sse", async (req, res) => {
|
|||
console.log(
|
||||
"New SSE connection. NOTE: The sse transport is deprecated and has been replaced by streamable-http",
|
||||
);
|
||||
|
||||
let serverTransport: Transport | undefined;
|
||||
try {
|
||||
await backingServerTransport?.close();
|
||||
backingServerTransport = await createTransport(req);
|
||||
serverTransport = await createTransport(req);
|
||||
} catch (error) {
|
||||
if (error instanceof SseError && error.code === 401) {
|
||||
console.error(
|
||||
|
|
@ -322,13 +318,15 @@ app.get("/sse", async (req, res) => {
|
|||
|
||||
const webAppTransport = new SSEServerTransport("/message", res);
|
||||
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();
|
||||
|
||||
mcpProxy({
|
||||
transportToClient: webAppTransport,
|
||||
transportToServer: backingServerTransport,
|
||||
transportToServer: serverTransport,
|
||||
});
|
||||
|
||||
console.log("Set up MCP proxy");
|
||||
|
|
|
|||
Loading…
Reference in a new issue