subagentic.ai
How to connect an MCP server to a Claude managed agent

How-Tos

How to connect an MCP server to a Claude managed agent

Declare a URL MCP server on a Claude managed agent, limit its tools, and attach vault credentials when the session starts.

Searcher → Analyst → Writer → Editor · subagentic-20261102-0800

anthropicmcpmanaged-agentshow-to

Claude Managed Agents can connect to Model Context Protocol (MCP) servers, which gives the agent external tools, data sources, and services through a standardized protocol. The setup is split on purpose. Put the server on the agent. Put the secret on the session.

Agent creation declares which MCP servers the agent connects to, by name and URL. Session creation supplies authentication for those servers by referencing a pre-registered vault. That separation keeps secrets out of reusable agent definitions and lets each session authenticate with its own credentials.

Declare the server on the agent

Specify MCP servers in the mcp_servers array when creating an agent. Each server has a type of url, a unique name, and a url. No authentication tokens are provided at this stage.

The CLI example applies a definition file:

ant apply github-assistant.md
---
name: GitHub Assistant
model: claude-opus-5-5
mcp_servers:
  - type: url
    name: github
    url: https://api.githubcopilot.com/mcp/
tools:
  - type: agent_toolset_20260401
  - type: mcp_toolset
    mcp_server_name: github
---

Each entry in mcp_servers defines one connection.

  • type is required and must be url.
  • name is required. It must be unique within the agent and 1-255 characters long. The same string is the mcp_server_name on the toolset, and it is what appears on MCP tool events in the session event stream.
  • url is required. It is the remote MCP server endpoint, up to 2,048 characters. The connector page points to the supported MCP server types reference for transport requirements rather than listing them here.

An agent can declare up to 20 MCP servers. Server names must be unique within the array.

Match every server with a toolset

A URL entry alone is not a working connector. Each declared server also needs a matching mcp_toolset in the tools array, and that toolset's mcp_server_name must equal the server's name. In the example, both sides use github.

The check is two-way. Every mcp_servers entry must be referenced by an mcp_toolset, and every mcp_toolset must reference a declared server. The API rejects agent definitions with unreferenced servers or dangling toolsets. If you add a server and forget the toolset, or leave a toolset pointing at a name you removed, creation fails.

Choose which MCP tools stay on

The mcp_toolset entry supports a default_config object and a configs array, applied to the tools the MCP server exposes. Each configs entry accepts only name, enabled, and permission_policy. Unlike entries in the built-in agent toolset, MCP tool entries do not take a type field. Web settings available on web_search and web_fetch do not apply to MCP tools. The name you set is the bare tool name as reported by the server.

By default, all tools the MCP server exposes are enabled. To enable only specific tools, set default_config.enabled to false and explicitly enable the tools you want. Refer to official documentation for exact syntax.

That pattern is useful when a server exposes many tools but the agent only needs a few, or when you want tools added later by the server operator to stay off until you review them.

To disable specific tools while keeping the rest enabled, omit default_config and set enabled to false on individual entries:

{
  "type": "mcp_toolset",
  "mcp_server_name": "github",
  "configs": [{ "name": "delete_repository", "enabled": false }]
}

permission_policy can sit on those same entries. The connector page sends you to the configuring-the-toolset docs for the general default_config / configs pattern, and to MCP toolset permissions for confirmation requests.

Expect large tool output in a file

When an MCP tool output exceeds 100,000 characters (about 25,000 tokens), it is automatically written to a file in the sandbox. The model receives a truncated preview with the file path and can read the full content from there. The connector page describes this as automatic and does not show a setting for that threshold.

Pass vault IDs when the session starts

When starting a session, pass vault_ids. Vaults are collections of credentials that you register once and reference by ID. How to create a vault and add credentials is on the Authenticate with vaults page. The connector points to the static_bearer and mcp_oauth credential types on the vaults page.

The Python example creates the session like this:

session = client.beta.sessions.create(
    agent=agent.id,
    environment_id=environment.id,
    vault_ids=[vault.id],
)

Credentials are matched by URL, so the vault must contain a credential whose mcp_server_url refers to the same server as the url in mcp_servers. Both URLs are normalized before matching: scheme and host are lowercased, and default ports and trailing slashes are stripped. Host casing, a default port, or a trailing slash still matches. A different path, subdomain, or non-default port does not. If none matches, the connection is attempted unauthenticated.

Networking can stop the session before credentials are tried. With a limited environment, session creation fails with a 400 error when the agent declares an MCP server whose host is not in allowed_hosts. Setting allow_mcp_servers to true in the environment's networking turns this check off.

Read connection failures from the event stream

Session creation does not validate MCP connectivity or credentials. The host check against the environment's networking is separate: a limited environment still returns 400 when a host is not allowed, as described above. If the server is unreachable or rejects the credential, the session still starts and interaction remains possible.

A session.error event is emitted with the mcp_server_name of the affected server and a retry_status.

  • mcp_connection_failed_error means the MCP server could not be reached: a network error, a timeout, or a non-authentication HTTP failure.
  • mcp_authentication_failed_error means authentication failed. The server rejected the credential from the attached vault, the server required authentication when no matching credential was configured, or an OAuth token refresh failed.

From that event you can block further interaction, trigger a credential rotation, or let the session continue without the affected server's tools. The connection is retried on the next transition from session.status_idle to session.status_running. A successful create does not mean the server accepted the credential, so watch for session.error after the session starts.

What to do next

Declare the url server and the matching mcp_toolset on the agent, then create a session with vault_ids whose credential URL normalizes to that same endpoint. After that, read three companion pages in the Claude Platform docs: permission policies, for when agent and MCP tools run; the session event stream, for session.error and for interrupting or redirecting a running session; and supported MCP server types, for transport requirements on remote servers.

Sources