Overview
MCPManager is the one class handling MCP in Swarms. Point it at one or more servers and it takes care of transport selection, authentication, tool discovery, schema caching, and routing each tool call to the server that owns it.
An Agent builds one as agent.mcp_manager whenever you set mcp_url or mcp_urls. You can also use it directly, with no agent involved.
Import
Constructor
Union[str, MCPConnection, Dict]
A single server — URL string, connection object, or dict.
List[Union[str, MCPConnection, Dict]]
Several servers. Entries may mix forms, so different servers can use different authentication.
Union[MCPConnection, Dict]
Full configuration for one server.
List[Union[MCPConnection, Dict]]
Full configuration for several servers.
str
API key applied to every server that does not define its own.
str
Bearer token applied to every server that does not define its own.
Union[MCPOAuthConfig, Dict]
OAuth 2.1 configuration.
Dict[str, str]
Extra headers merged into every request.
str
Force
streamable_http, sse, or stdio. Auto-detected otherwise; hyphenated forms like streamable-http are normalized.int
default:"30"
Request timeout in seconds.
str
default:"agent"
Name used in log messages.
bool
default:"false"
Verbose logging.
int
default:"3"
Retries per operation before raising.
Discovery
get_tools
force_refresh=True to re-fetch.
await manager.aget_tools(...).
list_tool_names
Execution
call_tool
await manager.acall_tool(...).
execute_tool_calls
Agent performs between LLM turns.
Any
required
An LLM response, a single call dict, or a list of calls.
"dict" | "json" | "str"
default:"dict"
Result format.
await manager.aexecute_tool_calls(...). To re-render results you already hold, use the static MCPManager.format_results(results, output_type).
When a tool returns structured data, its payload arrives as a JSON string in the
result field:Configuration management
Authentication
env:NAME and ${NAME} indirection are resolved when the connection is made, so secrets stay out of source.
Mixed auth across servers
Errors
All live in
swarms.schemas.agent_mcp_errors. Operations retry with backoff up to retry_attempts before raising.
Migration
The standalone functions inswarms.tools.mcp_client_tools were removed once everything moved onto this class.
Two behavioral differences to be aware of:
output_typeon tool fetching is gone.get_tools_for_multiple_mcp_serversaccepted the argument but never applied it. Useformat="openai" | "mcp"to pick the schema shape.- Execution results are wrapped. The old functions returned the raw MCP
CallToolResultdump.execute_tool_callsreturns one envelope per call, so results from several servers stay attributable. Readresult["result"]for the tool’s own payload.
Related
MCP Integration
Using MCP servers from an agent
Agent
Set
mcp_url / mcp_urls to wire this in automatically