# Add an MCP server

Add an external [MCP server](/docs/mcp.md) to an agent, and each of the server's tools becomes one the agent can call.

## Before you start

You need an agent. See [Create an agent](/docs/agents/create-agent.md).

## Add a server to an agent

**Code**

1. Add the server to the agent's `mcpServers`. `id` names it and `transport.url` is its address:

```ts title="agents/assistant.ts" {5-10}
import { agent } from "veryfront/agent";

export default agent({
  id: "assistant",
  system: "Answer questions about open source projects. Use the DeepWiki tools.",
  mcpServers: [
    {
      id: "deepwiki",
      transport: { type: "http", url: "https://mcp.deepwiki.com/mcp" },
    },
  ],
});
```

2. Start the project with `npm run dev`.
3. Open **Chat** in Studio.
4. Pick the agent.
5. Ask "Which sections does the DeepWiki wiki for honojs/hono have? List the first three." You should now see the agent call a DeepWiki tool and name the sections.

## Choose its tools

**Code**

A server's `toolPolicy` limits what the agent can call, by the server's own tool names as its `tools/list` gives them. `allow` lists the tools it may use; `deny` lists the ones it may not, and wins over `allow`:

```ts title="agents/assistant.ts"
{
  id: "deepwiki",
  transport: { type: "http", url: "https://mcp.deepwiki.com/mcp" },
  toolPolicy: { allow: ["ask_wiki_question"] },
}
```

A server that needs a key takes `auth: { type: "bearer", token }`, or `auth: { type: "headers", headers }`.

## Next steps

* [Add a tool](/docs/agents/tools.md)
* [Serve over MCP](/docs/mcp/serve.md)
