Connecting to Multiple MCP Servers
Learn how to use MCPServerAdapter in CrewAI to connect to multiple MCP servers simultaneously and aggregate their tools.
Overview
MCPServerAdapter
in crewai-tools
allows you to connect to multiple MCP servers concurrently. This is useful when your agents need to access tools distributed across different services or environments. The adapter aggregates tools from all specified servers, making them available to your CrewAI agents.
Configuration
To connect to multiple servers, you provide a list of server parameter dictionaries to MCPServerAdapter
. Each dictionary in the list should define the parameters for one MCP server.
Supported transport types for each server in the list include stdio
, sse
, and streamable-http
.
Connection Management
When using the context manager (with
statement), MCPServerAdapter
handles the lifecycle (start and stop) of all connections to the configured MCP servers. This simplifies resource management and ensures that all connections are properly closed when the context is exited.