Agency Swarm agents can interact with a wider range of tools and data sources beyond their built-in capabilities by using the Model Context Protocol (MCP). MCP is an open standard (view specification) that allows agents to communicate with external services like local file systems, databases, or custom APIs, as long as those services implement the protocol. Think of MCP as a universal translator that lets your agent talk to specialized external tools.

Why use MCP?

  • Access Local Resources: Let agents read/write local files or run local commands.
  • Connect to Custom Services: Integrate with proprietary APIs or internal tools without writing specific Agency Swarm tool wrappers for each one, provided an MCP server exists.
  • Leverage Existing MCP Tools: Utilize third-party tools that already support MCP.

Supported MCP Server Types

In v1.x, Agency Swarm provides helpers to connect to MCP servers using the Agents SDK. Choose the server type based on how your tool provider operates:

Connecting Agents to MCP Servers

To give an agent access to MCP tools, you define the server connections and pass them to the agent’s mcp_servers list or tools list during initialization. Follow these steps:

Runnable Demo

For a practical, runnable example using both local and hosted MCP servers, see the complete example above or the mcp_server_example.py script located in the examples/ directory of the Agency Swarm repository.
  • Remember: The demo requires you exposing port 8000 through ngrok prior to running it.

Key Takeaways

  • MCP connects agents to external tools/data via standard protocols (Stdio, SSE, Streamable HTTP).
  • v1.x: Use mcp_server for local mcp servers and HostedMCPTool for web-based servers, since the latter allows you to avoid maintaining server lifecycle.
  • v0.x: Use MCPServerStdio for command-line tools, MCPServerSse for SSE servers, and MCPServerStreamableHttp for HTTP streaming servers.
  • External MCP servers must be running separately for the agent to connect to them.