From 73eb490537782f7a1b2159d4ebc9d7570d5d8ed0 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 29 Aug 2026 19:13:20 -0500 Subject: [PATCH] utils.read_file --- src/personal_mcp/utils.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/personal_mcp/utils.py 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