Skip to main content

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.
swarms.tools.mcp_client_tools and its standalone functions have been removed. See Migration for direct replacements.

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

Fetch tools from every configured server. Returns OpenAI function-calling schemas by default, ready to hand to an LLM. Results are cached; pass force_refresh=True to re-fetch.
Async form: await manager.aget_tools(...).

list_tool_names

Every tool name across all configured servers — the cheapest way to see what is available.

Execution

call_tool

Call one tool directly, no LLM involved. Returns a result envelope:
Async form: await manager.acall_tool(...).

execute_tool_calls

Run the tool calls contained in an LLM response. Each call is routed to the server that advertised the tool, and results come back in call order. This is the step an 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.
Async form: 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

Both 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 in swarms.tools.mcp_client_tools were removed once everything moved onto this class. Two behavioral differences to be aware of:
  1. output_type on tool fetching is gone. get_tools_for_multiple_mcp_servers accepted the argument but never applied it. Use format="openai" | "mcp" to pick the schema shape.
  2. Execution results are wrapped. The old functions returned the raw MCP CallToolResult dump. execute_tool_calls returns one envelope per call, so results from several servers stay attributable. Read result["result"] for the tool’s own payload.

MCP Integration

Using MCP servers from an agent

Agent

Set mcp_url / mcp_urls to wire this in automatically