Skip to content

Commit b32096c

Browse files
authored
Update instructions for running the server with HTTP SSE
1 parent 66e1508 commit b32096c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: README.md

+15
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,30 @@ const server = new McpServer({
224224

225225
const app = express();
226226

227+
let transportMap = new Map();
228+
227229
app.get("/sse", async (req, res) => {
228230
const transport = new SSEServerTransport("/messages", res);
231+
const sessionId = transport.sessionId;
232+
transportsMap.set(sessionId, transport);
229233
await server.connect(transport);
230234
});
231235

232236
app.post("/messages", async (req, res) => {
233237
// Note: to support multiple simultaneous connections, these messages will
234238
// need to be routed to a specific matching transport. (This logic isn't
235239
// implemented here, for simplicity.)
240+
241+
const sessionId = req.query.sessionId;
242+
if (!sessionId) {
243+
return res.status(400).json({ error: "SessionId is not found" });
244+
}
245+
246+
const transport = transportMap.get(sessionId);
247+
if (!transport) {
248+
return res.status(400).json({ error: "Transport is not found" });
249+
}
250+
236251
await transport.handlePostMessage(req, res);
237252
});
238253

0 commit comments

Comments
 (0)