ReMe/reme2/mcp/server.py
huangsen dd2de16481 ```
feat(file_watcher): add directory deletion support with descendant indexing

Add support for deleting entire directories and their indexed descendants
in the file watcher. Previously only individual file deletions were
handled properly. Now when a directory is deleted, the system finds all
indexed files beneath that directory path and removes them along with
their metadata and chunks.

The implementation includes:
- New `_descendant_indexed_paths` method to find all indexed files
  under a given directory path
- Updated `_on_deleted` method to process both the target path and
  all its indexed descendants
- Proper handling of symlinks and path resolution differences
- Enhanced logging to show directory deletion with child count

Also adds necessary os import for path operations.

refactor(config): restructure configuration profiles for clarity

Rename curated.yaml to remove outdated configuration file and
rename full.yaml to expert.yaml with updated documentation.
Add new service.yaml configuration profile that provides a
service-aligned MCP surface with three main tools:
- retrieve: graph-aware hybrid retrieval
- remember: single write entry point with log/distill modes
- maintain: vault hygiene sweep

The expert configuration now excludes the ingest tool since
cold-path operations are handled by external agents, and adds
memory_lint tool for structural issue detection.

Updated documentation to clarify the different configuration
profiles and their intended usage patterns.
```
2026-05-11 10:52:25 +08:00

74 lines
2.5 KiB
Python

"""vault MCP server entry point.
Usage:
python -m reme2.mcp.server [config=path/to/yaml] [service.transport=stdio]
python reme2/mcp/server.py [config=path/to/yaml] [service.transport=stdio]
By default loads `reme2/config/service.yaml` and starts the
ReMe2 application with the MCP service registered.
Env vars:
VAULT_PATH — override vault watch path (overrides config + cli args).
"""
import os
import sys
from pathlib import Path
# Make this work whether invoked as `python -m reme2.mcp.server` (repo
# root already on sys.path) or `python reme2/mcp/server.py` (only this
# file's dir is on sys.path — without this, `import reme2.mcp.steps`
# would fail with ModuleNotFoundError).
_REPO_ROOT = Path(__file__).resolve().parents[2]
if str(_REPO_ROOT) not in sys.path:
sys.path.insert(0, str(_REPO_ROOT))
from dotenv import load_dotenv # noqa: E402
# Load .env from repo root before anything else touches env vars
# (embedding/llm clients read them at construction time).
load_dotenv(_REPO_ROOT / ".env")
# Eagerly import side-effect modules so all @R.register() decorators run
# before Application introspects the registry.
import reme2 # noqa: E402,F401
import reme2.mcp.steps # noqa: E402,F401
import reme2.memory # noqa: E402,F401 -- registers retriever + maintainer
import reme2.memory.ingestor # noqa: E402,F401
import reme2.memory.summarizer # noqa: E402,F401
import reme2.component.service.mcp_service # noqa: E402,F401
from reme2.application import Application # noqa: E402
from reme2.config import parse_args # noqa: E402
_DEFAULT_CONFIG = str(_REPO_ROOT / "reme2" / "config" / "service.yaml")
def main() -> None:
argv = list(sys.argv[1:])
if not argv or argv[0].startswith("config=") or "=" in argv[0]:
argv.insert(0, "start")
if not any(a.startswith("config=") for a in argv[1:]):
argv.insert(1, f"config={_DEFAULT_CONFIG}")
vault_path = os.environ.get("VAULT_PATH")
if vault_path:
argv.append(f"components.file_watcher.default.watch_path={vault_path}")
argv.append(f"components.file_store.default.db_path={vault_path}/.reme")
argv.append(f"service.sidecar_info_path={vault_path}/.reme/sidecar.json")
sidecar_port = os.environ.get("VAULT_HTTP_PORT")
if sidecar_port:
argv.append(f"service.sidecar_http_port={sidecar_port}")
action, config = parse_args(*argv)
if action != "start":
raise SystemExit("reme2.mcp.server only supports the 'start' action")
app = Application(**config)
app.run_app()
if __name__ == "__main__":
main()