fix: store session after handleRequest so sessionId is initialized
transport.sessionId is only populated during handleRequest(), not before. Reading it before that call stored sessions under key `undefined`, causing all subsequent requests to get "Session not found." Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -134,14 +134,14 @@ const httpServer = http.createServer(async (req, res) => {
|
||||
const mcpServer = await createServer(config);
|
||||
await mcpServer.connect(transport);
|
||||
|
||||
await transport.handleRequest(req, res, parsedBody);
|
||||
|
||||
const sid = transport.sessionId!;
|
||||
sessions.set(sid, { transport, createdAt: Date.now() });
|
||||
|
||||
transport.onclose = () => {
|
||||
sessions.delete(sid);
|
||||
};
|
||||
|
||||
await transport.handleRequest(req, res, parsedBody);
|
||||
} else {
|
||||
// Existing session
|
||||
const session = sessions.get(sessionId);
|
||||
|
||||
Reference in New Issue
Block a user