Skip to content

Commit 32e453b

Browse files
author
PR-Contributor
committed
deprecate: Mark SSE transport as deprecated
The HTTP+SSE transport was replaced by Streamable HTTP in protocol revision 2025-03-26. This change adds DeprecationWarning and docstring markers to: - sse_client in mcp/client/sse.py - SseServerTransport in mcp/server/sse.py - run_sse_async in MCPServer - sse_app in MCPServer The warnings direct users to use StreamableHTTPTransport instead. Fixes #2278
1 parent 883d893 commit 32e453b

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

src/mcp/client/sse.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import warnings
23
from collections.abc import Callable
34
from contextlib import asynccontextmanager
45
from typing import Any
@@ -37,7 +38,11 @@ async def sse_client(
3738
auth: httpx.Auth | None = None,
3839
on_session_created: Callable[[str], None] | None = None,
3940
):
40-
"""Client transport for SSE.
41+
"""Client transport for SSE (Deprecated).
42+
43+
.. deprecated::
44+
The HTTP+SSE transport is deprecated. Use `streamable_http_client` with
45+
`StreamableHTTPTransport` instead for connecting to MCP servers.
4146
4247
`sse_read_timeout` determines how long (in seconds) the client will wait for a new
4348
event before disconnecting. All other HTTP operations are controlled by `timeout`.
@@ -154,4 +159,10 @@ async def post_writer(endpoint_url: str):
154159
tg.start_soon(post_writer, endpoint_url)
155160

156161
yield read_stream, write_stream
157-
tg.cancel_scope.cancel()
162+
tg.cancel_scope.cancel()
163+
164+
warnings.warn(
165+
"sse_client is deprecated. Use streamable_http_client with StreamableHTTPTransport instead.",
166+
DeprecationWarning,
167+
stacklevel=2,
168+
)

src/mcp/server/mcpserver/server.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,18 @@ async def run_sse_async( # pragma: no cover
854854
message_path: str = "/messages/",
855855
transport_security: TransportSecuritySettings | None = None,
856856
) -> None:
857-
"""Run the server using SSE transport."""
857+
"""Run the server using SSE transport (Deprecated).
858+
859+
.. deprecated::
860+
The HTTP+SSE transport is deprecated. Use `run_streamable_http_async` instead.
861+
"""
862+
import warnings
863+
warnings.warn(
864+
"run_sse_async is deprecated. Use run_streamable_http_async instead.",
865+
DeprecationWarning,
866+
stacklevel=2,
867+
)
868+
858869
import uvicorn
859870

860871
starlette_app = self.sse_app(
@@ -915,7 +926,17 @@ def sse_app(
915926
transport_security: TransportSecuritySettings | None = None,
916927
host: str = "127.0.0.1",
917928
) -> Starlette:
918-
"""Return an instance of the SSE server app."""
929+
"""Return an instance of the SSE server app (Deprecated).
930+
931+
.. deprecated::
932+
The HTTP+SSE transport is deprecated. Use `streamable_http_app` instead.
933+
"""
934+
import warnings
935+
warnings.warn(
936+
"sse_app is deprecated. Use streamable_http_app instead.",
937+
DeprecationWarning,
938+
stacklevel=2,
939+
)
919940
# Auto-enable DNS rebinding protection for localhost (IPv4 and IPv6)
920941
if transport_security is None and host in ("127.0.0.1", "localhost", "::1"):
921942
transport_security = TransportSecuritySettings(

src/mcp/server/sse.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""SSE Server Transport Module
1+
"""SSE Server Transport Module (Deprecated)
2+
3+
.. deprecated::
4+
The HTTP+SSE transport is deprecated. Use `StreamableHTTPTransport` instead.
25
36
This module implements a Server-Sent Events (SSE) transport layer for MCP servers.
47
@@ -37,6 +40,7 @@ async def handle_sse(request):
3740
"""
3841

3942
import logging
43+
import warnings
4044
from contextlib import asynccontextmanager
4145
from typing import Any
4246
from urllib.parse import quote
@@ -61,7 +65,13 @@ async def handle_sse(request):
6165

6266

6367
class SseServerTransport:
64-
"""SSE server transport for MCP. This class provides two ASGI applications,
68+
"""SSE server transport for MCP (Deprecated).
69+
70+
.. deprecated::
71+
The HTTP+SSE transport is deprecated. Use `StreamableHTTPTransport` instead
72+
for new MCP server implementations.
73+
74+
This class provides two ASGI applications,
6575
suitable for use with a framework like Starlette and a server like Hypercorn:
6676
6777
1. connect_sse() is an ASGI application which receives incoming GET requests,
@@ -79,6 +89,9 @@ def __init__(self, endpoint: str, security_settings: TransportSecuritySettings |
7989
"""Creates a new SSE server transport, which will direct the client to POST
8090
messages to the relative path given.
8191
92+
.. deprecated::
93+
The HTTP+SSE transport is deprecated. Use `StreamableHTTPTransport` instead.
94+
8295
Args:
8396
endpoint: A relative path where messages should be posted
8497
(e.g., "/messages/").
@@ -99,6 +112,12 @@ def __init__(self, endpoint: str, security_settings: TransportSecuritySettings |
99112

100113
super().__init__()
101114

115+
warnings.warn(
116+
"SseServerTransport is deprecated. Use StreamableHTTPTransport instead.",
117+
DeprecationWarning,
118+
stacklevel=2,
119+
)
120+
102121
# Validate that endpoint is a relative path and not a full URL
103122
if "://" in endpoint or endpoint.startswith("//") or "?" in endpoint or "#" in endpoint:
104123
raise ValueError(

0 commit comments

Comments
 (0)