From 082ef9c8a792e7ce90a638fac18900af4cdb0d0f Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Sat, 28 Feb 2026 22:48:19 -0600 Subject: [PATCH] feat: per-project graph routing via COGNITIVE_MEMORY_GRAPH env var Allows projects to automatically route all memory operations to a specific graph without passing graph= on every MCP call. Set the env var in a project's .claude/settings.json to target a named graph. Resolution order: explicit graph param > env var > "default". Co-Authored-By: Claude Opus 4.6 --- mcp_server.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mcp_server.py b/mcp_server.py index 2ea9667..1e4e0aa 100644 --- a/mcp_server.py +++ b/mcp_server.py @@ -44,10 +44,17 @@ _clients: Dict[str, CognitiveMemoryClient] = {} def get_client(graph: Optional[str] = None) -> CognitiveMemoryClient: - """Get or create a CognitiveMemoryClient for the given graph.""" - key = graph or "default" + """Get or create a CognitiveMemoryClient for the given graph. + + Resolution order: explicit graph param > COGNITIVE_MEMORY_GRAPH env var > "default". + Set COGNITIVE_MEMORY_GRAPH per-project via Claude Code's .claude/settings.json env overrides. + """ + import os + + effective_graph = graph or os.environ.get("COGNITIVE_MEMORY_GRAPH") or None + key = effective_graph or "default" if key not in _clients: - path = resolve_graph_path(graph) + path = resolve_graph_path(effective_graph) _clients[key] = CognitiveMemoryClient(memory_dir=path) return _clients[key]