AgentSpec, so the agent can call the server’s tools while it runs.
What is MCP?
Model Context Protocol (MCP) is a standardized way for AI agents to interact with external data sources, tools, and services. By connecting an MCP server to an agent, it can:- Fetch real-time data (market data, internal APIs, databases)
- Call tools exposed by the server
- Access resources the server publishes
tools_list_dictionary function tools.
Ways to connect
AgentSpec exposes four related fields. Use the simplest one that fits:
1. mcp_url — a URL string or connection object
For an unauthenticated server, a plain URL string is enough:
mcp_url also accepts a full MCPConnection object when you need auth, a specific transport, or custom timeouts, instead of using mcp_config:
2. mcp_urls — multiple servers
mcp_urls is a plain JSON array; each entry is either a URL string or an MCPConnection object. Tools from every server are combined into one tool list for the agent:
3. mcp_config — a single connection with full control
Use mcp_config instead of mcp_url when you want the connection shape to be explicit (custom headers, an authorization token, a specific transport, or a timeout):
4. mcp_configs — multiple fully-configured connections
mcp_configs is a plain JSON array of MCPConnection objects (not wrapped in an outer object):
MCPConnection fields
All four fields above accept objects shaped like MCPConnection:
Transports
Settransport on the connection object:
streamable_http(default) — HTTP-based MCP transport, used for most remote servers.sse— Server-sent events transport.stdio— Launches a local process (command+args) and speaks MCP over stdin/stdout.auto— Let the client negotiate the transport with the server.
Auth modes
Ifauth_type is not set explicitly, it’s inferred in this order:
oauth— ifoauthis set.api_key— else ifapi_keyis set (sent viaapi_key_header/api_key_prefix).bearer— else ifauthorization_tokenis set (sent asAuthorization: Bearer <token>, unlessheadersalready definesAuthorization).custom— else ifheadersis set (sent as-is).none— otherwise.
MCPOAuthConfig fields
Set oauth on the connection to use OAuth 2.1 instead of a static token or API key. Three flows are supported:
authorization_code(default) — the interactive browser flow from the MCP authorization spec. PKCE and RFC 7591 dynamic client registration are handled automatically, soclient_idis optional. Tokens are cached on disk so the browser prompt only happens once.client_credentials— a headless machine-to-machine flow. Requiresclient_id/client_secret. The token endpoint is discovered from the server’s/.well-known/oauth-authorization-servermetadata unlesstoken_urlis given.- A pre-obtained
access_token— no flow is run; the token is sent directly as a bearer credential.
Secrets via environment variables
Rather than hardcoding a token in the request body, secret-bearing fields accept an indirection syntax:"env:MY_VAR" or "${MY_VAR}" reads the value from an environment variable on the server at connection time instead of the literal string.
This applies to:
MCPConnection.api_keyMCPConnection.authorization_tokenMCPConnection.envvalues (for thestdiotransport)MCPOAuthConfig.access_token,client_id,client_secret, andtoken_url
headers values are sent as-is and are not resolved through env:/${...} — only the fields listed above are.Billing
Agent completions bill a flat $0.10 MCP fee (agent_completions_mcp_cost) once per request when agent_config.mcp_url is set on the request. This is in addition to the usual token costs. Fetch current pricing from GET /v1/usage/costs rather than hardcoding it, since it can change.
Complete example: quantitative agent with MCP
Related resources
Agent Completions
Full
AgentSpec field referenceSwarms API Tools
Built-in
auto_search/web_scraper tools and autonomous looper tools