From 337170af12b306022d644afe911abc3e8ef47daa Mon Sep 17 00:00:00 2001 From: Dreamwxz <82244600+Dreamwxz@users.noreply.github.com> Date: Tue, 5 May 2026 20:03:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B9=E6=B3=95=E7=AD=BE?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mcp_module/connection.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/mcp_module/connection.py b/src/mcp_module/connection.py index 6f1f01b2..02a3823d 100644 --- a/src/mcp_module/connection.py +++ b/src/mcp_module/connection.py @@ -219,16 +219,30 @@ class MCPConnection: ) return read_stream, write_stream - def _build_http_client(self) -> httpx.AsyncClient: - """构建 Streamable HTTP 使用的 `httpx` 客户端。 + def _build_http_client( + self, + headers: dict[str, str] | None = None, + timeout: httpx.Timeout | None = None, + auth: httpx.Auth | None = None, + ) -> httpx.AsyncClient: + """构建 httpx 客户端。 + + Args: + headers: 合并到配置请求头的额外请求头。 + timeout: 覆盖的 httpx 超时配置。 + auth: 附加认证。 Returns: httpx.AsyncClient: 预配置的异步 HTTP 客户端。 """ + del auth + merged_headers = self.config.build_http_headers() + if headers: + merged_headers.update(headers) return httpx.AsyncClient( - headers=self.config.build_http_headers(), - timeout=httpx.Timeout(self.config.http_timeout_seconds), + headers=merged_headers, + timeout=timeout or httpx.Timeout(self.config.http_timeout_seconds), ) async def _create_client_session(self, read_stream: Any, write_stream: Any) -> Any: