fix(mcp): ignore oversized path-like text (#4582)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
yjchen101 2026-07-30 23:52:07 +08:00 committed by GitHub
parent 60fe0c4433
commit 6fe6bad001
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View File

@ -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()

View File

@ -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")