mirror of
https://github.com/okieselbach/AutopilotMonitor.git
synced 2026-10-24 12:42:38 +00:00
Fix session never stored: move transports.set() after handleRequest
The session ID is generated inside StreamableHTTPServerTransport during handleRequest() when it processes the initialize method. The previous code called transports.set() BEFORE handleRequest(), at which point transport.sessionId was still undefined — so the session was never stored in the map. Every subsequent request got "No valid session." https://claude.ai/code/session_01S8iM5fK53kYa54tydpgsNq
This commit is contained in:
@@ -102,11 +102,14 @@ app.all('/mcp', async (req, res) => {
|
||||
const server = createMcpServer();
|
||||
await server.connect(transport);
|
||||
|
||||
await transport.handleRequest(req, res, req.body);
|
||||
|
||||
// Register AFTER handleRequest — the session ID is only assigned during
|
||||
// initialize processing inside handleRequest, not before.
|
||||
if (transport.sessionId) {
|
||||
transports.set(transport.sessionId, transport);
|
||||
console.error(`[mcp] Session ${transport.sessionId} registered`);
|
||||
}
|
||||
|
||||
await transport.handleRequest(req, res, req.body);
|
||||
});
|
||||
|
||||
app.listen(PORT, '0.0.0.0', () => {
|
||||
|
||||
Reference in New Issue
Block a user