From 77c209fbf5715b59d899be8a540e7c63f6461e8a Mon Sep 17 00:00:00 2001 From: AgeevVG <99813231+AgeevVG@users.noreply.github.com> Date: Mon, 23 Nov 2026 03:57:12 +0300 Subject: [PATCH] =?UTF-8?q?fix(mcp):=20=D1=8F=D0=B2=D0=BD=D1=8B=D0=B5=20--?= =?UTF-8?q?pages/--vectors=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=D1=8E=D1=82=D1=81=D1=8F=20=D0=B1=D0=B5=D0=B7=20fcntl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit На Windows нет модуля fcntl, а runtime/v8std_mcp_snapshots.py импортировал его безусловно. Сервер падал при импорте даже с явными --pages/--vectors, которым кэш снимков не нужен. Импорт fcntl стал необязательным, SNAPSHOT_CACHE_SUPPORTED показывает, доступен ли кэш снимков. Режим SITE_URL без него отказывает в parse_args до загрузки источника и подсказывает --pages/--vectors. На POSIX поведение не меняется. Closes #48 --- runtime/v8std_mcp_server.py | 3 +++ runtime/v8std_mcp_snapshots.py | 8 +++++++- tests/test_v8std_mcp_runtime.py | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/runtime/v8std_mcp_server.py b/runtime/v8std_mcp_server.py index bc1b43b..ff29aea 100644 --- a/runtime/v8std_mcp_server.py +++ b/runtime/v8std_mcp_server.py @@ -43,6 +43,7 @@ ) from runtime.v8std_mcp_runtime import SnapshotIndex from runtime.v8std_mcp_snapshot_format import DEFAULT_SITE_URL, SnapshotError, normalize_site_url +from runtime.v8std_mcp_snapshots import SNAPSHOT_CACHE_SUPPORTED MCP_SELF_DOC_MESSAGE = "This is a MCP Streamable HTTP endpoint" @@ -990,6 +991,8 @@ def parse_args(argv: list[str]) -> argparse.Namespace: args.site_url = None if legacy else normalize_site_url(site if site is not None else DEFAULT_SITE_URL) except SnapshotError: parser.error("invalid SITE_URL") + if args.site_url is not None and not SNAPSHOT_CACHE_SUPPORTED: + parser.error("SITE_URL snapshot mode needs POSIX file locking; on this platform use --pages and --vectors") args.index_url = args.index_url if args.index_url is not None else DEFAULT_INDEX_URL args.vectors_url = args.vectors_url if args.vectors_url is not None else DEFAULT_VECTORS_URL raw_limit = args.max_snippet_chars diff --git a/runtime/v8std_mcp_snapshots.py b/runtime/v8std_mcp_snapshots.py index 55f8105..0b4a7b3 100644 --- a/runtime/v8std_mcp_snapshots.py +++ b/runtime/v8std_mcp_snapshots.py @@ -16,7 +16,10 @@ from __future__ import annotations from contextlib import contextmanager -import fcntl +try: + import fcntl +except ImportError: # Windows: no flock and no O_NOFOLLOW/O_DIRECTORY; see SNAPSHOT_CACHE_SUPPORTED. + fcntl = None import http.client import io import multiprocessing @@ -44,6 +47,9 @@ validate_manifest, verify_archive, ) +# The snapshot cache relies on POSIX file locking and open flags. Without them only +# explicit --pages/--vectors sources can run; importing this module must still work. +SNAPSHOT_CACHE_SUPPORTED = fcntl is not None ATTEMPT_SECONDS = 360 READ_SECONDS = 20 CACHE_BYTES = 256 * 1024 * 1024 diff --git a/tests/test_v8std_mcp_runtime.py b/tests/test_v8std_mcp_runtime.py index e462928..17b5a70 100644 --- a/tests/test_v8std_mcp_runtime.py +++ b/tests/test_v8std_mcp_runtime.py @@ -313,6 +313,23 @@ def test_ambiguous_or_empty_configuration_fails_without_loading(self): self.assertNotIn("private-path", stderr.getvalue()) self.assertNotIn("secret.invalid", stderr.getvalue()) + def test_explicit_local_sources_start_without_fcntl(self): + # Windows has no fcntl: the server must still import and accept --pages/--vectors, + # while snapshot mode is refused at argument parsing, before any source is loaded. + probe = "\n".join(( + "import sys", + "sys.modules['fcntl'] = None", + "from runtime.v8std_mcp_server import parse_args", + "assert parse_args(['--pages', 'pages.jsonl', '--vectors', 'search-vectors.jsonl']).site_url is None", + "parse_args([])", + )) + environment = {key: value for key, value in os.environ.items() if not key.startswith("V8STD_MCP_")} + result = subprocess.run([sys.executable, "-c", probe], cwd=ROOT, env=environment, + capture_output=True, text=True, timeout=60) + self.assertEqual(result.returncode, 2, result.stderr) + self.assertIn("use --pages and --vectors", result.stderr) + self.assertNotIn("Traceback", result.stderr) + def frozen_real_index(maximum=4000): from runtime.v8std_mcp_index import V8StdIndex