Skip to content

Commit 2f365d8

Browse files
fix: ensures MCP client can handle 4xx error codes
Ensures that any error code response from the MCP server is handled.
1 parent 6d2e6d4 commit 2f365d8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/mcp/client/streamable_http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ async def _handle_post_request(self, ctx: RequestContext) -> None:
266266
logger.debug("Received 202 Accepted")
267267
return
268268

269-
if response.status_code == 404:
269+
# ensures that all HTTP error codes are handled
270+
if response.status_code >= 400 and response.status_code <= 499:
270271
if isinstance(message.root, JSONRPCRequest):
271272
await self._send_session_terminated_error(
272273
ctx.read_stream_writer,

0 commit comments

Comments
 (0)