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]