RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Refa: change mcp_client module to rag/utils/conn (#8578)
Yongteng Lei8801de2772c6
diff --git a/Dockerfile b/Dockerfileindex 0f0727b63b..67fd264568 100644--- a/Dockerfile+++ b/Dockerfile@@ -200,7 +200,6 @@ COPY graphrag graphragCOPY agentic_reasoning agentic_reasoningCOPY pyproject.toml uv.lock ./COPY mcp mcp-COPY mcp_client mcp_clientCOPY plugin pluginCOPY docker/service_conf.yaml.template ./conf/service_conf.yaml.templatediff --git a/Dockerfile.scratch.oc9 b/Dockerfile.scratch.oc9index 2403eae167..64424735e8 100644--- a/Dockerfile.scratch.oc9+++ b/Dockerfile.scratch.oc9@@ -33,7 +33,6 @@ ADD ./rag ./ragADD ./requirements.txt ./requirements.txtADD ./agent ./agentADD ./graphrag ./graphrag-ADD ./mcp_client ./mcp_clientADD ./plugin ./pluginRUN dnf install -y openmpi openmpi-devel python3-openmpidiff --git a/api/apps/mcp_server_app.py b/api/apps/mcp_server_app.pyindex 34bd9dfb27..fb81d51e0d 100644--- a/api/apps/mcp_server_app.py+++ b/api/apps/mcp_server_app.py@@ -9,7 +9,7 @@ from api.settings import RetCodefrom api.utils import get_uuidfrom api.utils.api_utils import get_data_error_result, get_json_result, server_error_response, validate_requestfrom api.utils.web_utils import get_float, safe_json_parse-from mcp_client.mcp_tool_call import MCPToolCallSession, close_multiple_mcp_toolcall_sessions+from rag.utils.mcp_tool_call_conn import MCPToolCallSession, close_multiple_mcp_toolcall_sessions@manager.route("/list", methods=["POST"]) # noqa: F821diff --git a/api/ragflow_server.py b/api/ragflow_server.pyindex 288ae7fd3f..6d6c72ea16 100644--- a/api/ragflow_server.py+++ b/api/ragflow_server.py@@ -19,7 +19,6 @@# beartype_all(conf=BeartypeConf(violation_type=UserWarning)) # <-- emit warnings from all codefrom api.utils.log_utils import init_root_logger-from mcp_client.mcp_tool_call import shutdown_all_mcp_sessionsfrom plugin import GlobalPluginManagerinit_root_logger("ragflow_server")@@ -44,6 +43,7 @@ from api.db.init_data import init_web_datafrom api.versions import get_ragflow_versionfrom api.utils import show_configsfrom rag.settings import print_rag_settings+from rag.utils.mcp_tool_call_conn import shutdown_all_mcp_sessionsfrom rag.utils.redis_conn import RedisDistributedLockstop_event = threading.Event()diff --git a/mcp_client/__init__.py b/mcp_client/__init__.pydeleted file mode 100644index a071258534..0000000000--- a/mcp_client/__init__.py+++ /dev/null@@ -1,2 +0,0 @@-# ruff: noqa: F401-from .mcp_tool_call import MCPToolCallSession, mcp_tool_metadata_to_openai_tool, close_multiple_mcp_toolcall_sessionsdiff --git a/mcp_client/mcp_tool_call.py b/rag/utils/mcp_tool_call_conn.pysimilarity index 88%rename from mcp_client/mcp_tool_call.pyrename to rag/utils/mcp_tool_call_conn.pyindex 22fe5d20bf..5aca0e7544 100644--- a/mcp_client/mcp_tool_call.py+++ b/rag/utils/mcp_tool_call_conn.py@@ -1,8 +1,25 @@+#+# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#+import asyncioimport loggingimport threadingimport weakreffrom concurrent.futures import ThreadPoolExecutor+from concurrent.futures import TimeoutError as FuturesTimeoutErrorfrom string import Templatefrom typing import Any, Literal@@ -101,7 +118,7 @@ class MCPToolCallSession(ToolCallSession):try:result: CallToolResult | Exception = await asyncio.wait_for(results.get(), timeout=timeout)except asyncio.TimeoutError:- raise TimeoutError(f"MCP task '{task_type}' timeout after {timeout}s")+ raise asyncio.TimeoutError(f"MCP task '{task_type}' timeout after {timeout}s")if isinstance(result, Exception):raise result@@ -128,8 +145,8 @@ class MCPToolCallSession(ToolCallSession):future = asyncio.run_coroutine_threadsafe(self._get_tools_from_mcp_server(), self._event_loop)try:return future.result(timeout=timeout)- except TimeoutError:- logging.error(f"Timeout when fetching tools from MCP server: {self._mcp_server.id}")+ except FuturesTimeoutError:+ logging.error(f"Timeout when fetching tools from MCP server: {self._mcp_server.id} (timeout={timeout})")return []except Exception:logging.exception(f"Error fetching tools from MCP server: {self._mcp_server.id}")@@ -140,9 +157,9 @@ class MCPToolCallSession(ToolCallSession):future = asyncio.run_coroutine_threadsafe(self._call_mcp_tool(name, arguments), self._event_loop)try:return future.result(timeout=timeout)- except TimeoutError as te:- logging.error(f"Timeout calling tool '{name}' on MCP server: {self._mcp_server.id}")- return f"Timeout calling tool '{name}': {te}."+ except FuturesTimeoutError:+ logging.error(f"Timeout calling tool '{name}' on MCP server: {self._mcp_server.id} (timeout={timeout})")+ return f"Timeout calling tool '{name}' (timeout={timeout})."except Exception as e:logging.exception(f"Error calling tool '{name}' on MCP server: {self._mcp_server.id}")return f"Error calling tool '{name}': {e}."@@ -164,8 +181,8 @@ class MCPToolCallSession(ToolCallSession):future = asyncio.run_coroutine_threadsafe(self.close(), self._event_loop)try:future.result(timeout=timeout)- except TimeoutError:- logging.error(f"Timeout while closing session for server {self._mcp_server.id}")+ except FuturesTimeoutError:+ logging.error(f"Timeout while closing session for server {self._mcp_server.id} (timeout={timeout})")except Exception:logging.exception(f"Unexpected error during close_sync for {self._mcp_server.id}")