From 7f66cfd21e7c225211aa6902ca967ea7460c65cd Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Wed, 25 Feb 2026 15:22:10 +0800 Subject: [PATCH] Adjust the streamable-http initialization connection waiting logic --- services/api_service/controllers/mcp.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/services/api_service/controllers/mcp.py b/services/api_service/controllers/mcp.py index 710cfc8..e1f6e79 100644 --- a/services/api_service/controllers/mcp.py +++ b/services/api_service/controllers/mcp.py @@ -397,7 +397,7 @@ class McpController: # Ensure transport is connected before delegating (avoid race on first request) try: - await self._wait_transport_ready(transport, timeout_seconds=10.0) + await self._wait_transport_ready(transport, timeout_seconds=2.0) except TimeoutError: logger.error("Transport not ready within timeout; refusing request") response_body = b"Service Unavailable: transport not ready" @@ -469,7 +469,7 @@ class McpController: return asgi - async def _wait_transport_ready(self, transport: StreamableHTTPServerTransport, timeout_seconds: float = 3.0) -> None: + async def _wait_transport_ready(self, transport: StreamableHTTPServerTransport, timeout_seconds: float = 2.0) -> None: """Wait until StreamableHTTP transport is connected and streams are initialized. The underlying transport sets internal streams in connect(); POST/GET handling @@ -484,9 +484,7 @@ class McpController: # Heuristic: writer/reader set once connect() started has_read_writer = getattr(transport, "_read_stream_writer", None) is not None has_write_reader = getattr(transport, "_write_stream_reader", None) is not None - initialized_session_id = getattr(transport, "mcp_session_id", None) - initialized_flag = getattr(transport, "_initialized", False) or getattr(transport, "_has_initialized", False) - if has_read_writer and has_write_reader and (initialized_session_id is not None or initialized_flag): + if has_read_writer and has_write_reader: return if time.time() > deadline: raise TimeoutError("Transport not ready")