Open
Description
Describe the bug
The messages
endpoint returns a 400 because body parsing fails
To Reproduce
Steps to reproduce the behavior:
import express from "express";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
const server = new McpServer({
name: "example-server",
version: "1.0.0"
});
// ... set up server resources, tools, and prompts ...
const app = express();
let transport: SSEServerTransport | undefined = undefined;
app.get("/sse", async (req, res) => {
transport ??= new SSEServerTransport("/messages", res);
await server.connect(transport);
});
app.post("/messages", async (req, res) => {
await transport.handlePostMessage(req, res);
});
app.listen(3001);
Expected behavior
Should be able to connect to server via npx @modelcontextprotocol/inspector
and setting sse endpoint to http://localhost:3001
Additional context
I was able to work around it by passing the body to handlePostMessage
: await transport.handlePostMessage(req, res, req.body);
I'm unsure where the source of the error is from. Is the inspector sending the incorrect data to the messages
endpoint (Cursor also has the same issue) or is the sdk not working correctly?