diff --git a/src/personal_mcp/utils.py b/src/personal_mcp/utils.py new file mode 100644 index 0000000..0399ec1 --- /dev/null +++ b/src/personal_mcp/utils.py @@ -0,0 +1,20 @@ +import logging +from pathlib import Path + +logger = logging.getLogger(__name__) + +_FILE_CACHE: dict[Path, tuple[int, str]] = {} + + +def read_file(path: Path) -> str: + new_ts = path.stat().st_mtime_ns + match _FILE_CACHE.get(path): + case (int(timestamp), str(content)) if timestamp == new_ts: + return content + case _: + with path.open("r", encoding="utf-8") as f: + logger.info("Loading file %s", path) + content = f.read() + + _FILE_CACHE[path] = (new_ts, content) + return content