Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions runtime/v8std_mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion runtime/v8std_mcp_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/test_v8std_mcp_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down