Skip to content

SSE example is broken #187

Open
Open
@TheBestMoshe

Description

@TheBestMoshe

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions