From c5b4331e692c09bb285a5c8e3d811dbfca52b273 Mon Sep 17 00:00:00 2001 From: dxtime Date: Thu, 19 Feb 2026 01:21:17 +0800 Subject: [PATCH] feature: Added custom headers for MCP Auth use. --- nanobot/agent/tools/mcp.py | 18 +++++++++++++++--- nanobot/config/schema.py | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/nanobot/agent/tools/mcp.py b/nanobot/agent/tools/mcp.py index 1c8eac4..4d5c053 100644 --- a/nanobot/agent/tools/mcp.py +++ b/nanobot/agent/tools/mcp.py @@ -59,9 +59,21 @@ async def connect_mcp_servers( read, write = await stack.enter_async_context(stdio_client(params)) elif cfg.url: from mcp.client.streamable_http import streamable_http_client - read, write, _ = await stack.enter_async_context( - streamable_http_client(cfg.url) - ) + import httpx + if cfg.headers: + http_client = await stack.enter_async_context( + httpx.AsyncClient( + headers=cfg.headers, + follow_redirects=True + ) + ) + read, write, _ = await stack.enter_async_context( + streamable_http_client(cfg.url, http_client=http_client) + ) + else: + read, write, _ = await stack.enter_async_context( + streamable_http_client(cfg.url) + ) else: logger.warning(f"MCP server '{name}': no command or url configured, skipping") continue diff --git a/nanobot/config/schema.py b/nanobot/config/schema.py index ce9634c..e404d3c 100644 --- a/nanobot/config/schema.py +++ b/nanobot/config/schema.py @@ -257,6 +257,7 @@ class MCPServerConfig(Base): args: list[str] = Field(default_factory=list) # Stdio: command arguments env: dict[str, str] = Field(default_factory=dict) # Stdio: extra env vars url: str = "" # HTTP: streamable HTTP endpoint URL + headers: dict[str, str] = Field(default_factory=dict) # HTTP: Custom HTTP Headers class ToolsConfig(Base):