feat(files-mcp): scaffold package + path_guard sandbox

Adds the files_mcp/ sibling package and core/path_guard.py which
resolves arbitrary input paths and rejects any that escape the
FILES_MCP_ROOT sandbox (handles .., ~, symlinks, NUL, empty). Adds
tests/unit/test_path_guard.py covering accept, escape modes,
symlink escape, and _init_root failure paths.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-06-30 17:39:23 +08:00
co-authored by Claude Fable 5
parent d985883c20
commit d8d541f50d
4 changed files with 201 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
# 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 once the sandbox root has been initialized.
# server.py is created in a later task; importing it lazily keeps this
# package importable (and unit-testable) before that task lands.
try: # pragma: no cover - exercised once server.py exists
from files_mcp.server import app # noqa: E402
except ImportError:
app = None # type: ignore[assignment]
ROOT: Path | None = _ROOT
__all__ = ["app", "ROOT"]