nitrostack 1.0.18 → 1.0.19

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.
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Streamable HTTP Transport for MCP
3
+ *
4
+ * Implements the MCP Streamable HTTP transport specification (2025-06-18).
5
+ * https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#streamable-http
6
+ *
7
+ * Features:
8
+ * - Single MCP endpoint supporting both POST and GET
9
+ * - POST for sending messages to server
10
+ * - GET for SSE streams from server
11
+ * - Session management with Mcp-Session-Id header
12
+ * - Resumability support with Last-Event-ID
13
+ * - Multiple concurrent client connections
14
+ * - Protocol version header support
15
+ */
16
+ import { Express } from 'express';
17
+ import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
18
+ import { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
19
+ export interface StreamableHttpTransportOptions {
20
+ /**
21
+ * Port to listen on (default: 3000)
22
+ */
23
+ port?: number;
24
+ /**
25
+ * Host to bind to (default: 'localhost' for security)
26
+ */
27
+ host?: string;
28
+ /**
29
+ * MCP endpoint path (default: '/mcp')
30
+ */
31
+ endpoint?: string;
32
+ /**
33
+ * Enable session management (default: true)
34
+ */
35
+ enableSessions?: boolean;
36
+ /**
37
+ * Session timeout in ms (default: 30 minutes)
38
+ */
39
+ sessionTimeout?: number;
40
+ /**
41
+ * Custom Express app (optional)
42
+ */
43
+ app?: Express;
44
+ /**
45
+ * Enable CORS (default: false for security)
46
+ */
47
+ enableCors?: boolean;
48
+ }
49
+ /**
50
+ * Streamable HTTP Transport
51
+ * Implements MCP Streamable HTTP specification
52
+ */
53
+ export declare class StreamableHttpTransport implements Transport {
54
+ private app;
55
+ private server;
56
+ private sessions;
57
+ private activeStreams;
58
+ private messageHandler?;
59
+ private closeHandler?;
60
+ private errorHandler?;
61
+ private options;
62
+ private sessionCleanupInterval?;
63
+ constructor(options?: StreamableHttpTransportOptions);
64
+ /**
65
+ * Setup Express middleware
66
+ */
67
+ private setupMiddleware;
68
+ /**
69
+ * Setup MCP endpoint routes
70
+ */
71
+ private setupRoutes;
72
+ /**
73
+ * Handle POST requests (client sending messages to server)
74
+ */
75
+ private handlePost;
76
+ /**
77
+ * Handle GET requests (client opening SSE stream)
78
+ */
79
+ private handleGet;
80
+ /**
81
+ * Handle DELETE requests (session termination)
82
+ */
83
+ private handleDelete;
84
+ /**
85
+ * Start SSE stream for a request
86
+ */
87
+ private startSSEStream;
88
+ /**
89
+ * Send message to client(s)
90
+ */
91
+ send(message: JSONRPCMessage): Promise<void>;
92
+ /**
93
+ * Send message to a specific stream
94
+ */
95
+ private sendToStream;
96
+ /**
97
+ * Send response to the stream that made the request
98
+ */
99
+ private sendToRequestStream;
100
+ /**
101
+ * Send message to a sessionless stream
102
+ */
103
+ private sendToStreamSessionless;
104
+ /**
105
+ * Replay messages for resumability
106
+ */
107
+ private replayMessages;
108
+ /**
109
+ * Start the HTTP server
110
+ */
111
+ start(): Promise<void>;
112
+ /**
113
+ * Close the transport
114
+ */
115
+ close(): Promise<void>;
116
+ /**
117
+ * Set message handler
118
+ */
119
+ set onmessage(handler: (message: JSONRPCMessage) => Promise<void>);
120
+ /**
121
+ * Set close handler
122
+ */
123
+ set onclose(handler: () => void);
124
+ /**
125
+ * Set error handler
126
+ */
127
+ set onerror(handler: (error: Error) => void);
128
+ /**
129
+ * Start session cleanup interval
130
+ */
131
+ private startSessionCleanup;
132
+ /**
133
+ * Helper methods
134
+ */
135
+ private generateSessionId;
136
+ private getMessageType;
137
+ private isResponse;
138
+ private isInitializeRequest;
139
+ private isLocalhost;
140
+ /**
141
+ * Get the Express app (for adding custom routes)
142
+ */
143
+ getApp(): Express;
144
+ }
145
+ //# sourceMappingURL=streamable-http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streamable-http.d.ts","sourceRoot":"","sources":["../../../src/core/transports/streamable-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;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