11/**
22 * Node.js HTTP Streamable HTTP Server Transport
33 *
4- * This is a thin wrapper around `FetchStreamableHTTPServerTransport ` that provides
4+ * This is a thin wrapper around `WebStandardStreamableHTTPServerTransport ` that provides
55 * compatibility with Node.js HTTP server (IncomingMessage/ServerResponse).
66 *
7- * For web-standard environments (Cloudflare Workers, Deno, Bun), use `FetchStreamableHTTPServerTransport ` directly.
7+ * For web-standard environments (Cloudflare Workers, Deno, Bun), use `WebStandardStreamableHTTPServerTransport ` directly.
88 */
99
1010import { IncomingMessage , ServerResponse } from 'node:http' ;
@@ -13,28 +13,28 @@ import { Transport } from '../shared/transport.js';
1313import { AuthInfo } from './auth/types.js' ;
1414import { MessageExtraInfo , JSONRPCMessage , RequestId } from '../types.js' ;
1515import {
16- FetchStreamableHTTPServerTransport ,
17- FetchStreamableHTTPServerTransportOptions ,
16+ WebStandardStreamableHTTPServerTransport ,
17+ WebStandardStreamableHTTPServerTransportOptions ,
1818 EventStore ,
1919 StreamId ,
2020 EventId
21- } from './fetchStreamableHttp .js' ;
21+ } from './webStandardStreamableHttp .js' ;
2222
2323// Re-export types from the core transport for backward compatibility
2424export type { EventStore , StreamId , EventId } ;
2525
2626/**
2727 * Configuration options for StreamableHTTPServerTransport
2828 *
29- * This is an alias for FetchStreamableHTTPServerTransportOptions for backward compatibility.
29+ * This is an alias for WebStandardStreamableHTTPServerTransportOptions for backward compatibility.
3030 */
31- export type StreamableHTTPServerTransportOptions = FetchStreamableHTTPServerTransportOptions ;
31+ export type StreamableHTTPServerTransportOptions = WebStandardStreamableHTTPServerTransportOptions ;
3232
3333/**
3434 * Server transport for Streamable HTTP: this implements the MCP Streamable HTTP transport specification.
3535 * It supports both SSE streaming and direct HTTP responses.
3636 *
37- * This is a wrapper around `FetchStreamableHTTPServerTransport ` that provides Node.js HTTP compatibility.
37+ * This is a wrapper around `WebStandardStreamableHTTPServerTransport ` that provides Node.js HTTP compatibility.
3838 * It uses the `@hono/node-server` library to convert between Node.js HTTP and Web Standard APIs.
3939 *
4040 * Usage example:
@@ -68,20 +68,20 @@ export type StreamableHTTPServerTransportOptions = FetchStreamableHTTPServerTran
6868 * - No session validation is performed
6969 */
7070export class StreamableHTTPServerTransport implements Transport {
71- private _fetchTransport : FetchStreamableHTTPServerTransport ;
71+ private _webStandardTransport : WebStandardStreamableHTTPServerTransport ;
7272 private _requestListener : ReturnType < typeof getRequestListener > ;
7373 // Store auth and parsedBody per request for passing through to handleRequest
7474 private _requestContext : WeakMap < Request , { authInfo ?: AuthInfo ; parsedBody ?: unknown } > = new WeakMap ( ) ;
7575
7676 constructor ( options : StreamableHTTPServerTransportOptions ) {
77- this . _fetchTransport = new FetchStreamableHTTPServerTransport ( options ) ;
77+ this . _webStandardTransport = new WebStandardStreamableHTTPServerTransport ( options ) ;
7878
79- // Create a request listener that wraps the fetch transport
79+ // Create a request listener that wraps the web standard transport
8080 // getRequestListener converts Node.js HTTP to Web Standard and properly handles SSE streaming
8181 this . _requestListener = getRequestListener ( async ( webRequest : Request ) => {
8282 // Get context if available (set during handleRequest)
8383 const context = this . _requestContext . get ( webRequest ) ;
84- return this . _fetchTransport . handleRequest ( webRequest , {
84+ return this . _webStandardTransport . handleRequest ( webRequest , {
8585 authInfo : context ?. authInfo ,
8686 parsedBody : context ?. parsedBody
8787 } ) ;
@@ -92,69 +92,69 @@ export class StreamableHTTPServerTransport implements Transport {
9292 * Gets the session ID for this transport instance.
9393 */
9494 get sessionId ( ) : string | undefined {
95- return this . _fetchTransport . sessionId ;
95+ return this . _webStandardTransport . sessionId ;
9696 }
9797
9898 /**
9999 * Sets callback for when the transport is closed.
100100 */
101101 set onclose ( handler : ( ( ) => void ) | undefined ) {
102- this . _fetchTransport . onclose = handler ;
102+ this . _webStandardTransport . onclose = handler ;
103103 }
104104
105105 get onclose ( ) : ( ( ) => void ) | undefined {
106- return this . _fetchTransport . onclose ;
106+ return this . _webStandardTransport . onclose ;
107107 }
108108
109109 /**
110110 * Sets callback for transport errors.
111111 */
112112 set onerror ( handler : ( ( error : Error ) => void ) | undefined ) {
113- this . _fetchTransport . onerror = handler ;
113+ this . _webStandardTransport . onerror = handler ;
114114 }
115115
116116 get onerror ( ) : ( ( error : Error ) => void ) | undefined {
117- return this . _fetchTransport . onerror ;
117+ return this . _webStandardTransport . onerror ;
118118 }
119119
120120 /**
121121 * Sets callback for incoming messages.
122122 */
123123 set onmessage ( handler : ( ( message : JSONRPCMessage , extra ?: MessageExtraInfo ) => void ) | undefined ) {
124- this . _fetchTransport . onmessage = handler ;
124+ this . _webStandardTransport . onmessage = handler ;
125125 }
126126
127127 get onmessage ( ) : ( ( message : JSONRPCMessage , extra ?: MessageExtraInfo ) => void ) | undefined {
128- return this . _fetchTransport . onmessage ;
128+ return this . _webStandardTransport . onmessage ;
129129 }
130130
131131 /**
132132 * Starts the transport. This is required by the Transport interface but is a no-op
133133 * for the Streamable HTTP transport as connections are managed per-request.
134134 */
135135 async start ( ) : Promise < void > {
136- return this . _fetchTransport . start ( ) ;
136+ return this . _webStandardTransport . start ( ) ;
137137 }
138138
139139 /**
140140 * Closes the transport and all active connections.
141141 */
142142 async close ( ) : Promise < void > {
143- return this . _fetchTransport . close ( ) ;
143+ return this . _webStandardTransport . close ( ) ;
144144 }
145145
146146 /**
147147 * Sends a JSON-RPC message through the transport.
148148 */
149149 async send ( message : JSONRPCMessage , options ?: { relatedRequestId ?: RequestId } ) : Promise < void > {
150- return this . _fetchTransport . send ( message , options ) ;
150+ return this . _webStandardTransport . send ( message , options ) ;
151151 }
152152
153153 /**
154154 * Handles an incoming HTTP request, whether GET or POST.
155155 *
156156 * This method converts Node.js HTTP objects to Web Standard Request/Response
157- * and delegates to the underlying FetchStreamableHTTPServerTransport .
157+ * and delegates to the underlying WebStandardStreamableHTTPServerTransport .
158158 *
159159 * @param req - Node.js IncomingMessage, optionally with auth property from middleware
160160 * @param res - Node.js ServerResponse
@@ -167,7 +167,7 @@ export class StreamableHTTPServerTransport implements Transport {
167167
168168 // Create a custom handler that includes our context
169169 const handler = getRequestListener ( async ( webRequest : Request ) => {
170- return this . _fetchTransport . handleRequest ( webRequest , {
170+ return this . _webStandardTransport . handleRequest ( webRequest , {
171171 authInfo,
172172 parsedBody
173173 } ) ;
@@ -184,14 +184,14 @@ export class StreamableHTTPServerTransport implements Transport {
184184 * client will reconnect after the retry interval specified in the priming event.
185185 */
186186 closeSSEStream ( requestId : RequestId ) : void {
187- this . _fetchTransport . closeSSEStream ( requestId ) ;
187+ this . _webStandardTransport . closeSSEStream ( requestId ) ;
188188 }
189189
190190 /**
191191 * Close the standalone GET SSE stream, triggering client reconnection.
192192 * Use this to implement polling behavior for server-initiated notifications.
193193 */
194194 closeStandaloneSSEStream ( ) : void {
195- this . _fetchTransport . closeStandaloneSSEStream ( ) ;
195+ this . _webStandardTransport . closeStandaloneSSEStream ( ) ;
196196 }
197197}
0 commit comments