Skip to content

Your lightweight open-source personal agent.

feature: Added custom headers for MCP Auth use.

dxtimec5b4331e692c
diff --git a/nanobot/agent/tools/mcp.py b/nanobot/agent/tools/mcp.py
index 1c8eac4f1..4d5c05388 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 ce9634c3b..e404d3cef 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):