> 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. # addMcpServer > Add an external MCP server for tool discovery and invocation. [enable-mcp-server]: /docs/server-sdks/reference/typescript/agents/agent-base/enable-mcp-server [ref-agentbase]: /docs/server-sdks/reference/typescript/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 > [`enableMcpServer()`][enable-mcp-server]. ## **Parameters** **`url`** `string` — required MCP server HTTP endpoint URL. --- **`opts`** `object` Optional configuration. --- **`opts.headers`** `Record` HTTP headers sent with every request to the MCP server (e.g., `{ Authorization: 'Bearer sk-xxx' }`). --- **`opts.resources`** `boolean` Whether to fetch the server's resources into the agent's `global_data`. --- **`opts.resourceVars`** `Record` Variables for URI template substitution when fetching resources. Supports SignalWire call variables such as `${caller_id_number}`. --- ## **Returns** [`AgentBase`][ref-agentbase] -- Returns `this` for method chaining. ## **Example** ```typescript {5} import { AgentBase } from '@signalwire/sdk'; const agent = new AgentBase({ name: 'assistant', route: '/assistant' }); agent.setPromptText('You are a helpful assistant.'); agent.addMcpServer('https://mcp.example.com/sse', { headers: { Authorization: 'Bearer sk-xxx' }, resources: true, resourceVars: { caller_id: '${caller_id_number}' }, }); await agent.serve(); ``` > Add an external MCP server for tool discovery and invocation.