Skip to content

Commit 47591fe

Browse files
committed
Reject standalone GET in stateless streamable HTTP mode
1 parent 1eb80c4 commit 47591fe

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

packages/server/src/server/streamableHttp.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,17 @@ export class WebStandardStreamableHTTPServerTransport implements Transport {
402402
* Handles `GET` requests for SSE stream
403403
*/
404404
private async handleGetRequest(req: Request): Promise<Response> {
405+
// Stateless transports cannot safely own a standalone GET SSE stream.
406+
// In stateless mode, each HTTP request must use a fresh transport
407+
// instance, so allowing GET here would create transport-local stream
408+
// state with no durable owner across requests.
409+
if (this.sessionIdGenerator === undefined) {
410+
return this.createJsonErrorResponse(405, -32_000, 'Method not allowed.', {
411+
headers: {
412+
Allow: 'POST'
413+
}
414+
});
415+
}
405416
// The client MUST include an Accept header, listing text/event-stream as a supported content type.
406417
const acceptHeader = req.headers.get('accept');
407418
if (!acceptHeader?.includes('text/event-stream')) {

0 commit comments

Comments
 (0)