> For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

# add_mcp_server

> Add an external MCP server for tool discovery and invocation.

[enable-mcp-server]: /docs/server-sdks/reference/python/agents/agent-base/enable-mcp-server

[ref-agentbase]: /docs/server-sdks/reference/python/agents/agent-base

[swml-mcp-servers]: /docs/swml/reference/calling/ai/swaig#swaigmcp_servers

Connect the agent to an external [Model Context Protocol](https://modelcontextprotocol.io/) (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.

Each server you add appears in the SWML [`SWAIG.mcp_servers`][swml-mcp-servers] field of the document the agent generates.

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()`][enable-mcp-server].

## **Parameters**

MCP server HTTP endpoint URL.

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

Whether to fetch the server's resources into the agent's `global_data`.

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

## **Returns**

[`AgentBase`][ref-agentbase] -- Returns self for method chaining.

## **Example**

```python {5}
from signalwire import AgentBase

agent = AgentBase(name="assistant", route="/assistant")
agent.set_prompt_text("You are a helpful assistant.")
agent.add_mcp_server(
    url="https://mcp.example.com/sse",
    headers={"Authorization": "Bearer sk-xxx"},
    resources=True,
    resource_vars={"caller_id": "${caller_id_number}"}
)
agent.serve()
```