- 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 (see Authenticate with vaults).
Managed Agents API requests require the
managed-agents-2026-04-01 beta header, except memory store endpoints, which use agent-memory-2026-07-22 instead. The SDK sets the correct beta header automatically. See Beta headers.Declare MCP servers on the agent
Specify MCP servers in themcp_servers array when creating an agent. Each server needs a type, a unique name, and a url. No authentication tokens are provided at this stage.
Each declared server also needs a matching mcp_toolset entry in the tools array. The toolset’s mcp_server_name must match the server’s name.
mcp_servers field reference
Each entry in the mcp_servers array defines one connection.
Constraints:
- An agent can declare up to 20 MCP servers. Server names must be unique within the array.
- Every
mcp_serversentry must be referenced by anmcp_toolsetin thetoolsarray, and everymcp_toolsetmust reference a declared server. The API rejects agent definitions with unreferenced servers or dangling toolsets.
Configure which MCP tools are available
Themcp_toolset entry supports the same default_config and configs shape as the built-in agent toolset, applied to the tools the MCP server exposes. The name in each configs entry is the bare tool name as reported by the server.
By default all tools exposed by the MCP server are enabled. To enable only specific tools, set default_config.enabled to false and explicitly enable the tools you want:
default_config and set enabled: false on individual entries:
default_config / configs pattern, and MCP toolset permissions for setting permission_policy on MCP tools and handling confirmation requests.
MCP tool output handling
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.Provide authentication at session creation
When starting a session, passvault_ids to provide credentials for your MCP servers. Vaults are collections of credentials that you register once and reference by ID. See Authenticate with vaults for how to create vaults and manage credentials.
mcp_server_url refers to the same server as the url declared in mcp_servers. Both URLs are normalized before matching (scheme and host lowercased, default ports and trailing slashes stripped), so differences in host casing, a default port, or a trailing slash don’t prevent a match; a different path, subdomain, or non-default port does. If none matches, the connection is attempted unauthenticated. See Add a credential for the static_bearer and mcp_oauth credential types.
Handle connection and authentication failures
Session creation does not validate MCP connectivity or credentials. If an MCP server is unreachable or rejects the supplied credential, the session still starts and interaction remains possible. Asession.error event is emitted with the mcp_server_name of the affected server and a retry_status:
You can decide whether to block further interaction on this error, trigger a credential rotation, or let the session continue without the affected server’s tools. The connection is retried on the next
session.status_idle to session.status_running transition.
Next steps
Permission policies
Control when agent and MCP tools run.
Session event stream
Send events, stream responses, and interrupt or redirect your session mid-execution.
Supported MCP server types
Transport requirements for remote MCP servers.