From c5b4331e692c09bb285a5c8e3d811dbfca52b273 Mon Sep 17 00:00:00 2001 From: dxtime Date: Thu, 19 Feb 2026 01:21:17 +0800 Subject: [PATCH 1/3] 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): From f3c7337356de507b6a1e0b10725bc2521f48ec95 Mon Sep 17 00:00:00 2001 From: dxtime Date: Fri, 20 Feb 2026 08:31:52 +0800 Subject: [PATCH 2/3] feat: Added custom headers for MCP Auth use, update README.md --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7fad9ce..e8aac1e 100644 --- a/README.md +++ b/README.md @@ -752,7 +752,14 @@ Add MCP servers to your `config.json`: "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"] } - } + }, + "urlMcpServers": { + "url": "https://xx.xx.xx.xx:xxxx/mcp/", + "headers": { + "Authorization": "Bearer xxxxx", + "X-API-Key": "xxxxxxx" + } + }, } } ``` @@ -762,7 +769,7 @@ Two transport modes are supported: | Mode | Config | Example | |------|--------|---------| | **Stdio** | `command` + `args` | Local process via `npx` / `uvx` | -| **HTTP** | `url` | Remote endpoint (`https://mcp.example.com/sse`) | +| **HTTP** | `url` + `option(headers)`| Remote endpoint (`https://mcp.example.com/sse`) | MCP tools are automatically discovered and registered on startup. The LLM can use them alongside built-in tools — no extra configuration needed. From f5fe74f5789be04028a03ed8c95c9f35feb2fd81 Mon Sep 17 00:00:00 2001 From: Re-bin Date: Fri, 20 Feb 2026 08:49:49 +0000 Subject: [PATCH 3/3] style: move httpx import to top-level and fix README example for MCP headers --- README.md | 17 ++++++++--------- nanobot/agent/tools/mcp.py | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ece47e0..b37f8bd 100644 --- a/README.md +++ b/README.md @@ -753,15 +753,14 @@ Add MCP servers to your `config.json`: "filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"] - } - }, - "urlMcpServers": { - "url": "https://xx.xx.xx.xx:xxxx/mcp/", - "headers": { - "Authorization": "Bearer xxxxx", - "X-API-Key": "xxxxxxx" - } }, + "my-remote-mcp": { + "url": "https://example.com/mcp/", + "headers": { + "Authorization": "Bearer xxxxx" + } + } + } } } ``` @@ -771,7 +770,7 @@ Two transport modes are supported: | Mode | Config | Example | |------|--------|---------| | **Stdio** | `command` + `args` | Local process via `npx` / `uvx` | -| **HTTP** | `url` + `option(headers)`| Remote endpoint (`https://mcp.example.com/sse`) | +| **HTTP** | `url` + `headers` (optional) | Remote endpoint (`https://mcp.example.com/sse`) | MCP tools are automatically discovered and registered on startup. The LLM can use them alongside built-in tools — no extra configuration needed. diff --git a/nanobot/agent/tools/mcp.py b/nanobot/agent/tools/mcp.py index a02f42b..ad352bf 100644 --- a/nanobot/agent/tools/mcp.py +++ b/nanobot/agent/tools/mcp.py @@ -3,6 +3,7 @@ from contextlib import AsyncExitStack from typing import Any +import httpx from loguru import logger from nanobot.agent.tools.base import Tool @@ -59,7 +60,6 @@ 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 - import httpx if cfg.headers: http_client = await stack.enter_async_context( httpx.AsyncClient(