***

title: add_mcp_server
slug: /reference/python/agents/agent-base/add-mcp-server
description: Add an external MCP server for tool discovery and invocation.
max-toc-depth: 3
---------------------

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

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

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

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.

<Note>
  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].
</Note>

## **Parameters**

<ParamField path="url" type="str" required={true} toc={true}>
  MCP server HTTP endpoint URL.
</ParamField>

<ParamField path="headers" type="Optional[dict[str, str]]" toc={true}>
  Optional HTTP headers sent with every request to the MCP server (e.g.,
  `{"Authorization": "Bearer sk-xxx"}`).
</ParamField>

<ParamField path="resources" type="bool" default="False" toc={true}>
  Whether to fetch the server's resources into the agent's `global_data`.
</ParamField>

<ParamField path="resource_vars" type="Optional[dict[str, str]]" toc={true}>
  Variables for URI template substitution when fetching resources. Supports SignalWire
  call variables such as `${caller_id_number}`.
</ParamField>

## **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()
```