@mongodb-js/mcp-http-runners 3.0.0-prerelease.1 → 3.0.0-prerelease.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
- import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
2
- import type { ICompositeLogger, IMetrics, DefaultMetricDefinitions, TransportRequestContext, ISessionStore, HttpServerOptions, SessionManagementOptions, SessionServer } from "@mongodb-js/mcp-types";
1
+ import { type McpHttpHandler } from "@modelcontextprotocol/server";
2
+ import type { ICompositeLogger, IMetrics, DefaultMetricDefinitions, TransportRequestContext, HttpServerOptions, BaseServer } from "@mongodb-js/mcp-types";
3
3
  import { ExpressBasedHttpServer } from "./expressBasedHttpServer.js";
4
+ import { type LegacyMcpHandler, type LegacySessionOptions } from "./legacyMcpHttpHandler.js";
4
5
  /**
5
6
  * Options for creating an MCPHttpServer instance.
6
7
  */
@@ -8,19 +9,32 @@ export type MCPHttpServerOptions<TMetrics extends DefaultMetricDefinitions = Def
8
9
  options: {
9
10
  /** HTTP server options */
10
11
  http: HttpServerOptions;
11
- /** Session management options */
12
- session: SessionManagementOptions;
13
12
  };
14
13
  /** Logger for the server */
15
14
  logger: ICompositeLogger;
16
15
  /** Metrics instance */
17
16
  metrics: IMetrics<TMetrics>;
18
- /** Session store for managing transports */
19
- sessionStore: ISessionStore<StreamableHTTPServerTransport>;
17
+ /**
18
+ * Tunables for the 2025-era (legacy) session lifecycle: the `maxSessions`
19
+ * cap, the idle/notification timeouts, and the LRU eviction idle grace. See
20
+ * {@link LegacySessionOptions}.
21
+ */
22
+ sessionOptions?: LegacySessionOptions;
20
23
  };
21
24
  /**
22
- * HTTP server that handles MCP requests over HTTP using the Streamable HTTP transport.
25
+ * HTTP server that serves MCP requests over HTTP.
26
+ *
27
+ * The 2026-07-28 protocol is served **statelessly** through the SDK's
28
+ * `createMcpHandler` (`legacy: 'reject'`): each request builds a fresh
29
+ * request-scoped server and carries client identity per request in the `_meta`
30
+ * envelope. No per-client sessions, no `mcp-session-id` routing on that path.
23
31
  *
32
+ * 2025-era (legacy) requests are delegated to a sessionful
33
+ * {@link LegacyMcpHttpHandler} (see its docs for why): the 2025 protocol needs
34
+ * a live, correlated transport for its `initialize`-declared capabilities and
35
+ * server→client elicitation, which the SDK's `legacy: 'stateless'` mode cannot
36
+ * provide. The modern/legacy split is isolated from this class so each path
37
+ * stays clean.
24
38
  *
25
39
  * @example
26
40
  * ```typescript
@@ -31,56 +45,41 @@ export type MCPHttpServerOptions<TMetrics extends DefaultMetricDefinitions = Def
31
45
  * }
32
46
  * ```
33
47
  */
34
- export declare abstract class MCPHttpServer<TServer extends SessionServer = SessionServer, TMetrics extends DefaultMetricDefinitions = DefaultMetricDefinitions> extends ExpressBasedHttpServer {
35
- private readonly sessionStore;
36
- readonly sessionOptions: SessionManagementOptions;
48
+ export declare abstract class MCPHttpServer<TServer extends BaseServer = BaseServer, TMetrics extends DefaultMetricDefinitions = DefaultMetricDefinitions> extends ExpressBasedHttpServer {
49
+ /** The 2026-07-28 serving entry; modern requests are routed here. */
50
+ private readonly modernHandler;
51
+ /** Sessionful 2025-era serving (initialize/SSE/requests carried per session). */
52
+ private readonly legacyHandler;
37
53
  protected readonly metrics: IMetrics<TMetrics>;
38
- private readonly pendingInitializations;
39
- constructor({ options, logger, metrics, sessionStore }: MCPHttpServerOptions<TMetrics>);
54
+ constructor({ options, logger, metrics, sessionOptions }: MCPHttpServerOptions<TMetrics>);
40
55
  stop(): Promise<void>;
56
+ /**
57
+ * Builds the handler that serves 2025-era (legacy) traffic. Subclasses may
58
+ * override this to plug in an alternative legacy transport/session
59
+ * implementation; the default returns a {@link LegacyMcpHttpHandler} built
60
+ * from {@link MCPHttpServer.createServerForRequest}.
61
+ */
62
+ protected createLegacyHandler({ logger, http, sessionOptions, }: {
63
+ logger: ICompositeLogger;
64
+ http: HttpServerOptions;
65
+ sessionOptions?: LegacySessionOptions;
66
+ }): LegacyMcpHandler;
41
67
  /**
42
68
  * Creates a server instance for a specific request. Override this method
43
69
  * in subclasses to customize per-request server creation.
44
70
  */
45
71
  protected abstract createServerForRequest(request: TransportRequestContext): Promise<TServer>;
46
- private reportSessionError;
47
- private startKeepAliveLoop;
48
- /**
49
- * Ensures the session for the given sessionId is initialized, serializing
50
- * concurrent initialization attempts so only one runs at a time.
51
- *
52
- * If a session already exists in the store, this is a no-op.
53
- * If another request is already initializing this session, this call waits
54
- * for that initialization to complete.
55
- * Otherwise, this call performs the initialization.
56
- *
57
- * After this method resolves, the caller should look up the transport from
58
- * the session store via `sessionStore.getSession()`.
59
- *
60
- * When `isImplicitInitialization` is true, the transport is pre-configured as
61
- * initialized (bypassing the MCP initialize handshake) so that it can handle
62
- * non-initialize requests immediately. When false, the transport is left in
63
- * its default state so it can process the initialize request normally.
64
- */
65
- private ensureSessionInitialized;
66
- /**
67
- * Restores the client state negotiated during the session's original
68
- * initialization onto an implicitly re-initialized server. The server on
69
- * this pod never saw the client's `initialize` request, so without this
70
- * it would treat the client as capability-less — e.g. skipping
71
- * confirmation elicitation for destructive tools. No-op when the session
72
- * store does not persist negotiated client state.
73
- */
74
- private restoreNegotiatedClientState;
72
+ /** Request middleware hook for `/mcp`, called after body parse + header validation, before routing. */
73
+ protected registerMiddlewares(): void;
75
74
  /**
76
- * Arranges for the client state negotiated by a real `initialize`
77
- * exchange to be persisted through the session store, so implicit
78
- * re-initializations of this session can restore it. Wraps the
79
- * `oninitialized` callback installed by `server.connect`, hence must run
80
- * after it.
75
+ * Builds the 2026-07-28 serving entry. One factory backs every modern
76
+ * request: it constructs a fresh request-scoped server, registers it, and
77
+ * hands the underlying {@link McpServer} to `createMcpHandler`.
78
+ * `legacy: 'reject'` means this entry serves ONLY the 2026-07-28 era;
79
+ * 2025-era traffic is routed to the sessionful legacy handler (see
80
+ * {@link LegacyMcpHttpHandler}).
81
81
  */
82
- private captureNegotiatedClientStateOnInitialize;
83
- protected setupMiddlewares(): void;
82
+ protected createModernHandler(): McpHttpHandler;
84
83
  protected setupRoutes(): Promise<void>;
85
84
  private withErrorHandling;
86
85
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mcpHttpServer.d.ts","sourceRoot":"","sources":["../src/mcpHttpServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAGnG,OAAO,KAAK,EACR,gBAAgB,EAEhB,QAAQ,EACR,wBAAwB,EACxB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,aAAa,EAEhB,MAAM,uBAAuB,CAAC;AAgB/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGrE;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,QAAQ,SAAS,wBAAwB,GAAG,wBAAwB,IAAI;IACrG,OAAO,EAAE;QACL,0BAA0B;QAC1B,IAAI,EAAE,iBAAiB,CAAC;QACxB,iCAAiC;QACjC,OAAO,EAAE,wBAAwB,CAAC;KACrC,CAAC;IACF,4BAA4B;IAC5B,MAAM,EAAE,gBAAgB,CAAC;IACzB,uBAAuB;IACvB,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC5B,4CAA4C;IAC5C,YAAY,EAAE,aAAa,CAAC,6BAA6B,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,8BAAsB,aAAa,CAC/B,OAAO,SAAS,aAAa,GAAG,aAAa,EAC7C,QAAQ,SAAS,wBAAwB,GAAG,wBAAwB,CACtE,SAAQ,sBAAsB;IAC5B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA+C;IAC5E,SAAgB,cAAc,EAAE,wBAAwB,CAAC;IACzD,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC/C,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAoC;gBAE/D,EAAE,OAAO,EA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