AgentsAgentBase

add_mcp_server

View as MarkdownOpen in Claude

Connect the agent to an external Model Context Protocol (MCP) server. Tools are discovered via the MCP protocol at session start and automatically registered as SWAIG functions. Optionally, the server’s resources can be fetched into the agent’s global data.

This method connects your agent to an MCP server as a client. To expose your agent’s own tools as an MCP server, use enable_mcp_server().

Parameters

url
strRequired

MCP server HTTP endpoint URL.

headers
Optional[dict[str, str]]

Optional HTTP headers sent with every request to the MCP server (e.g., {"Authorization": "Bearer sk-xxx"}).

resources
boolDefaults to False

Whether to fetch the server’s resources into the agent’s global_data.

resource_vars
Optional[dict[str, str]]

Variables for URI template substitution when fetching resources. Supports SignalWire call variables such as ${caller_id_number}.

Returns

AgentBase — Returns self for method chaining.

Example

1from signalwire import AgentBase
2
3agent = AgentBase(name="assistant", route="/assistant")
4agent.set_prompt_text("You are a helpful assistant.")
5agent.add_mcp_server(
6 url="https://mcp.example.com/sse",
7 headers={"Authorization": "Bearer sk-xxx"},
8 resources=True,
9 resource_vars={"caller_id": "${caller_id_number}"}
10)
11agent.serve()