Reraise exception and make websocket optional
This commit is contained in:
parent
9d65e5ac03
commit
ea8a2dbd6d
2 changed files with 5 additions and 3 deletions
|
|
@ -30,12 +30,12 @@ dependencies = [
|
||||||
"sse-starlette>=1.6.1",
|
"sse-starlette>=1.6.1",
|
||||||
"pydantic-settings>=2.5.2",
|
"pydantic-settings>=2.5.2",
|
||||||
"uvicorn>=0.23.1",
|
"uvicorn>=0.23.1",
|
||||||
"websockets>=15.0.1",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
rich = ["rich>=13.9.4"]
|
rich = ["rich>=13.9.4"]
|
||||||
cli = ["typer>=0.12.4", "python-dotenv>=1.0.0"]
|
cli = ["typer>=0.12.4", "python-dotenv>=1.0.0"]
|
||||||
|
ws = ["websockets>=15.0.1"]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
mcp = "mcp.cli:app [cli]"
|
mcp = "mcp.cli:app [cli]"
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,9 @@ async def websocket_client(url: str) -> AsyncGenerator[
|
||||||
except ValidationError as exc:
|
except ValidationError as exc:
|
||||||
# If JSON parse or model validation fails, send the exception
|
# If JSON parse or model validation fails, send the exception
|
||||||
await read_stream_writer.send(exc)
|
await read_stream_writer.send(exc)
|
||||||
except (anyio.ClosedResourceError, Exception):
|
except (anyio.ClosedResourceError, Exception) as e:
|
||||||
await ws.close()
|
await ws.close()
|
||||||
|
raise e
|
||||||
|
|
||||||
async def ws_writer():
|
async def ws_writer():
|
||||||
"""
|
"""
|
||||||
|
|
@ -71,8 +72,9 @@ async def websocket_client(url: str) -> AsyncGenerator[
|
||||||
by_alias=True, mode="json", exclude_none=True
|
by_alias=True, mode="json", exclude_none=True
|
||||||
)
|
)
|
||||||
await ws.send(json.dumps(msg_dict))
|
await ws.send(json.dumps(msg_dict))
|
||||||
except (anyio.ClosedResourceError, Exception):
|
except (anyio.ClosedResourceError, Exception) as e:
|
||||||
await ws.close()
|
await ws.close()
|
||||||
|
raise e
|
||||||
|
|
||||||
async with anyio.create_task_group() as tg:
|
async with anyio.create_task_group() as tg:
|
||||||
# Start reader and writer tasks
|
# Start reader and writer tasks
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue