Skip to content

Commit 9194e0c

Browse files
committed
Inline the SSE response headers
1 parent e213d78 commit 9194e0c

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎src/mcp/server/_streamable_http_modern.py‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,6 @@ async def _to_jsonrpc_response(
146146
_SSE_PING_INTERVAL: float = 15.0
147147
"""Seconds between SSE comment-line keepalives once `text/event-stream` has committed."""
148148

149-
_SSE_HEADERS: Final[list[tuple[bytes, bytes]]] = [
150-
(b"content-type", b"text/event-stream"),
151-
(b"cache-control", b"no-cache, no-transform"),
152-
(b"connection", b"keep-alive"),
153-
(b"x-accel-buffering", b"no"),
154-
]
155-
156149

157150
def _sse_event(msg: JSONRPCResponse | JSONRPCError | JSONRPCNotification) -> bytes:
158151
"""Serialise a JSON-RPC message as one SSE `event: message` frame.
@@ -512,7 +505,18 @@ async def watch_disconnect(cancel_scope: anyio.CancelScope) -> None:
512505
# First notification arrived, or the deferral window elapsed: commit
513506
# `text/event-stream` and start pinging so a proxy idle-read timeout
514507
# cannot close the stream (which on this path cancels the handler).
515-
await send({"type": "http.response.start", "status": _OK_STATUS, "headers": list(_SSE_HEADERS)})
508+
await send(
509+
{
510+
"type": "http.response.start",
511+
"status": _OK_STATUS,
512+
"headers": [
513+
(b"content-type", b"text/event-stream"),
514+
(b"cache-control", b"no-cache, no-transform"),
515+
(b"connection", b"keep-alive"),
516+
(b"x-accel-buffering", b"no"),
517+
],
518+
}
519+
)
516520
while not done:
517521
await send({"type": "http.response.body", "body": event or b": ping\r\n\r\n", "more_body": True})
518522
event = None

0 commit comments

Comments
 (0)