docs: updating MCP docs with connect_timeout attribute (#3273)

This commit is contained in:
Lucas Gomide
2025-08-05 11:27:18 -03:00
committed by GitHub
parent 88ed91561f
commit 246cf588cd
2 changed files with 31 additions and 5 deletions

View File

@@ -44,6 +44,19 @@ The `MCPServerAdapter` class from `crewai-tools` is the primary way to connect t
Using a Python context manager (`with` statement) is the **recommended approach** for `MCPServerAdapter`. It automatically handles starting and stopping the connection to the MCP server. Using a Python context manager (`with` statement) is the **recommended approach** for `MCPServerAdapter`. It automatically handles starting and stopping the connection to the MCP server.
## Connection Configuration
The `MCPServerAdapter` supports several configuration options to customize the connection behavior:
- **`connect_timeout`** (optional): Maximum time in seconds to wait for establishing a connection to the MCP server. Defaults to 30 seconds if not specified. This is particularly useful for remote servers that may have variable response times.
```python
# Example with custom connection timeout
with MCPServerAdapter(server_params, connect_timeout=60) as tools:
# Connection will timeout after 60 seconds if not established
pass
```
```python ```python
from crewai import Agent from crewai import Agent
from crewai_tools import MCPServerAdapter from crewai_tools import MCPServerAdapter
@@ -70,7 +83,7 @@ server_params = {
} }
# Example usage (uncomment and adapt once server_params is set): # Example usage (uncomment and adapt once server_params is set):
with MCPServerAdapter(server_params) as mcp_tools: with MCPServerAdapter(server_params, connect_timeout=60) as mcp_tools:
print(f"Available tools: {[tool.name for tool in mcp_tools]}") print(f"Available tools: {[tool.name for tool in mcp_tools]}")
my_agent = Agent( my_agent = Agent(
@@ -95,7 +108,7 @@ There are two ways to filter tools:
### Accessing a specific tool using dictionary-style indexing. ### Accessing a specific tool using dictionary-style indexing.
```python ```python
with MCPServerAdapter(server_params) as mcp_tools: with MCPServerAdapter(server_params, connect_timeout=60) as mcp_tools:
print(f"Available tools: {[tool.name for tool in mcp_tools]}") print(f"Available tools: {[tool.name for tool in mcp_tools]}")
my_agent = Agent( my_agent = Agent(
@@ -112,7 +125,7 @@ with MCPServerAdapter(server_params) as mcp_tools:
### Pass a list of tool names to the `MCPServerAdapter` constructor. ### Pass a list of tool names to the `MCPServerAdapter` constructor.
```python ```python
with MCPServerAdapter(server_params, "tool_name") as mcp_tools: with MCPServerAdapter(server_params, "tool_name", connect_timeout=60) as mcp_tools:
print(f"Available tools: {[tool.name for tool in mcp_tools]}") print(f"Available tools: {[tool.name for tool in mcp_tools]}")
my_agent = Agent( my_agent = Agent(

View File

@@ -44,6 +44,19 @@ A classe `MCPServerAdapter` da `crewai-tools` é a principal forma de conectar-s
O uso de um gerenciador de contexto Python (`with`) é a **abordagem recomendada** para o `MCPServerAdapter`. Ele lida automaticamente com a abertura e o fechamento da conexão com o servidor MCP. O uso de um gerenciador de contexto Python (`with`) é a **abordagem recomendada** para o `MCPServerAdapter`. Ele lida automaticamente com a abertura e o fechamento da conexão com o servidor MCP.
## Configuração de Conexão
O `MCPServerAdapter` suporta várias opções de configuração para personalizar o comportamento da conexão:
- **`connect_timeout`** (opcional): Tempo máximo em segundos para aguardar o estabelecimento de uma conexão com o servidor MCP. O padrão é 30 segundos se não especificado. Isso é particularmente útil para servidores remotos que podem ter tempos de resposta variáveis.
```python
# Exemplo com timeout personalizado para conexão
with MCPServerAdapter(server_params, connect_timeout=60) as tools:
# A conexão terá timeout após 60 segundos se não estabelecida
pass
```
```python ```python
from crewai import Agent from crewai import Agent
from crewai_tools import MCPServerAdapter from crewai_tools import MCPServerAdapter
@@ -70,7 +83,7 @@ server_params = {
} }
# Exemplo de uso (descomente e adapte após definir server_params): # Exemplo de uso (descomente e adapte após definir server_params):
with MCPServerAdapter(server_params) as mcp_tools: with MCPServerAdapter(server_params, connect_timeout=60) as mcp_tools:
print(f"Available tools: {[tool.name for tool in mcp_tools]}") print(f"Available tools: {[tool.name for tool in mcp_tools]}")
meu_agente = Agent( meu_agente = Agent(
@@ -88,7 +101,7 @@ Este padrão geral mostra como integrar ferramentas. Para exemplos específicos
## Filtrando Ferramentas ## Filtrando Ferramentas
```python ```python
with MCPServerAdapter(server_params) as mcp_tools: with MCPServerAdapter(server_params, connect_timeout=60) as mcp_tools:
print(f"Available tools: {[tool.name for tool in mcp_tools]}") print(f"Available tools: {[tool.name for tool in mcp_tools]}")
meu_agente = Agent( meu_agente = Agent(