SDK Parity: Avoid Parsing Server Response for non-JsonRPCMessage Requests (#1290)
This commit is contained in:
parent
eaf7cf41d5
commit
9c6fd15a88
1 changed files with 163 additions and 11 deletions
|
|
@ -279,17 +279,19 @@ class StreamableHTTPTransport:
|
|||
if is_initialization:
|
||||
self._maybe_extract_session_id_from_response(response)
|
||||
|
||||
content_type = response.headers.get(CONTENT_TYPE, "").lower()
|
||||
|
||||
if content_type.startswith(JSON):
|
||||
await self._handle_json_response(response, ctx.read_stream_writer, is_initialization)
|
||||
elif content_type.startswith(SSE):
|
||||
await self._handle_sse_response(response, ctx, is_initialization)
|
||||
else:
|
||||
await self._handle_unexpected_content_type(
|
||||
content_type,
|
||||
ctx.read_stream_writer,
|
||||
)
|
||||
# Per https://modelcontextprotocol.io/specification/2025-06-18/basic#notifications:
|
||||
# The server MUST NOT send a response to notifications.
|
||||
if isinstance(message.root, JSONRPCRequest):
|
||||
content_type = response.headers.get(CONTENT_TYPE, "").lower()
|
||||
if content_type.startswith(JSON):
|
||||
await self._handle_json_response(response, ctx.read_stream_writer, is_initialization)
|
||||
elif content_type.startswith(SSE):
|
||||
await self._handle_sse_response(response, ctx, is_initialization)
|
||||
else:
|
||||
await self._handle_unexpected_content_type(
|
||||
content_type,
|
||||
ctx.read_stream_writer,
|
||||
)
|
||||
|
||||
async def _handle_json_response(
|
||||
self,
|
||||
|
|
|
|||
Loading…
Reference in a new issue