mirror of
https://github.com/crewAIInc/crewAI.git
synced 2025-12-16 04:18:35 +00:00
* docs(cli): document device-code login and config reset guidance; renumber sections * docs(cli): fix duplicate numbering (renumber Login/API Keys/Configuration sections) * docs: Fix webhook documentation to include meta dict in all webhook payloads - Add note explaining that meta objects from kickoff requests are included in all webhook payloads - Update webhook examples to show proper payload structure including meta field - Fix webhook examples to match actual API implementation - Apply changes to English, Korean, and Portuguese documentation Resolves the documentation gap where meta dict passing to webhooks was not documented despite being implemented in the API. * WIP: CrewAI docs theme, changelog, GEO, localization * docs(cli): fix merge markers; ensure mode: "wide"; convert ASCII tables to Markdown (en/pt-BR/ko) * docs: add group icons across locales; split Automation/Integrations; update tools overviews and links
66 lines
2.5 KiB
Plaintext
66 lines
2.5 KiB
Plaintext
---
|
|
title: Connecting to Multiple MCP Servers
|
|
description: Learn how to use MCPServerAdapter in CrewAI to connect to multiple MCP servers simultaneously and aggregate their tools.
|
|
icon: layer-group
|
|
mode: "wide"
|
|
---
|
|
|
|
## 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`.
|
|
|
|
```python
|
|
from crewai import Agent, Task, Crew, Process
|
|
from crewai_tools import MCPServerAdapter
|
|
from mcp import StdioServerParameters # Needed for Stdio example
|
|
|
|
# Define parameters for multiple MCP servers
|
|
server_params_list = [
|
|
# Streamable HTTP Server
|
|
{
|
|
"url": "http://localhost:8001/mcp",
|
|
"transport": "streamable-http"
|
|
},
|
|
# SSE Server
|
|
{
|
|
"url": "http://localhost:8000/sse",
|
|
"transport": "sse"
|
|
},
|
|
# StdIO Server
|
|
StdioServerParameters(
|
|
command="python3",
|
|
args=["servers/your_stdio_server.py"],
|
|
env={"UV_PYTHON": "3.12", **os.environ},
|
|
)
|
|
]
|
|
|
|
try:
|
|
with MCPServerAdapter(server_params_list) as aggregated_tools:
|
|
print(f"Available aggregated tools: {[tool.name for tool in aggregated_tools]}")
|
|
|
|
multi_server_agent = Agent(
|
|
role="Versatile Assistant",
|
|
goal="Utilize tools from local Stdio, remote SSE, and remote HTTP MCP servers.",
|
|
backstory="An AI agent capable of leveraging a diverse set of tools from multiple sources.",
|
|
tools=aggregated_tools, # All tools are available here
|
|
verbose=True,
|
|
)
|
|
|
|
... # Your other agent, tasks, and crew code here
|
|
|
|
except Exception as e:
|
|
print(f"Error connecting to or using multiple MCP servers (Managed): {e}")
|
|
print("Ensure all MCP servers are running and accessible with correct configurations.")
|
|
|
|
```
|
|
|
|
## 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.
|