Repository navigation
Description
Summary
lookup_native, search_events and search_docs each open and json.load their data file on every call, with no caching. For the native databases (3.5 MB / 2.8 MB) re-parsing is 90-95% of each lookup.
Where
mcp-server/tools/natives.py:29-36(lookup_native)mcp-server/tools/event_search.py:28-34(search_events)mcp-server/tools/docs_search.py:38-44(search_docs)mcp-server/server.py:28(NATIVES_PATHused for all three datasets)
Details
with open(filepath, "r", encoding="utf-8") as f:
natives = json.load(f)Measured at 701824d: parsing natives_gta5.json (6,339 entries) takes about 37 ms and natives_rdr3.json (5,876 entries) about 17 ms, allocating about 17 MB at peak per parse. The substring scan itself takes about 2.6 ms. The events and docs files are small (under 0.5 ms), but the three modules repeat the same load-and-check code, and a malformed JSON file raises an uncaught exception.
Impact
Agents often make many native lookups in a row; each pays about 35 ms of CPU and allocation churn on the single stdio server thread, growing as upstream databases grow. A fourth dataset would mean a fourth copy of the loader.
Steps to reproduce
python -c "import sys,time; sys.path.insert(0,'mcp-server'); from tools.natives import lookup_native; t=time.perf_counter(); lookup_native('vehicle','gta5',None,'mcp-server/data',None); print(time.perf_counter()-t)"prints about 0.037 s on each call.
Suggested fix
- Add
tools/data.pywithload_dataset(data_path, filename) -> list | str, cached by(path, mtime)(for examplefunctools.lru_cacheon a helper keyed by both), returning a consistent error string for missing or invalid files. - Switch the three modules to it.
- Optionally precompute lowercase name, description, category and hash once at load time.
Acceptance criteria
- Each data file is parsed once per process unless it changes on disk.
- Missing and malformed files return an error string from all three tools, not an exception.
- Repeated
lookup_nativecalls take a few milliseconds after the first.
Getting started
- Relevant files:
mcp-server/tools/natives.py,mcp-server/tools/event_search.py,mcp-server/tools/docs_search.py - How to run checks: there is no test suite yet; run the MCP server with
cd mcp-server && pip install -r requirements.txt && python server.py, and CI checks live in.github/workflows/validate.yml - Related docs:
mcp-server/README.md(Data files)
Filed by repo-audit/full-audit at 701824d. Severity: low. Effort: S. audit-key: performance|mcp-server/tools/natives.py|json-cache
Activity
TMHSDigital commentedon Nov 21, 2026
Fixed in 9f58ba2.
Added tools/data.py: each JSON data file is parsed once per process and re-read only when its mtime or size changes; missing, malformed and non-array files return a consistent error string. natives, events and docs search use it.
Verified: First lookup about 37 ms, repeat about 8 ms; tests cover single parse until change, error strings and repeat latency.