Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: Add JSON RPC request type guard (#30216)

Noviced8010a7fbce0
diff --git a/api/core/mcp/client/streamable_client.py b/api/core/mcp/client/streamable_client.py
index f81e7cead81..5c3cd0d8f80 100644
--- a/api/core/mcp/client/streamable_client.py
+++ b/api/core/mcp/client/streamable_client.py
@@ -313,17 +313,20 @@ class StreamableHTTPTransport:
if is_initialization:
self._maybe_extract_session_id_from_response(response)
- content_type = cast(str, response.headers.get(CONTENT_TYPE, "").lower())
-
- if content_type.startswith(JSON):
- self._handle_json_response(response, ctx.server_to_client_queue)
- elif content_type.startswith(SSE):
- self._handle_sse_response(response, ctx)
- else:
- self._handle_unexpected_content_type(
- content_type,
- ctx.server_to_client_queue,
- )
+ # 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 = cast(str, response.headers.get(CONTENT_TYPE, "").lower())
+
+ if content_type.startswith(JSON):
+ self._handle_json_response(response, ctx.server_to_client_queue)
+ elif content_type.startswith(SSE):
+ self._handle_sse_response(response, ctx)
+ else:
+ self._handle_unexpected_content_type(
+ content_type,
+ ctx.server_to_client_queue,
+ )
def _handle_json_response(
self,