diff --git a/ue_mcp_server.py b/ue_mcp_server.py index 881ac45..92c334e 100644 --- a/ue_mcp_server.py +++ b/ue_mcp_server.py @@ -28,15 +28,24 @@ def _engine_root() -> Path: return Path(p) +_type_index_cache: dict[str, str] = {} +_type_index_mtime: float = 0.0 + + def _load_type_index() -> dict[str, str]: - """Returns {TypeName: relative_md_path}.""" - idx = (_docs_root() / "type-index.txt").read_text() - result = {} - for line in idx.splitlines(): - if ": " in line: - name, path = line.split(": ", 1) - result[name.strip()] = path.strip() - return result + """Returns {TypeName: relative_md_path}, reloading only if the file has changed.""" + global _type_index_cache, _type_index_mtime + idx_path = _docs_root() / "type-index.txt" + mtime = idx_path.stat().st_mtime + if mtime != _type_index_mtime: + result = {} + for line in idx_path.read_text().splitlines(): + if ": " in line: + name, path = line.split(": ", 1) + result[name.strip()] = path.strip() + _type_index_cache = result + _type_index_mtime = mtime + return _type_index_cache # ---------------------------------------------------------------------------