Skip to content

Commit b70d130

Browse files
Alex Chenclaude
andcommitted
Mark SSE transport as deprecated in favor of Streamable HTTP
Add DeprecationWarning and docstring deprecation notices to: - sse_client() in client/sse.py - SseServerTransport in server/sse.py - MCPServer.run(transport="sse"), run_sse_async(), and sse_app() The HTTP+SSE transport was replaced by Streamable HTTP in protocol revision 2025-03-26. The TypeScript SDK already marks SSEClientTransport as deprecated; this brings the Python SDK into alignment. Closes #2278 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5388bea commit b70d130

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

src/mcp/client/sse.py

Lines changed: 14 additions & 0 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
@@ -39,6 +40,12 @@ async def sse_client(
3940
):
4041
"""Client transport for SSE.
4142
43+
.. deprecated::
44+
sse_client is deprecated. Prefer to use
45+
:func:`streamablehttp_client` where possible instead.
46+
Note that because some servers still use SSE, clients may need
47+
to support both transports during the migration period.
48+
4249
`sse_read_timeout` determines how long (in seconds) the client will wait for a new
4350
event before disconnecting. All other HTTP operations are controlled by `timeout`.
4451
@@ -51,6 +58,13 @@ async def sse_client(
5158
auth: Optional HTTPX authentication handler.
5259
on_session_created: Optional callback invoked with the session ID when received.
5360
"""
61+
warnings.warn(
62+
"sse_client is deprecated. Prefer to use streamablehttp_client where possible "
63+
"instead. Note that because some servers still use SSE, clients may need to "
64+
"support both transports during the migration period.",
65+
DeprecationWarning,
66+
stacklevel=2,
67+
)
5468
read_stream: MemoryObjectReceiveStream[SessionMessage | Exception]
5569
read_stream_writer: MemoryObjectSendStream[SessionMessage | Exception]
5670

src/mcp/server/mcpserver/server.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import inspect
77
import json
88
import re
9+
import warnings
910
from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Sequence
1011
from contextlib import AbstractAsyncContextManager, asynccontextmanager
1112
from typing import Any, Generic, Literal, TypeVar, overload
@@ -286,6 +287,11 @@ def run(
286287
case "stdio":
287288
anyio.run(self.run_stdio_async)
288289
case "sse": # pragma: no cover
290+
warnings.warn(
291+
'transport="sse" is deprecated. Use transport="streamable-http" instead.',
292+
DeprecationWarning,
293+
stacklevel=2,
294+
)
289295
anyio.run(lambda: self.run_sse_async(**kwargs))
290296
case "streamable-http": # pragma: no cover
291297
anyio.run(lambda: self.run_streamable_http_async(**kwargs))
@@ -854,7 +860,17 @@ async def run_sse_async( # pragma: no cover
854860
message_path: str = "/messages/",
855861
transport_security: TransportSecuritySettings | None = None,
856862
) -> None:
857-
"""Run the server using SSE transport."""
863+
"""Run the server using SSE transport.
864+
865+
.. deprecated::
866+
SSE transport is deprecated. Prefer to use
867+
:meth:`run_streamable_http_async` instead.
868+
"""
869+
warnings.warn(
870+
"run_sse_async is deprecated. Use run_streamable_http_async instead.",
871+
DeprecationWarning,
872+
stacklevel=2,
873+
)
858874
import uvicorn
859875

860876
starlette_app = self.sse_app(
@@ -915,7 +931,17 @@ def sse_app(
915931
transport_security: TransportSecuritySettings | None = None,
916932
host: str = "127.0.0.1",
917933
) -> Starlette:
918-
"""Return an instance of the SSE server app."""
934+
"""Return an instance of the SSE server app.
935+
936+
.. deprecated::
937+
SSE transport is deprecated. Prefer to use
938+
:meth:`streamable_http_app` instead.
939+
"""
940+
warnings.warn(
941+
"sse_app is deprecated. Use streamable_http_app instead.",
942+
DeprecationWarning,
943+
stacklevel=2,
944+
)
919945
# Auto-enable DNS rebinding protection for localhost (IPv4 and IPv6)
920946
if transport_security is None and host in ("127.0.0.1", "localhost", "::1"):
921947
transport_security = TransportSecuritySettings(

src/mcp/server/sse.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
"""SSE Server Transport Module
1+
"""SSE Server Transport Module (Deprecated)
2+
3+
.. deprecated::
4+
The HTTP+SSE transport was replaced by Streamable HTTP in the
5+
`2025-03-26 <https://modelcontextprotocol.io/specification/2025-03-26/changelog>`_
6+
protocol revision. Use :class:`mcp.server.streamable_http.StreamableHTTPServerTransport`
7+
instead. SSE is retained for backwards compatibility with older clients.
28
39
This module implements a Server-Sent Events (SSE) transport layer for MCP servers.
410
@@ -37,6 +43,7 @@ async def handle_sse(request):
3743
"""
3844

3945
import logging
46+
import warnings
4047
from contextlib import asynccontextmanager
4148
from typing import Any
4249
from urllib.parse import quote
@@ -61,7 +68,15 @@ async def handle_sse(request):
6168

6269

6370
class SseServerTransport:
64-
"""SSE server transport for MCP. This class provides two ASGI applications,
71+
"""SSE server transport for MCP.
72+
73+
.. deprecated::
74+
``SseServerTransport`` is deprecated. Prefer to use
75+
:class:`~mcp.server.streamable_http.StreamableHTTPServerTransport`
76+
where possible instead. Note that because some clients still use SSE,
77+
servers may need to support both transports during the migration period.
78+
79+
This class provides two ASGI applications,
6580
suitable for use with a framework like Starlette and a server like Hypercorn:
6681
6782
1. connect_sse() is an ASGI application which receives incoming GET requests,
@@ -99,6 +114,15 @@ def __init__(self, endpoint: str, security_settings: TransportSecuritySettings |
99114

100115
super().__init__()
101116

117+
warnings.warn(
118+
"SseServerTransport is deprecated. Prefer to use "
119+
"StreamableHTTPServerTransport where possible instead. Note that because "
120+
"some clients still use SSE, servers may need to support both transports "
121+
"during the migration period.",
122+
DeprecationWarning,
123+
stacklevel=2,
124+
)
125+
102126
# Validate that endpoint is a relative path and not a full URL
103127
if "://" in endpoint or endpoint.startswith("//") or "?" in endpoint or "#" in endpoint:
104128
raise ValueError(

0 commit comments

Comments
 (0)