MCP Integration
Connect your agents to external tools and data using the Model Context Protocol (MCP).
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
Agency Swarm provides helpers to connect to the two common MCP transport protocols. 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 during initialization. Agency Swarm then automatically discovers the tools offered by the server and makes them available to the agent under the name
you specified (e.g., Filesystem_Server.list_files
).
Follow these steps:
Runnable Demo
For a practical, runnable example using both MCPServerStdio
and MCPServerSse
, see the demo_mcp.py
script located in the tests/demos/
directory of the Agency Swarm repository.
- Remember: The demo requires you to run the example SSE server (server.py) in a separate terminal first.
Key Takeaways
- MCP connects agents to external tools/data via standard protocols (Stdio, SSE).
- Use
MCPServerStdio
for command-line tool servers andMCPServerSse
for URL-based tool servers. - Define server connections using the appropriate class, providing
name
,params
, and optionally configuringstrict
andcache_tools_list
. - Pass configured server instances to the
Agent
’smcp_servers
parameter during initialization. - The
name
you give a server connection becomes the prefix for its tools (e.g.,MyServerName.tool_name
). - External MCP servers (especially SSE ones) must be running separately for the agent to connect to them.