Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: component MCP Tools (SSE): 'Timeout' #5638

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
remove asyncio.timeout
Remove asyncio.timeout() (not valid for Py3.10) and replace it by asyncio.wait_for()
azdolinski authored Jan 24, 2025
commit fff5ffe648442a32d0a54db447d303fc3db78445
28 changes: 15 additions & 13 deletions src/backend/base/langflow/components/tools/mcp_sse.py
Original file line number Diff line number Diff line change
@@ -38,24 +38,26 @@
if headers is None:
headers = {}
url = await self.pre_check_redirect(url)

try:
async with asyncio.timeout(timeout_seconds):
sse_transport = await self.exit_stack.enter_async_context(
sse_client(url, headers, timeout_seconds, sse_read_timeout_seconds)
)
self.sse, self.write = sse_transport
self.session = await self.exit_stack.enter_async_context(ClientSession(self.sse, self.write))

await self.session.initialize()

# List available tools
response = await self.session.list_tools()
return response.tools
await asyncio.wait_for(
self._connect_with_timeout(url, headers, timeout_seconds, sse_read_timeout_seconds),
timeout=timeout_seconds
)
# List available tools
response = await self.session.list_tools()
return response.tools

Check failure on line 48 in src/backend/base/langflow/components/tools/mcp_sse.py

GitHub Actions / Ruff Style Check (3.12)

Ruff (TRY300)

src/backend/base/langflow/components/tools/mcp_sse.py:48:13: TRY300 Consider moving this statement to an `else` block
except asyncio.TimeoutError as err:
error_message = f"Connection to {url} timed out after {timeout_seconds} seconds"
raise TimeoutError(error_message) from err

async def _connect_with_timeout(self, url: str, headers: dict[str, str] | None, timeout_seconds: int, sse_read_timeout_seconds: int):

Check failure on line 53 in src/backend/base/langflow/components/tools/mcp_sse.py

GitHub Actions / Ruff Style Check (3.12)

Ruff (E501)

src/backend/base/langflow/components/tools/mcp_sse.py:53:121: E501 Line too long (137 > 120)
sse_transport = await self.exit_stack.enter_async_context(
sse_client(url, headers, timeout_seconds, sse_read_timeout_seconds)
)
self.sse, self.write = sse_transport
self.session = await self.exit_stack.enter_async_context(ClientSession(self.sse, self.write))
await self.session.initialize()


class MCPSse(Component):
client = MCPSseClient()