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