Skip to content

Commit

Permalink
Update instructions for running the server with HTTP SSE
Browse files Browse the repository at this point in the history
  • Loading branch information
Constaline authored Mar 3, 2025
1 parent 66e1508 commit b32096c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,30 @@ const server = new McpServer({

const app = express();

let transportMap = new Map();

app.get("/sse", async (req, res) => {
const transport = new SSEServerTransport("/messages", res);
const sessionId = transport.sessionId;
transportsMap.set(sessionId, transport);
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.)

const sessionId = req.query.sessionId;
if (!sessionId) {
return res.status(400).json({ error: "SessionId is not found" });
}

const transport = transportMap.get(sessionId);
if (!transport) {
return res.status(400).json({ error: "Transport is not found" });
}

await transport.handlePostMessage(req, res);
});

Expand Down

0 comments on commit b32096c

Please sign in to comment.