# Directory Structure
```
├── .gitignore
├── memory_manager.py
├── memory.sh
└── README.md
```
# Files
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
```
1 | # Configuration files with personal data
2 | config.json
3 |
4 | # Python
5 | __pycache__/
6 | *.py[cod]
7 | *$py.class
8 | *.so
9 | .Python
10 | env/
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 |
27 | # IDE
28 | .idea/
29 | .vscode/
30 | *.swp
31 | *.swo
32 |
33 | # OS
34 | .DS_Store
35 | .DS_Store?
36 | ._*
37 | .Spotlight-V100
38 | .Trashes
39 | ehthumbs.db
40 | Thumbs.db
```
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
```markdown
1 | # Memory MCP Manager
2 |
3 | A tool to manage and switch between different memory paths for Claude clients using the [mcp-knowledge-graph](https://github.com/shaneholloman/mcp-knowledge-graph) server.
4 |
5 | ## Prerequisites
6 |
7 | - Python 3.x
8 | - A Claude client with MCP memory server
9 | - [mcp-knowledge-graph](https://github.com/shaneholloman/mcp-knowledge-graph) installed
10 |
11 | ## Quick Start
12 |
13 | ```bash
14 | # Install
15 | git clone https://github.com/yourusername/memory-mcp-manager.git
16 | cd memory-mcp-manager
17 | chmod +x memory.sh
18 |
19 | # Setup
20 | ./memory.sh init
21 | ./memory.sh add-client my-claude "/path/to/claude/config.json"
22 | ./memory.sh add project1 "~/projects/project1/memory.jsonl"
23 | ./memory.sh switch project1
24 | ```
25 |
26 | ## Commands
27 |
28 | ```bash
29 | # Client Management
30 | ./memory.sh add-client <name> <config_path> # Add a Claude client
31 | ./memory.sh list-clients # List configured clients
32 |
33 | # Memory Management
34 | ./memory.sh add <name> <path> # Add a memory path
35 | ./memory.sh remove <name> # Remove a memory path
36 | ./memory.sh switch <name> # Switch to a memory path
37 | ./memory.sh list # List all memory paths
38 | ```
39 |
40 | ## Configuration
41 |
42 | Your settings are stored in `config.json` (git-ignored):
43 |
44 | ```json
45 | {
46 | "clients": [
47 | {
48 | "name": "my-claude",
49 | "config_path": "/path/to/claude/config.json"
50 | }
51 | ],
52 | "memory_paths": {
53 | "project1": "/path/to/project1/memory.jsonl"
54 | }
55 | }
56 | ```
57 |
58 | ## How It Works
59 |
60 | When switching memory paths, the tool updates all registered Claude clients to use the new memory path, allowing you to maintain separate memory contexts for different projects.
61 |
```
--------------------------------------------------------------------------------
/memory.sh:
--------------------------------------------------------------------------------
```bash
1 | #!/bin/bash
2 |
3 | # Initialize configuration if it doesn't exist
4 | if [ ! -f "config.json" ]; then
5 | python3 memory_manager.py init
6 | fi
7 |
8 | if [ "$#" -lt 1 ]; then
9 | echo "Usage:"
10 | echo " Initialize config: ./memory.sh init"
11 | echo " Add memory path: ./memory.sh add <name> <path>"
12 | echo " Remove memory path: ./memory.sh remove <name>"
13 | echo " List memory paths: ./memory.sh list"
14 | echo " Switch memory: ./memory.sh switch <name>"
15 | echo " Add client: ./memory.sh add-client <name> <config_path>"
16 | echo " List clients: ./memory.sh list-clients"
17 | exit 1
18 | fi
19 |
20 | python3 memory_manager.py "$@"
```
--------------------------------------------------------------------------------
/memory_manager.py:
--------------------------------------------------------------------------------
```python
1 | import json
2 | import os
3 | import sys
4 |
5 | CONFIG_FILE = "config.json"
6 |
7 | def expand_path(path):
8 | """Expand ~ to user's home directory and resolve any relative paths."""
9 | return os.path.expanduser(os.path.expandvars(path))
10 |
11 | def init_config():
12 | """Initialize configuration if it doesn't exist."""
13 | if not os.path.exists(CONFIG_FILE):
14 | config = {
15 | "clients": [],
16 | "memory_paths": {}
17 | }
18 | save_config(config)
19 | print("Initialized new configuration file")
20 | return load_config()
21 |
22 | def load_config():
23 | """Load configuration, initializing if necessary."""
24 | if not os.path.exists(CONFIG_FILE):
25 | return init_config()
26 | with open(CONFIG_FILE, 'r') as f:
27 | return json.load(f)
28 |
29 | def save_config(config):
30 | with open(CONFIG_FILE, 'w') as f:
31 | json.dump(config, f, indent=2)
32 |
33 | def update_client_configs(memory_path):
34 | """Update memory path in all client configurations."""
35 | config = load_config()
36 | success = True
37 |
38 | for client in config["clients"]:
39 | try:
40 | config_path = expand_path(client["config_path"])
41 | with open(config_path, 'r') as f:
42 | client_config = json.load(f)
43 |
44 | if 'mcpServers' in client_config and 'memory' in client_config['mcpServers']:
45 | client_config['mcpServers']['memory']['args'][3] = memory_path
46 |
47 | with open(config_path, 'w') as f:
48 | json.dump(client_config, f, indent=2)
49 | print(f"Updated {client['name']} config memory path to: {memory_path}")
50 | except Exception as e:
51 | print(f"Error updating {client['name']} config: {e}")
52 | success = False
53 |
54 | return success
55 |
56 | def add_memory_path(name, path):
57 | config = load_config()
58 | config["memory_paths"][name] = expand_path(path)
59 | save_config(config)
60 | print(f"Added memory path '{name}' => '{path}'")
61 |
62 | def remove_memory_path(name):
63 | config = load_config()
64 | if name in config["memory_paths"]:
65 | del config["memory_paths"][name]
66 | save_config(config)
67 | print(f"Removed memory path '{name}'")
68 | else:
69 | print(f"Memory path '{name}' not found")
70 |
71 | def list_memory_paths():
72 | config = load_config()
73 | if not config["memory_paths"]:
74 | print("No memory paths configured")
75 | return
76 |
77 | print("\nConfigured memory paths:")
78 | for name, path in config["memory_paths"].items():
79 | print(f" {name}: {path}")
80 |
81 | def switch_memory(name):
82 | config = load_config()
83 | if name not in config["memory_paths"]:
84 | print(f"Error: Memory path '{name}' not found")
85 | return False
86 |
87 | path = config["memory_paths"][name]
88 | return update_client_configs(path)
89 |
90 | def add_client(name, config_path):
91 | config = load_config()
92 | for client in config["clients"]:
93 | if client["name"] == name:
94 | print(f"Client '{name}' already exists")
95 | return False
96 |
97 | config["clients"].append({
98 | "name": name,
99 | "config_path": expand_path(config_path)
100 | })
101 | save_config(config)
102 | print(f"Added client '{name}' with config path: {config_path}")
103 | return True
104 |
105 | def list_clients():
106 | config = load_config()
107 | print("\nConfigured clients:")
108 | for client in config["clients"]:
109 | print(f" {client['name']}: {client['config_path']}")
110 |
111 | if __name__ == "__main__":
112 | if len(sys.argv) < 2:
113 | print("Usage:")
114 | print(" Initialize config: python memory_manager.py init")
115 | print(" Add memory path: python memory_manager.py add <name> <path>")
116 | print(" Remove memory path: python memory_manager.py remove <name>")
117 | print(" List memory paths: python memory_manager.py list")
118 | print(" Switch memory: python memory_manager.py switch <name>")
119 | print(" Add client: python memory_manager.py add-client <name> <config_path>")
120 | print(" List clients: python memory_manager.py list-clients")
121 | sys.exit(1)
122 |
123 | command = sys.argv[1]
124 |
125 | if command == "init":
126 | init_config()
127 | elif command == "add" and len(sys.argv) == 4:
128 | add_memory_path(sys.argv[2], sys.argv[3])
129 | elif command == "remove" and len(sys.argv) == 3:
130 | remove_memory_path(sys.argv[2])
131 | elif command == "list":
132 | list_memory_paths()
133 | elif command == "switch" and len(sys.argv) == 3:
134 | switch_memory(sys.argv[2])
135 | elif command == "add-client" and len(sys.argv) == 4:
136 | add_client(sys.argv[2], sys.argv[3])
137 | elif command == "list-clients":
138 | list_clients()
139 | else:
140 | print("Invalid command or arguments")
```