From 6fe6bad001c118733364ab3ce09412b6df0eca8f Mon Sep 17 00:00:00 2001 From: yjchen101 <1945825785@qq.com> Date: Thu, 30 Jul 2026 23:52:07 +0800 Subject: [PATCH] fix(mcp): ignore oversized path-like text (#4582) Co-authored-by: Claude Fable 5 --- backend/packages/harness/deerflow/mcp/tools.py | 4 ++-- backend/tests/test_mcp_file_migration.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/packages/harness/deerflow/mcp/tools.py b/backend/packages/harness/deerflow/mcp/tools.py index 148f82b49..0072616e4 100644 --- a/backend/packages/harness/deerflow/mcp/tools.py +++ b/backend/packages/harness/deerflow/mcp/tools.py @@ -117,10 +117,10 @@ def _local_uri_to_virtual_path( try: real = src.resolve() + if not real.is_file(): + return None except OSError: return None - if not real.is_file(): - return None try: user_data_root = get_paths().sandbox_user_data_dir(thread_id, user_id=user_id).resolve() diff --git a/backend/tests/test_mcp_file_migration.py b/backend/tests/test_mcp_file_migration.py index 235be193e..c8216f804 100644 --- a/backend/tests/test_mcp_file_migration.py +++ b/backend/tests/test_mcp_file_migration.py @@ -203,6 +203,20 @@ class TestRewriteLocalPathsInText: assert result == text + def test_oversized_path_like_text_is_left_untouched(self, paths: Paths): + workspace = paths.sandbox_work_dir("t1", user_id="u1") + text = f"手术室/重症监护室(OR/ICU)整体解决方案{'说明' * 200}" + + with _patch_paths(paths): + result = mcp_tools._rewrite_local_paths_in_text( + text, + thread_id="t1", + user_id="u1", + source_base_dir=workspace, + ) + + assert result == text + def test_playwright_markdown_path_is_rewritten_twice_without_copy(self, paths: Paths): workspace = paths.sandbox_work_dir("t1", user_id="u1") _workspace_file(paths, ".playwright-mcp/page.png", content=b"png")