feature: Added custom headers for MCP Auth use.

This commit is contained in:
dxtime
2026-02-19 01:21:17 +08:00
parent 1f1f5b2d27
commit c5b4331e69
2 changed files with 16 additions and 3 deletions

View File

@@ -59,9 +59,21 @@ async def connect_mcp_servers(
read, write = await stack.enter_async_context(stdio_client(params)) read, write = await stack.enter_async_context(stdio_client(params))
elif cfg.url: elif cfg.url:
from mcp.client.streamable_http import streamable_http_client from mcp.client.streamable_http import streamable_http_client
read, write, _ = await stack.enter_async_context( import httpx
streamable_http_client(cfg.url) 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: else:
logger.warning(f"MCP server '{name}': no command or url configured, skipping") logger.warning(f"MCP server '{name}': no command or url configured, skipping")
continue continue

View File

@@ -257,6 +257,7 @@ class MCPServerConfig(Base):
args: list[str] = Field(default_factory=list) # Stdio: command arguments args: list[str] = Field(default_factory=list) # Stdio: command arguments
env: dict[str, str] = Field(default_factory=dict) # Stdio: extra env vars env: dict[str, str] = Field(default_factory=dict) # Stdio: extra env vars
url: str = "" # HTTP: streamable HTTP endpoint URL url: str = "" # HTTP: streamable HTTP endpoint URL
headers: dict[str, str] = Field(default_factory=dict) # HTTP: Custom HTTP Headers
class ToolsConfig(Base): class ToolsConfig(Base):