-
Notifications
You must be signed in to change notification settings - Fork 583
SSE example is broken #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
ObservationsWhen running this example and connecting to it with the Inspector, I get the following in the server console output:
SolutionThere are problems in the example that must be fixed; Typescript will complain about the fact that I see that @TheBestMoshe has done this in his example by moving the declaration outside the handler and using Below is the example from the SDK page, but with that fixed. As far as my tired eyes can see, it is the same as posted above except I don't define 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;
app.get("/sse", async (req, res) => {
transport = new SSEServerTransport("/messages", res);
await server.connect(transport);
});
app.post("/messages", async (req, res) => {
// Note: to support multiple simultaneous connections, these messages will
// need to be routed to a specific matching transport. (This logic isn't
// implemented here, for simplicity.)
await transport.handlePostMessage(req, res);
});
app.listen(3001); |
…red as a const inside the handler for /sse endpoint and referenced in the handler for the /messages endpoint. This fixes modelcontextprotocol#187
Same problem here! But as I add the param here:
It works! |
Are you using the latest version of the Typescript SDK? And also, the above example, taken from the SDK README, was changed recently. Try with this setup. |
@adcentury @TheBestMoshe @Symbolk Here is what I did to test the current example. In a local copy of the servers repo, in the
What my code looks like![]() The server responds just fine![]() |
Describe the bug
The
messages
endpoint returns a 400 because body parsing failsTo Reproduce
Steps to reproduce the behavior:
Expected behavior
Should be able to connect to server via
npx @modelcontextprotocol/inspector
and setting sse endpoint tohttp://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?The text was updated successfully, but these errors were encountered: