From 482aa5a7c41dcc4028b2439376f12ce362354461 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 13 May 2025 09:31:30 -0300 Subject: [PATCH] fix: Use async file operations for error log management in MCPStdioClient (#8012) --- src/backend/base/langflow/base/mcp/util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/base/langflow/base/mcp/util.py b/src/backend/base/langflow/base/mcp/util.py index 03bd2904f..f2ac3b91e 100644 --- a/src/backend/base/langflow/base/mcp/util.py +++ b/src/backend/base/langflow/base/mcp/util.py @@ -4,13 +4,13 @@ import os import platform from collections.abc import Awaitable, Callable from contextlib import AsyncExitStack -from pathlib import Path from typing import Any, cast from urllib.parse import urlparse from uuid import UUID import aiofiles import httpx +from anyio import Path from httpx import codes as httpx_codes from loguru import logger from mcp import ClientSession, StdioServerParameters, stdio_client @@ -271,7 +271,7 @@ class MCPStdioClient: while True: await asyncio.sleep(0.05) await tmp.flush() - current = Path(errlog_path).stat().st_size + current = (await Path(errlog_path).stat()).st_size if current > last_size: async with aiofiles.open(errlog_path, encoding="utf-8") as f: await f.seek(last_size) @@ -326,7 +326,7 @@ class MCPStdioClient: finally: # Clean up the temp file with contextlib.suppress(FileNotFoundError, PermissionError): - Path(errlog_path).unlink() + await Path(errlog_path).unlink() class MCPSseClient: