Skip to content

Commit 95b711a

Browse files
committed
Remove the unsupported WebSocket transport
WebSocket was never part of the MCP specification. Delete the client and server transports (mcp.client.websocket, mcp.server.websocket), the ws optional-dependency extra, the websockets filterwarnings, and the transport's tests. tests/test_helpers.py goes too: the WebSocket test was the last remaining user of run_uvicorn_in_thread after the other transport tests moved in process. Documented in docs/migration.md; use streamable HTTP instead.
1 parent 19fe9fa commit 95b711a

8 files changed

Lines changed: 9 additions & 331 deletions

File tree

docs/migration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ The `headers`, `timeout`, `sse_read_timeout`, and `auth` parameters have been re
105105

106106
Note: `sse_client` retains its `headers`, `timeout`, `sse_read_timeout`, and `auth` parameters — only the streamable HTTP transport changed.
107107

108+
### WebSocket transport removed
109+
110+
The WebSocket transport has been removed: `mcp.client.websocket.websocket_client`, `mcp.server.websocket.websocket_server`, and the `ws` optional dependency extra (`mcp[ws]`) no longer exist. WebSocket was never part of the MCP specification. Use the streamable HTTP transport instead (`mcp.client.streamable_http.streamable_http_client` on the client, `streamable_http_app()` on the server), which supports bidirectional communication with server-to-client streaming over standard HTTP.
111+
108112
### Removed type aliases and classes
109113

110114
The following deprecated type aliases and classes have been removed from `mcp.types`:

pyproject.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ dependencies = [
4646
[project.optional-dependencies]
4747
rich = ["rich>=13.9.4"]
4848
cli = ["typer>=0.16.0", "python-dotenv>=1.0.0"]
49-
ws = ["websockets>=15.0.1"]
5049

5150
[project.scripts]
5251
mcp = "mcp.cli:app [cli]"
@@ -75,8 +74,8 @@ build-constraint-dependencies = [
7574

7675
[dependency-groups]
7776
dev = [
78-
# We add mcp[cli,ws] so `uv sync` considers the extras.
79-
"mcp[cli,ws]",
77+
# We add mcp[cli] so `uv sync` considers the extras.
78+
"mcp[cli]",
8079
"pyright>=1.1.400",
8180
"pytest>=8.4.0",
8281
"ruff>=0.8.5",
@@ -204,9 +203,6 @@ addopts = """
204203
"""
205204
filterwarnings = [
206205
"error",
207-
# This should be fixed on Uvicorn's side.
208-
"ignore::DeprecationWarning:websockets",
209-
"ignore:websockets.server.WebSocketServerProtocol is deprecated:DeprecationWarning",
210206
# pywin32 internal deprecation warning
211207
"ignore:getargs.*The 'u' format is deprecated:DeprecationWarning",
212208
]

src/mcp/client/websocket.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/mcp/server/websocket.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

tests/client/test_transport_stream_cleanup.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
from mcp.client.sse import sse_client
2323
from mcp.client.streamable_http import streamable_http_client
24-
from mcp.client.websocket import websocket_client
2524

2625

2726
@contextmanager
@@ -104,16 +103,3 @@ async def test_streamable_http_client_closes_all_streams_on_exit() -> None:
104103
with _assert_no_memory_stream_leak():
105104
async with streamable_http_client("http://127.0.0.1:1/mcp"):
106105
pass
107-
108-
109-
@pytest.mark.anyio
110-
async def test_websocket_client_closes_all_streams_on_connection_error(free_tcp_port: int) -> None:
111-
"""websocket_client must close all 4 stream ends when ws_connect fails.
112-
113-
Before the fix, there was no try/finally at all — if ws_connect raised,
114-
all 4 streams were leaked.
115-
"""
116-
with _assert_no_memory_stream_leak():
117-
with pytest.raises(OSError):
118-
async with websocket_client(f"ws://127.0.0.1:{free_tcp_port}/ws"):
119-
pytest.fail("should not reach here") # pragma: no cover

tests/shared/test_ws.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

tests/test_helpers.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)