***

title: addMcpServer
slug: /reference/typescript/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/typescript/agents/agent-base/enable-mcp-server

[ref-agentbase]: /docs/server-sdks/reference/typescript/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
  [`enableMcpServer()`][enable-mcp-server].
</Note>

## **Parameters**

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

<ParamField path="opts" type="object" toc={true}>
  Optional configuration.
</ParamField>

<Indent>
  <ParamField path="opts.headers" type={"Record<string, string>"} toc={true}>
    HTTP headers sent with every request to the MCP server (e.g.,
    `{ Authorization: 'Bearer sk-xxx' }`).
  </ParamField>

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

  <ParamField path="opts.resourceVars" type={"Record<string, string>"} toc={true}>
    Variables for URI template substitution when fetching resources. Supports SignalWire
    call variables such as `${caller_id_number}`.
  </ParamField>
</Indent>

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