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 <noreply@anthropic.com>
This commit is contained in:
parent
1fefb1d5e2
commit
082ef9c8a7
@ -44,10 +44,17 @@ _clients: Dict[str, CognitiveMemoryClient] = {}
|
|||||||
|
|
||||||
|
|
||||||
def get_client(graph: Optional[str] = None) -> CognitiveMemoryClient:
|
def get_client(graph: Optional[str] = None) -> CognitiveMemoryClient:
|
||||||
"""Get or create a CognitiveMemoryClient for the given graph."""
|
"""Get or create a CognitiveMemoryClient for the given graph.
|
||||||
key = graph or "default"
|
|
||||||
|
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:
|
if key not in _clients:
|
||||||
path = resolve_graph_path(graph)
|
path = resolve_graph_path(effective_graph)
|
||||||
_clients[key] = CognitiveMemoryClient(memory_dir=path)
|
_clients[key] = CognitiveMemoryClient(memory_dir=path)
|
||||||
return _clients[key]
|
return _clients[key]
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user