Skip to content

Commit ac6cc7d

Browse files
committed
Generic 500 body in outer POST except; make leak-test assertion load-bearing
The outer except now returns a fixed message instead of embedding the exception text in the response body, matching the convention in runner.py and jsonrpc_dispatcher.py (detail goes to logger.exception). Moves the _request_streams/_sse_stream_writers emptiness assertions inside the connect() context so connect()'s own teardown doesn't make them vacuous, and asserts the store's exception message is absent from the 500 body.
1 parent 1f1cb48 commit ac6cc7d

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/mcp/server/streamable_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ async def _handle_post_request(self, scope: Scope, request: Request, receive: Re
641641
except Exception as err:
642642
logger.exception("Error handling POST request")
643643
response = self._create_error_response(
644-
f"Error handling POST request: {err}",
644+
"Error handling POST request",
645645
HTTPStatus.INTERNAL_SERVER_ERROR,
646646
INTERNAL_ERROR,
647647
)

tests/server/test_streamable_http_router.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,12 @@ async def asgi_send(message: Message) -> None:
151151
with anyio.fail_after(5):
152152
forwarded = await read_stream.receive()
153153
assert isinstance(forwarded, Exception)
154+
# handle_request has returned; connect()'s finally (which clears
155+
# _request_streams unconditionally) has not yet run.
156+
assert transport._request_streams == {}
157+
assert transport._sse_stream_writers == {}
154158

155-
assert transport._request_streams == {}
156-
assert transport._sse_stream_writers == {}
157159
assert sent[0]["type"] == "http.response.start"
158160
assert sent[0]["status"] == 500
161+
body = b"".join(m.get("body", b"") for m in sent if m["type"] == "http.response.body")
162+
assert b"backend unavailable" not in body

0 commit comments

Comments
 (0)