@nitrostack/core 1.0.11 → 1.0.12
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.
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +17 -0
- package/dist/auth/middleware.js.map +1 -1
- package/dist/auth/token-validation.d.ts.map +1 -1
- package/dist/auth/token-validation.js +12 -2
- package/dist/auth/token-validation.js.map +1 -1
- package/dist/core/app-decorator.d.ts.map +1 -1
- package/dist/core/app-decorator.js +0 -3
- package/dist/core/app-decorator.js.map +1 -1
- package/dist/core/oauth-module.d.ts +76 -5
- package/dist/core/oauth-module.d.ts.map +1 -1
- package/dist/core/oauth-module.js +343 -83
- package/dist/core/oauth-module.js.map +1 -1
- package/dist/core/prompt.d.ts +0 -3
- package/dist/core/prompt.d.ts.map +1 -1
- package/dist/core/prompt.js +28 -1
- package/dist/core/prompt.js.map +1 -1
- package/dist/core/server.d.ts +13 -25
- package/dist/core/server.d.ts.map +1 -1
- package/dist/core/server.js +111 -94
- package/dist/core/server.js.map +1 -1
- package/dist/core/transports/streamable-http.d.ts +64 -61
- package/dist/core/transports/streamable-http.d.ts.map +1 -1
- package/dist/core/transports/streamable-http.js +1608 -823
- package/dist/core/transports/streamable-http.js.map +1 -1
- package/package.json +5 -5
|
@@ -14,8 +14,16 @@
|
|
|
14
14
|
* - Protocol version header support
|
|
15
15
|
*/
|
|
16
16
|
import { Express, Request, Response } from 'express';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
17
|
+
import type { Server as McpServer } from '@modelcontextprotocol/sdk/server/index.js';
|
|
18
|
+
import { Tool as McpTool } from '@modelcontextprotocol/sdk/types.js';
|
|
19
|
+
/**
|
|
20
|
+
* Factory that builds a fully-configured MCP server instance.
|
|
21
|
+
* Each Streamable HTTP session gets its own server, since an SDK server can
|
|
22
|
+
* only be connected to a single transport at a time.
|
|
23
|
+
*/
|
|
24
|
+
export type McpServerFactory = () => McpServer;
|
|
25
|
+
/** Handles legacy HTTP+SSE clients that open GET without a Streamable HTTP session id (e.g. Cursor). */
|
|
26
|
+
export type LegacySseHandler = (req: Request, res: Response) => Promise<void>;
|
|
19
27
|
export interface StreamableHttpTransportOptions {
|
|
20
28
|
/**
|
|
21
29
|
* Port to listen on (default: 3000)
|
|
@@ -35,8 +43,15 @@ export interface StreamableHttpTransportOptions {
|
|
|
35
43
|
enableSessions?: boolean;
|
|
36
44
|
/**
|
|
37
45
|
* Session timeout in ms (default: 30 minutes)
|
|
46
|
+
* Idle sessions are torn down after this period of inactivity.
|
|
38
47
|
*/
|
|
39
48
|
sessionTimeout?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Maximum number of concurrent MCP sessions (default: 1000).
|
|
51
|
+
* Once reached, new `initialize` requests are rejected with HTTP 429 to
|
|
52
|
+
* bound memory usage against unauthenticated session-creation floods.
|
|
53
|
+
*/
|
|
54
|
+
maxSessions?: number;
|
|
40
55
|
/**
|
|
41
56
|
* Custom Express app (optional)
|
|
42
57
|
*/
|
|
@@ -47,23 +62,41 @@ export interface StreamableHttpTransportOptions {
|
|
|
47
62
|
enableCors?: boolean;
|
|
48
63
|
}
|
|
49
64
|
/**
|
|
50
|
-
* Streamable HTTP
|
|
51
|
-
*
|
|
65
|
+
* Streamable HTTP host.
|
|
66
|
+
*
|
|
67
|
+
* This class owns the Express application (CORS, origin checks, OAuth discovery
|
|
68
|
+
* routes, health, documentation page, legacy-SSE lifecycle) but delegates the
|
|
69
|
+
* actual MCP protocol handling on `/mcp` to the official
|
|
70
|
+
* `@modelcontextprotocol/sdk` `StreamableHTTPServerTransport`. That transport
|
|
71
|
+
* returns the JSON-RPC result on the POST response (or an SSE stream on the same
|
|
72
|
+
* request), which is what modern MCP clients such as Cursor expect.
|
|
52
73
|
*/
|
|
53
|
-
export declare class StreamableHttpTransport
|
|
74
|
+
export declare class StreamableHttpTransport {
|
|
54
75
|
private app;
|
|
55
76
|
private server;
|
|
56
|
-
private sessions;
|
|
57
|
-
private activeStreams;
|
|
58
|
-
private messageHandler?;
|
|
59
|
-
private closeHandler?;
|
|
60
|
-
private errorHandler?;
|
|
61
77
|
private options;
|
|
62
|
-
private sessionCleanupInterval?;
|
|
63
78
|
private getToolsCallback?;
|
|
64
79
|
private serverConfig?;
|
|
65
80
|
private logoBase64?;
|
|
81
|
+
private _routesRegistered;
|
|
82
|
+
private mcpServerFactory?;
|
|
83
|
+
private legacySseHandler?;
|
|
84
|
+
private mcpSessions;
|
|
85
|
+
private pendingSessions;
|
|
86
|
+
private sessionCleanupInterval?;
|
|
87
|
+
/** Grace period for a created session to finish `initialize` before it is reaped. */
|
|
88
|
+
private static readonly PENDING_SESSION_TIMEOUT_MS;
|
|
66
89
|
constructor(options?: StreamableHttpTransportOptions);
|
|
90
|
+
/**
|
|
91
|
+
* Provide the factory used to build a configured MCP server per session.
|
|
92
|
+
* Must be called before `start()`.
|
|
93
|
+
*/
|
|
94
|
+
setMcpServerFactory(factory: McpServerFactory): void;
|
|
95
|
+
/**
|
|
96
|
+
* Fallback for clients that speak legacy HTTP+SSE on GET /mcp (no mcp-session-id).
|
|
97
|
+
* Streamable HTTP clients always begin with POST initialize instead.
|
|
98
|
+
*/
|
|
99
|
+
setLegacySseHandler(handler: LegacySseHandler): void;
|
|
67
100
|
/**
|
|
68
101
|
* Load logo image as base64 for embedding in documentation page
|
|
69
102
|
*/
|
|
@@ -77,41 +110,30 @@ export declare class StreamableHttpTransport implements Transport {
|
|
|
77
110
|
*/
|
|
78
111
|
private setupRoutes;
|
|
79
112
|
/**
|
|
80
|
-
*
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* Handle GET requests (client opening SSE stream)
|
|
85
|
-
*/
|
|
86
|
-
private handleGet;
|
|
87
|
-
/**
|
|
88
|
-
* Handle DELETE requests (session termination)
|
|
113
|
+
* Delegate an `/mcp` request (POST/GET/DELETE) to the official SDK
|
|
114
|
+
* Streamable HTTP transport. A new session (and its own MCP server instance)
|
|
115
|
+
* is created on an `initialize` POST; subsequent requests are routed by the
|
|
116
|
+
* `mcp-session-id` header.
|
|
89
117
|
*/
|
|
90
|
-
private
|
|
118
|
+
private handleMcpRequest;
|
|
91
119
|
/**
|
|
92
|
-
*
|
|
120
|
+
* Create a new MCP session: a fresh configured MCP server connected to a new
|
|
121
|
+
* official Streamable HTTP transport. The transport registers itself in the
|
|
122
|
+
* session map once it has negotiated a session id, and removes itself on close.
|
|
93
123
|
*/
|
|
94
|
-
private
|
|
124
|
+
private createSession;
|
|
95
125
|
/**
|
|
96
|
-
*
|
|
126
|
+
* Tear down a session, removing it from both the live and pending collections
|
|
127
|
+
* and closing its transport and server. Safe to call from the sweeper, request
|
|
128
|
+
* error paths, and shutdown.
|
|
97
129
|
*/
|
|
98
|
-
|
|
130
|
+
private destroySession;
|
|
99
131
|
/**
|
|
100
|
-
*
|
|
132
|
+
* Periodically tear down sessions that have been idle longer than
|
|
133
|
+
* `sessionTimeout`. Prevents unbounded memory growth from clients that
|
|
134
|
+
* initialize but never disconnect or send DELETE.
|
|
101
135
|
*/
|
|
102
|
-
private
|
|
103
|
-
/**
|
|
104
|
-
* Send response to the stream that made the request
|
|
105
|
-
*/
|
|
106
|
-
private sendToRequestStream;
|
|
107
|
-
/**
|
|
108
|
-
* Send message to a sessionless stream
|
|
109
|
-
*/
|
|
110
|
-
private sendToStreamSessionless;
|
|
111
|
-
/**
|
|
112
|
-
* Replay messages for resumability
|
|
113
|
-
*/
|
|
114
|
-
private replayMessages;
|
|
136
|
+
private startSessionCleanup;
|
|
115
137
|
/**
|
|
116
138
|
* Start the HTTP server
|
|
117
139
|
*/
|
|
@@ -120,33 +142,14 @@ export declare class StreamableHttpTransport implements Transport {
|
|
|
120
142
|
* Register additional HTTP routes
|
|
121
143
|
* Allows modules (like OAuthModule) to add custom endpoints
|
|
122
144
|
*/
|
|
123
|
-
on(path: string, handler: (req:
|
|
145
|
+
on(path: string, handler: (req: any, res: any) => void): void;
|
|
124
146
|
/**
|
|
125
|
-
* Close the transport
|
|
147
|
+
* Close the transport: tear down all live MCP sessions and the HTTP server.
|
|
126
148
|
*/
|
|
127
149
|
close(): Promise<void>;
|
|
128
150
|
/**
|
|
129
|
-
*
|
|
130
|
-
*/
|
|
131
|
-
set onmessage(handler: (message: JSONRPCMessage) => Promise<void>);
|
|
132
|
-
/**
|
|
133
|
-
* Set close handler
|
|
134
|
-
*/
|
|
135
|
-
set onclose(handler: () => void);
|
|
136
|
-
/**
|
|
137
|
-
* Set error handler
|
|
138
|
-
*/
|
|
139
|
-
set onerror(handler: (error: Error) => void);
|
|
140
|
-
/**
|
|
141
|
-
* Start session cleanup interval
|
|
142
|
-
*/
|
|
143
|
-
private startSessionCleanup;
|
|
144
|
-
/**
|
|
145
|
-
* Helper methods
|
|
151
|
+
* Whether a parsed JSON-RPC body is an `initialize` request.
|
|
146
152
|
*/
|
|
147
|
-
private generateSessionId;
|
|
148
|
-
private getMessageType;
|
|
149
|
-
private isResponse;
|
|
150
153
|
private isInitializeRequest;
|
|
151
154
|
private isLocalhost;
|
|
152
155
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamable-http.d.ts","sourceRoot":"","sources":["../../../src/core/transports/streamable-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"streamable-http.d.ts","sourceRoot":"","sources":["../../../src/core/transports/streamable-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG9D,OAAO,KAAK,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACrF,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAMrE;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,S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