mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-08 23:58:34 +00:00
* docs: add pt-br translations Powered by a CrewAI Flow https://github.com/danielfsbarreto/docs_translator * Update mcp/overview.mdx brazilian docs Its en-US counterpart was updated after I did a pass, so now it includes the new section about @CrewBase
64 lines
2.6 KiB
Plaintext
64 lines
2.6 KiB
Plaintext
---
|
|
title: Conectando a Múltiplos Servidores MCP
|
|
description: Saiba como usar o MCPServerAdapter no CrewAI para conectar-se simultaneamente a múltiplos servidores MCP e agregar suas ferramentas.
|
|
icon: layer-group
|
|
---
|
|
|
|
## Visão Geral
|
|
|
|
O `MCPServerAdapter` em `crewai-tools` permite que você conecte-se a vários servidores MCP simultaneamente. Isso é útil quando seus agentes precisam acessar ferramentas distribuídas entre diferentes serviços ou ambientes. O adaptador agrega as ferramentas de todos os servidores especificados, tornando-as disponíveis para seus agentes CrewAI.
|
|
|
|
## Configuração
|
|
|
|
Para conectar-se a múltiplos servidores, você fornece uma lista de dicionários de parâmetros de servidor para o `MCPServerAdapter`. Cada dicionário na lista deve definir os parâmetros para um servidor MCP.
|
|
|
|
Os tipos de transporte suportados para cada servidor na lista incluem `stdio`, `sse` e `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.")
|
|
|
|
```
|
|
|
|
## Gerenciamento de Conexão
|
|
|
|
Ao utilizar o gerenciador de contexto (`with` statement), o `MCPServerAdapter` gerencia o ciclo de vida (início e término) de todas as conexões aos servidores MCP configurados. Isso simplifica o gerenciamento de recursos e garante que todas as conexões sejam devidamente fechadas ao sair do contexto. |