From 246cf588cdb88bbb6ef4466ba5ea167b051fb13f Mon Sep 17 00:00:00 2001 From: Lucas Gomide Date: Tue, 5 Aug 2025 11:27:18 -0300 Subject: [PATCH] docs: updating MCP docs with connect_timeout attribute (#3273) --- docs/en/mcp/overview.mdx | 19 ++++++++++++++++--- docs/pt-BR/mcp/overview.mdx | 17 +++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/docs/en/mcp/overview.mdx b/docs/en/mcp/overview.mdx index a5c18b106..6b2268454 100644 --- a/docs/en/mcp/overview.mdx +++ b/docs/en/mcp/overview.mdx @@ -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. +## 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 from crewai import Agent from crewai_tools import MCPServerAdapter @@ -70,7 +83,7 @@ server_params = { } # 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]}") my_agent = Agent( @@ -95,7 +108,7 @@ There are two ways to filter tools: ### Accessing a specific tool using dictionary-style indexing. ```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]}") my_agent = Agent( @@ -112,7 +125,7 @@ with MCPServerAdapter(server_params) as mcp_tools: ### Pass a list of tool names to the `MCPServerAdapter` constructor. ```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]}") my_agent = Agent( diff --git a/docs/pt-BR/mcp/overview.mdx b/docs/pt-BR/mcp/overview.mdx index 5ce4444c9..5ceaaa144 100644 --- a/docs/pt-BR/mcp/overview.mdx +++ b/docs/pt-BR/mcp/overview.mdx @@ -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. +## 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 from crewai import Agent from crewai_tools import MCPServerAdapter @@ -70,7 +83,7 @@ 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]}") meu_agente = Agent( @@ -88,7 +101,7 @@ Este padrão geral mostra como integrar ferramentas. Para exemplos específicos ## Filtrando Ferramentas ```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]}") meu_agente = Agent(