Skip to content

Commit ea8a2db

Browse files
committed
Reraise exception and make websocket optional
1 parent 9d65e5a commit ea8a2db

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ dependencies = [
3030
"sse-starlette>=1.6.1",
3131
"pydantic-settings>=2.5.2",
3232
"uvicorn>=0.23.1",
33-
"websockets>=15.0.1",
3433
]
3534

3635
[project.optional-dependencies]
3736
rich = ["rich>=13.9.4"]
3837
cli = ["typer>=0.12.4", "python-dotenv>=1.0.0"]
38+
ws = ["websockets>=15.0.1"]
3939

4040
[project.scripts]
4141
mcp = "mcp.cli:app [cli]"

src/mcp/client/websocket.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ async def ws_reader():
5656
except ValidationError as exc:
5757
# If JSON parse or model validation fails, send the exception
5858
await read_stream_writer.send(exc)
59-
except (anyio.ClosedResourceError, Exception):
59+
except (anyio.ClosedResourceError, Exception) as e:
6060
await ws.close()
61+
raise e
6162

6263
async def ws_writer():
6364
"""
@@ -71,8 +72,9 @@ async def ws_writer():
7172
by_alias=True, mode="json", exclude_none=True
7273
)
7374
await ws.send(json.dumps(msg_dict))
74-
except (anyio.ClosedResourceError, Exception):
75+
except (anyio.ClosedResourceError, Exception) as e:
7576
await ws.close()
77+
raise e
7678

7779
async with anyio.create_task_group() as tg:
7880
# Start reader and writer tasks

0 commit comments

Comments
 (0)