@@ -84,31 +84,20 @@ export class StreamableHTTPServerTransport implements Transport {
84
84
* Handles an incoming HTTP request, whether GET or POST
85
85
*/
86
86
async handleRequest ( req : IncomingMessage , res : ServerResponse , parsedBody ?: unknown ) : Promise < void > {
87
- if ( req . method === "GET" ) {
88
- await this . handleGetRequest ( req , res ) ;
89
- } else if ( req . method === "POST" ) {
87
+ if ( req . method === "POST" ) {
90
88
await this . handlePostRequest ( req , res , parsedBody ) ;
91
89
} else if ( req . method === "DELETE" ) {
92
90
await this . handleDeleteRequest ( req , res ) ;
93
91
} else {
94
- res . writeHead ( 405 ) . end ( JSON . stringify ( {
95
- jsonrpc : "2.0" ,
96
- error : {
97
- code : - 32000 ,
98
- message : "Method not allowed"
99
- } ,
100
- id : null
101
- } ) ) ;
92
+ await this . handleUnsupportedRequest ( req , res ) ;
102
93
}
103
94
}
104
95
105
96
/**
106
- * Handles GET requests to establish SSE connections
107
- * According to the MCP Streamable HTTP transport spec, the server MUST either return SSE or 405.
108
- * We choose to return 405 Method Not Allowed as we don't support GET SSE connections yet.
97
+ * Handles unsupported requests (GET, PUT, PATCH, etc.)
98
+ * For now we support only POST and DELETE requests. Support for GET for SSE connections will be added later.
109
99
*/
110
- private async handleGetRequest ( req : IncomingMessage , res : ServerResponse ) : Promise < void > {
111
- // Check session validity first for GET requests when session management is enabled
100
+ private async handleUnsupportedRequest ( req : IncomingMessage , res : ServerResponse ) : Promise < void > {
112
101
if ( this . _sessionId !== undefined && ! this . validateSession ( req , res ) ) {
113
102
return ;
114
103
}
@@ -119,7 +108,7 @@ export class StreamableHTTPServerTransport implements Transport {
119
108
jsonrpc : "2.0" ,
120
109
error : {
121
110
code : - 32000 ,
122
- message : "Method not allowed: Server does not offer an SSE stream at this endpoint "
111
+ message : "Method not allowed. "
123
112
} ,
124
113
id : null
125
114
} ) ) ;
@@ -322,6 +311,8 @@ export class StreamableHTTPServerTransport implements Transport {
322
311
323
312
async send ( message : JSONRPCMessage , options ?: { relatedRequestId ?: RequestId } ) : Promise < void > {
324
313
const relatedRequestId = options ?. relatedRequestId ;
314
+ // SSE connections are established per POST request, for now we don't support it through the GET
315
+ // this will be changed when we implement the GET SSE connection
325
316
if ( relatedRequestId === undefined ) {
326
317
throw new Error ( "relatedRequestId is required for Streamable HTTP transport" ) ;
327
318
}
0 commit comments