mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-04-03 16:13:08 +00:00
Fix SSE clients entering rapid reconnection loops because POST /mcp never routed messages to SSEServerTransport.handlePostMessage() (#617). Root cause: SSE sessions were stored in a separate `this.session` property invisible to the StreamableHTTP POST handler. The POST handler only checked `this.transports` (StreamableHTTP map), so SSE messages were never delivered, causing immediate reconnection and rate limiter exhaustion. Changes: - Add GET /sse + POST /messages endpoints following the official MCP SDK backward-compatible server pattern (separate endpoints per transport) - Store SSE transports in the shared this.transports map with instanceof guards for type discrimination - Remove legacy this.session singleton, resetSessionSSE(), and isExpired() - Extract duplicated auth logic into authenticateRequest() method - Add Bearer token auth and rate limiting to SSE endpoints - Add skipSuccessfulRequests to authLimiter to prevent 429 storms - Mark SSE transport as deprecated (removed in MCP SDK v2.x) The handleRequest() codepath used by the downstream SaaS backend (N8NMCPEngine.processRequest()) is unchanged. Session persistence (exportSessionState/restoreSessionState) is unchanged. Closes #617 Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
57 lines
1.9 KiB
JavaScript
57 lines
1.9 KiB
JavaScript
#!/usr/bin/env node
|
|
import express from 'express';
|
|
import { InstanceContext } from './types/instance-context';
|
|
import { SessionState } from './types/session-state';
|
|
import { GenerateWorkflowHandler } from './types/generate-workflow';
|
|
export interface SingleSessionHTTPServerOptions {
|
|
generateWorkflowHandler?: GenerateWorkflowHandler;
|
|
}
|
|
export declare class SingleSessionHTTPServer {
|
|
private transports;
|
|
private servers;
|
|
private sessionMetadata;
|
|
private sessionContexts;
|
|
private contextSwitchLocks;
|
|
private consoleManager;
|
|
private expressServer;
|
|
private sessionTimeout;
|
|
private authToken;
|
|
private cleanupTimer;
|
|
private generateWorkflowHandler?;
|
|
constructor(options?: SingleSessionHTTPServerOptions);
|
|
private startSessionCleanup;
|
|
private cleanupExpiredSessions;
|
|
private removeSession;
|
|
private getActiveSessionCount;
|
|
private canCreateSession;
|
|
private isValidSessionId;
|
|
private isJsonRpcNotification;
|
|
private sanitizeErrorForClient;
|
|
private updateSessionAccess;
|
|
private authenticateRequest;
|
|
private switchSessionContext;
|
|
private performContextSwitch;
|
|
private getSessionMetrics;
|
|
private loadAuthToken;
|
|
private validateEnvironment;
|
|
handleRequest(req: express.Request, res: express.Response, instanceContext?: InstanceContext): Promise<void>;
|
|
private createSSESession;
|
|
private isSessionExpired;
|
|
start(): Promise<void>;
|
|
shutdown(): Promise<void>;
|
|
getSessionInfo(): {
|
|
active: boolean;
|
|
sessionId?: string;
|
|
age?: number;
|
|
sessions?: {
|
|
total: number;
|
|
active: number;
|
|
expired: number;
|
|
max: number;
|
|
sessionIds: string[];
|
|
};
|
|
};
|
|
exportSessionState(): SessionState[];
|
|
restoreSessionState(sessions: SessionState[]): number;
|
|
}
|
|
//# sourceMappingURL=http-server-single-session.d.ts.map
|