- main.py: import files_app, append McpService entry to MCP_SERVICES. Lifespan already iterates the list, so no edit to the lifespan function. - tests/conftest.py: autouse fixture rebinds files_mcp.core.path_guard._ROOT to a per-test tmp_path so the sandbox is fresh for every test. - files_mcp/__init__.py: drop the try/except around the server import now that server.py exists, restoring fail-fast on a missing/corrupt server module in production. The _init_root() try/except stays, since pytest collection can import the package before FILES_MCP_ROOT is set. Verified via uv run pytest: 327 tests pass, no regressions. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
29 lines
902 B
Python
29 lines
902 B
Python
# coding=utf-8
|
|
"""
|
|
@Time :2026/6/30
|
|
@Author :tao.chen
|
|
"""
|
|
from pathlib import Path
|
|
|
|
from files_mcp.core import path_guard
|
|
|
|
# Fail fast at process start if FILES_MCP_ROOT is unset / bad. During tests
|
|
# the root is injected via set_root_for_testing(), so tolerate the env var
|
|
# being unset here rather than crashing at import/collection time.
|
|
_ROOT: Path | None
|
|
try:
|
|
_ROOT = path_guard._init_root()
|
|
except RuntimeError:
|
|
_ROOT = None
|
|
|
|
# Re-export the FastAPI app. server.py now exists, so this import is
|
|
# unconditional — a missing/corrupt server.py fails loud at import time
|
|
# (production-correct behavior). The sandbox root is only needed by the
|
|
# tool routes at request time, not at import, so this stays safe to import
|
|
# even when FILES_MCP_ROOT is unset (e.g. during pytest collection).
|
|
from files_mcp.server import app # noqa: E402
|
|
|
|
ROOT: Path | None = _ROOT
|
|
|
|
__all__ = ["app", "ROOT"]
|