> ## Documentation Index
> Fetch the complete documentation index at: https://docs.veadk.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP Router

## 功能说明

`mcp_router`（`from veadk.tools.builtin_tools.mcp_router import mcp_router`）通过火山引擎 MCP Router 聚合并转发多个 MCP Server 的工具，适合需要统一接入多个 MCP 服务的场景。它基于可流式传输的 HTTP 连接（`StreamableHTTPConnectionParams`）工作。

## 环境变量与前提

环境变量：

* `TOOL_MCP_ROUTER_URL`：MCP Router 的服务地址
* `TOOL_MCP_ROUTER_API_KEY`：鉴权 API Key，将作为 `Authorization: Bearer <key>` 请求头发送

应在导入 `mcp_router` 前设置以下环境变量，修改配置后重新启动进程：

```bash lines theme={null}
export TOOL_MCP_ROUTER_URL="https://your-mcp-router-endpoint"
export TOOL_MCP_ROUTER_API_KEY="your-router-api-key"
```

## 使用方法

```python lines theme={null}
from veadk import Agent
from veadk.tools.builtin_tools.mcp_router import mcp_router

agent = Agent(tools=[mcp_router])
```

## 验证连接与释放资源

URL 必须是已启用的 Streamable HTTP MCP 地址，API Key 由 Router 服务颁发。API Key 为空时不会发送 `Authorization` 头，不代表服务允许匿名访问。此预构建工具集在导入时读取环境变量。若使用 `config.yaml`，先导入 `Agent` 以加载配置，再导入 `mcp_router`；下面的独立检查使用启动前设置的环境变量。服务地址不会自动切换为 BytePlus 地址

以下示例列出服务当前开放的工具，不调用具体业务操作。列表为空时检查 Router 是否已挂载 MCP Server，以及当前凭证是否有权限

```python lines theme={null}
import asyncio

from veadk.tools.builtin_tools.mcp_router import mcp_router


async def main():
    try:
        tools = await mcp_router.get_tools()
        print([tool.name for tool in tools])
    finally:
        await mcp_router.close()


if __name__ == "__main__":
    asyncio.run(main())
```
