> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # 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. > **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]. ## **Parameters** **`url`** `str` — required MCP server HTTP endpoint URL. --- **`headers`** `dict[str, str] | None` — default: None Optional HTTP headers sent with every request to the MCP server (e.g., `{"Authorization": "Bearer sk-xxx"}`). --- **`resources`** `bool` — default: False Whether to fetch the server's resources into the agent's `global_data`. --- **`resource_vars`** `dict[str, str] | None` — default: None 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() ``` > Add an external MCP server for tool discovery and invocation.