Files
codebase-memory-mcp/src
Andrew Hundt 1751217dae fix(mcp): scope architecture key functions by path
Previous behavior:
- handle_get_architecture() built the PageRank key_functions query with only pr.project = ?1, so a JSON request scoped to apps/hoa returned GlobalKeyFunction from scripts/helpers.py.

Changes:
- Pass path_scoped into build_key_functions_sql() in src/mcp/mcp.c:1903 and add exact-file-or-descendant predicates bound as ?2 and ?3 at src/mcp/mcp.c:6983-6987.
- Preserve unscoped first-response and codebase://architecture queries by passing path_scoped=false.
- Extend tool_get_architecture_path_scoping in tests/test_mcp.c:4421-4494 with higher-ranked out-of-scope and lower-ranked in-scope functions.

Resource and complexity:
- The scope pattern is stack-owned and copied with SQLITE_TRANSIENT; the existing sqlite3_finalize() and free(kf_sql_heap) paths remain unchanged.
- The predicate narrows scoped PageRank rows and adds no thread, worker, heap-owner, or shared-state lifecycle.

Verification:
- Red: focused ASan/UBSan test failed at tests/test_mcp.c:4494 because GlobalKeyFunction was present.
- Green: focused ASan/UBSan test passed 1/1; MCP ASan/UBSan suite passed 222/222.
- make -f Makefile.cbm lint-source-safety passed both source-safety checks.
- git clang-format --diff HEAD reported no changed-line formatting edits.

Signed-off-by: Andrew Hundt <ATHundt@gmail.com>
2026-07-16 03:31:33 -04:00
..