universal-memory-mcp 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -39
- package/package.json +4 -2
- package/scripts/postinstall.js +278 -0
package/README.md
CHANGED
|
@@ -2,17 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
MCP Server for persistent AI memory across sessions. Works with any MCP-compatible AI CLI.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Automatic Setup**: Installs MCP server and memory-assistant skill automatically
|
|
8
|
+
- **Persistent Memory**: Remember conversations across sessions
|
|
9
|
+
- **Smart Recall**: AI automatically searches past discussions when relevant
|
|
10
|
+
- **Long-term Storage**: Store preferences, decisions, and important facts
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
6
13
|
|
|
7
14
|
```bash
|
|
8
15
|
npm install -g universal-memory-mcp
|
|
9
16
|
```
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
That's it! The installer will:
|
|
19
|
+
1. Configure MCP server in `~/.claude/settings.json`
|
|
20
|
+
2. Install memory-assistant skill to `~/.claude/skills/`
|
|
21
|
+
3. Prompt you to restart Claude Code
|
|
12
22
|
|
|
13
|
-
|
|
23
|
+
**After restart**, Claude will automatically:
|
|
24
|
+
- Search past conversations when you reference them
|
|
25
|
+
- Record important conversations for future recall
|
|
26
|
+
- Remember your preferences and decisions
|
|
14
27
|
|
|
15
|
-
|
|
28
|
+
## Manual Configuration
|
|
29
|
+
|
|
30
|
+
If automatic setup doesn't work, configure manually:
|
|
31
|
+
|
|
32
|
+
### Claude Code CLI
|
|
33
|
+
|
|
34
|
+
Edit `~/.claude/settings.json`:
|
|
16
35
|
|
|
17
36
|
```json
|
|
18
37
|
{
|
|
@@ -25,9 +44,9 @@ Edit `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
|
25
44
|
}
|
|
26
45
|
```
|
|
27
46
|
|
|
28
|
-
### Claude
|
|
47
|
+
### Claude Desktop
|
|
29
48
|
|
|
30
|
-
Edit
|
|
49
|
+
Edit `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
31
50
|
|
|
32
51
|
```json
|
|
33
52
|
{
|
|
@@ -40,9 +59,21 @@ Edit `~/.config/claude/settings.json`:
|
|
|
40
59
|
}
|
|
41
60
|
```
|
|
42
61
|
|
|
43
|
-
##
|
|
62
|
+
## How It Works
|
|
63
|
+
|
|
64
|
+
### Memory Assistant Skill
|
|
65
|
+
|
|
66
|
+
The installed skill guides Claude to use memory tools automatically:
|
|
67
|
+
|
|
68
|
+
| Trigger | Action |
|
|
69
|
+
|---------|--------|
|
|
70
|
+
| User mentions "之前", "上次", "remember", "we talked about" | Search past memories |
|
|
71
|
+
| End of meaningful conversation | Record the exchange |
|
|
72
|
+
| User expresses preference or makes decision | Store in long-term memory |
|
|
44
73
|
|
|
45
|
-
###
|
|
74
|
+
### MCP Tools
|
|
75
|
+
|
|
76
|
+
#### memory_search
|
|
46
77
|
|
|
47
78
|
Search through conversation history and long-term memories.
|
|
48
79
|
|
|
@@ -55,13 +86,7 @@ Search through conversation history and long-term memories.
|
|
|
55
86
|
}
|
|
56
87
|
```
|
|
57
88
|
|
|
58
|
-
|
|
59
|
-
- User asks about past discussions
|
|
60
|
-
- User references "we talked about before"
|
|
61
|
-
- Need to know user preferences (search "preferences")
|
|
62
|
-
- Need context from previous sessions
|
|
63
|
-
|
|
64
|
-
### memory_record
|
|
89
|
+
#### memory_record
|
|
65
90
|
|
|
66
91
|
Record conversation for future reference.
|
|
67
92
|
|
|
@@ -73,11 +98,7 @@ Record conversation for future reference.
|
|
|
73
98
|
}
|
|
74
99
|
```
|
|
75
100
|
|
|
76
|
-
|
|
77
|
-
- After every meaningful conversation exchange
|
|
78
|
-
- To ensure continuity across sessions
|
|
79
|
-
|
|
80
|
-
### memory_update_long_term
|
|
101
|
+
#### memory_update_long_term
|
|
81
102
|
|
|
82
103
|
Store important information for easy retrieval.
|
|
83
104
|
|
|
@@ -94,24 +115,6 @@ Store important information for easy retrieval.
|
|
|
94
115
|
- `facts` - Key information about user/projects
|
|
95
116
|
- `contacts` - People and teams
|
|
96
117
|
|
|
97
|
-
## How It Works
|
|
98
|
-
|
|
99
|
-
```
|
|
100
|
-
User asks about past discussion
|
|
101
|
-
│
|
|
102
|
-
▼
|
|
103
|
-
AI calls memory_search("topic")
|
|
104
|
-
│
|
|
105
|
-
▼
|
|
106
|
-
Returns relevant memories
|
|
107
|
-
│
|
|
108
|
-
▼
|
|
109
|
-
AI responds with context
|
|
110
|
-
│
|
|
111
|
-
▼
|
|
112
|
-
AI calls memory_record() to save this exchange
|
|
113
|
-
```
|
|
114
|
-
|
|
115
118
|
## Storage
|
|
116
119
|
|
|
117
120
|
All data stored locally in `~/.ai_memory/`:
|
|
@@ -124,10 +127,29 @@ All data stored locally in `~/.ai_memory/`:
|
|
|
124
127
|
└── config.json # Configuration
|
|
125
128
|
```
|
|
126
129
|
|
|
130
|
+
## Troubleshooting
|
|
131
|
+
|
|
132
|
+
### MCP tools not available
|
|
133
|
+
|
|
134
|
+
1. Ensure you've restarted Claude Code after installation
|
|
135
|
+
2. Check `~/.claude/settings.json` contains the MCP configuration
|
|
136
|
+
3. Try running `npx universal-memory-mcp` directly to test
|
|
137
|
+
|
|
138
|
+
### Skill not triggering
|
|
139
|
+
|
|
140
|
+
1. Check `~/.claude/skills/memory-assistant/SKILL.md` exists
|
|
141
|
+
2. Restart Claude Code to reload skills
|
|
142
|
+
3. Try explicitly asking Claude to "search my memories for X"
|
|
143
|
+
|
|
127
144
|
## Development
|
|
128
145
|
|
|
129
146
|
```bash
|
|
147
|
+
git clone https://github.com/slicenferqin/universal-memory-mcp.git
|
|
148
|
+
cd universal-memory-mcp
|
|
130
149
|
pnpm install
|
|
131
150
|
pnpm build
|
|
132
|
-
node dist/index.js
|
|
133
151
|
```
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "universal-memory-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "MCP Server for persistent AI memory across sessions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"dev": "tsc --watch",
|
|
20
20
|
"clean": "rm -rf dist",
|
|
21
21
|
"start": "node dist/index.js",
|
|
22
|
-
"test": "vitest"
|
|
22
|
+
"test": "vitest",
|
|
23
|
+
"postinstall": "node scripts/postinstall.js"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
26
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"homepage": "https://github.com/slicenferqin/universal-memory-mcp#readme",
|
|
49
50
|
"files": [
|
|
50
51
|
"dist",
|
|
52
|
+
"scripts",
|
|
51
53
|
"README.md"
|
|
52
54
|
]
|
|
53
55
|
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Universal Memory MCP - Postinstall Script
|
|
5
|
+
*
|
|
6
|
+
* Automatically configures:
|
|
7
|
+
* 1. MCP server in Claude Code settings
|
|
8
|
+
* 2. Memory assistant skill
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import fs from 'fs';
|
|
12
|
+
import path from 'path';
|
|
13
|
+
import os from 'os';
|
|
14
|
+
|
|
15
|
+
const CLAUDE_SETTINGS_PATH = path.join(os.homedir(), '.claude', 'settings.json');
|
|
16
|
+
const CLAUDE_SKILLS_PATH = path.join(os.homedir(), '.claude', 'skills');
|
|
17
|
+
|
|
18
|
+
// MCP server configuration
|
|
19
|
+
const MCP_CONFIG = {
|
|
20
|
+
'universal-memory': {
|
|
21
|
+
command: 'npx',
|
|
22
|
+
args: ['-y', 'universal-memory-mcp'],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Skill content
|
|
27
|
+
const SKILL_CONTENT = `---
|
|
28
|
+
name: memory-assistant
|
|
29
|
+
description: |
|
|
30
|
+
Automatic conversation memory management using universal-memory MCP.
|
|
31
|
+
|
|
32
|
+
ALWAYS activate this skill to:
|
|
33
|
+
1. SEARCH memories when user mentions: "之前", "上次", "我们讨论过", "remember", "we talked about", "what did we decide"
|
|
34
|
+
2. RECORD conversations at the END of EVERY meaningful response
|
|
35
|
+
3. STORE long-term info when discovering: user preferences, important decisions, key facts
|
|
36
|
+
|
|
37
|
+
This skill ensures AI maintains persistent memory across all sessions.
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
# Memory Assistant
|
|
41
|
+
|
|
42
|
+
You have access to persistent memory through the universal-memory MCP tools. Use them proactively.
|
|
43
|
+
|
|
44
|
+
## Core Rules
|
|
45
|
+
|
|
46
|
+
### 1. Always Search Before Answering (When Relevant)
|
|
47
|
+
|
|
48
|
+
When user references past conversations or asks about previous decisions:
|
|
49
|
+
|
|
50
|
+
\`\`\`
|
|
51
|
+
Call memory_search with relevant keywords
|
|
52
|
+
\`\`\`
|
|
53
|
+
|
|
54
|
+
Trigger phrases:
|
|
55
|
+
- "之前", "上次", "我们讨论过", "记得吗"
|
|
56
|
+
- "remember", "we talked about", "what did we decide", "last time"
|
|
57
|
+
- Any reference to past discussions or decisions
|
|
58
|
+
|
|
59
|
+
### 2. Always Record After Responding
|
|
60
|
+
|
|
61
|
+
At the END of EVERY meaningful conversation exchange, call:
|
|
62
|
+
|
|
63
|
+
\`\`\`
|
|
64
|
+
memory_record({
|
|
65
|
+
user_message: "<summarize user's question/request>",
|
|
66
|
+
ai_response: "<key points of your response>",
|
|
67
|
+
project: "<current project name if applicable>"
|
|
68
|
+
})
|
|
69
|
+
\`\`\`
|
|
70
|
+
|
|
71
|
+
What counts as "meaningful":
|
|
72
|
+
- Technical discussions or decisions
|
|
73
|
+
- Problem-solving conversations
|
|
74
|
+
- User preferences expressed
|
|
75
|
+
- Any information worth remembering
|
|
76
|
+
|
|
77
|
+
What to skip:
|
|
78
|
+
- Simple greetings ("hi", "thanks")
|
|
79
|
+
- Trivial clarifications
|
|
80
|
+
|
|
81
|
+
### 3. Store Important Long-term Information
|
|
82
|
+
|
|
83
|
+
When you identify important information, immediately call:
|
|
84
|
+
|
|
85
|
+
\`\`\`
|
|
86
|
+
memory_update_long_term({
|
|
87
|
+
category: "preferences" | "decisions" | "facts" | "contacts",
|
|
88
|
+
content: "<the information>"
|
|
89
|
+
})
|
|
90
|
+
\`\`\`
|
|
91
|
+
|
|
92
|
+
Categories:
|
|
93
|
+
- **preferences**: User's coding style, tool preferences, communication style
|
|
94
|
+
- **decisions**: Architecture choices, technology selections, design decisions
|
|
95
|
+
- **facts**: Key information about user, projects, team structure
|
|
96
|
+
- **contacts**: People, teams, organizations mentioned
|
|
97
|
+
|
|
98
|
+
## Examples
|
|
99
|
+
|
|
100
|
+
### Example 1: User References Past Discussion
|
|
101
|
+
|
|
102
|
+
**User**: "我们之前讨论的认证方案是什么来着?"
|
|
103
|
+
|
|
104
|
+
**Action**:
|
|
105
|
+
1. Call \`memory_search({ query: "认证方案 authentication" })\`
|
|
106
|
+
2. Use search results to answer
|
|
107
|
+
3. Call \`memory_record\` to log this exchange
|
|
108
|
+
|
|
109
|
+
### Example 2: User Expresses Preference
|
|
110
|
+
|
|
111
|
+
**User**: "我喜欢用 TypeScript,不要给我 JavaScript 代码"
|
|
112
|
+
|
|
113
|
+
**Action**:
|
|
114
|
+
1. Acknowledge the preference
|
|
115
|
+
2. Call \`memory_update_long_term({ category: "preferences", content: "用户偏好 TypeScript,不使用 JavaScript" })\`
|
|
116
|
+
3. Call \`memory_record\` to log this exchange
|
|
117
|
+
|
|
118
|
+
### Example 3: Technical Decision Made
|
|
119
|
+
|
|
120
|
+
**User**: "好,我们就用 PostgreSQL 作为主数据库"
|
|
121
|
+
|
|
122
|
+
**Action**:
|
|
123
|
+
1. Confirm the decision
|
|
124
|
+
2. Call \`memory_update_long_term({ category: "decisions", content: "选择 PostgreSQL 作为主数据库" })\`
|
|
125
|
+
3. Call \`memory_record\` to log this exchange
|
|
126
|
+
|
|
127
|
+
## Important Notes
|
|
128
|
+
|
|
129
|
+
- Memory tools are provided by the universal-memory MCP server
|
|
130
|
+
- If tools are not available, inform user to restart Claude Code
|
|
131
|
+
- Always summarize, don't record full conversation text
|
|
132
|
+
- Use project name when in a project context for better organization
|
|
133
|
+
`;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Read JSON file safely
|
|
137
|
+
*/
|
|
138
|
+
function readJsonFile(filePath) {
|
|
139
|
+
try {
|
|
140
|
+
if (fs.existsSync(filePath)) {
|
|
141
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
142
|
+
return JSON.parse(content);
|
|
143
|
+
}
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.error(`Warning: Could not read ${filePath}:`, error.message);
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Write JSON file with backup
|
|
152
|
+
*/
|
|
153
|
+
function writeJsonFile(filePath, data) {
|
|
154
|
+
const dir = path.dirname(filePath);
|
|
155
|
+
|
|
156
|
+
// Create directory if not exists
|
|
157
|
+
if (!fs.existsSync(dir)) {
|
|
158
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Backup existing file
|
|
162
|
+
if (fs.existsSync(filePath)) {
|
|
163
|
+
const backupPath = `${filePath}.backup.${Date.now()}`;
|
|
164
|
+
fs.copyFileSync(filePath, backupPath);
|
|
165
|
+
console.log(` Backed up existing config to: ${backupPath}`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Configure MCP server in Claude settings
|
|
173
|
+
*/
|
|
174
|
+
function configureMcpServer() {
|
|
175
|
+
console.log('\n📦 Configuring MCP server...');
|
|
176
|
+
|
|
177
|
+
let settings = readJsonFile(CLAUDE_SETTINGS_PATH) || {};
|
|
178
|
+
|
|
179
|
+
// Initialize mcpServers if not exists
|
|
180
|
+
if (!settings.mcpServers) {
|
|
181
|
+
settings.mcpServers = {};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Check if already configured
|
|
185
|
+
if (settings.mcpServers['universal-memory']) {
|
|
186
|
+
console.log(' MCP server already configured');
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Add MCP configuration
|
|
191
|
+
settings.mcpServers = {
|
|
192
|
+
...settings.mcpServers,
|
|
193
|
+
...MCP_CONFIG,
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
writeJsonFile(CLAUDE_SETTINGS_PATH, settings);
|
|
197
|
+
console.log(' MCP server configured successfully');
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Install memory assistant skill
|
|
203
|
+
*/
|
|
204
|
+
function installSkill() {
|
|
205
|
+
console.log('\n🎯 Installing memory-assistant skill...');
|
|
206
|
+
|
|
207
|
+
const skillDir = path.join(CLAUDE_SKILLS_PATH, 'memory-assistant');
|
|
208
|
+
const skillFile = path.join(skillDir, 'SKILL.md');
|
|
209
|
+
|
|
210
|
+
// Create skills directory if not exists
|
|
211
|
+
if (!fs.existsSync(skillDir)) {
|
|
212
|
+
fs.mkdirSync(skillDir, { recursive: true });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Check if skill already exists
|
|
216
|
+
if (fs.existsSync(skillFile)) {
|
|
217
|
+
const existingContent = fs.readFileSync(skillFile, 'utf-8');
|
|
218
|
+
if (existingContent === SKILL_CONTENT) {
|
|
219
|
+
console.log(' Skill already installed (same version)');
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
// Backup existing skill
|
|
223
|
+
const backupPath = `${skillFile}.backup.${Date.now()}`;
|
|
224
|
+
fs.copyFileSync(skillFile, backupPath);
|
|
225
|
+
console.log(` Backed up existing skill to: ${backupPath}`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
fs.writeFileSync(skillFile, SKILL_CONTENT);
|
|
229
|
+
console.log(' Skill installed successfully');
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Main installation
|
|
235
|
+
*/
|
|
236
|
+
function main() {
|
|
237
|
+
console.log('╔════════════════════════════════════════════════════════════╗');
|
|
238
|
+
console.log('║ Universal Memory MCP - Setup ║');
|
|
239
|
+
console.log('╚════════════════════════════════════════════════════════════╝');
|
|
240
|
+
|
|
241
|
+
let needsRestart = false;
|
|
242
|
+
|
|
243
|
+
try {
|
|
244
|
+
// Configure MCP server
|
|
245
|
+
const mcpConfigured = configureMcpServer();
|
|
246
|
+
if (mcpConfigured) needsRestart = true;
|
|
247
|
+
|
|
248
|
+
// Install skill
|
|
249
|
+
const skillInstalled = installSkill();
|
|
250
|
+
if (skillInstalled) needsRestart = true;
|
|
251
|
+
|
|
252
|
+
// Summary
|
|
253
|
+
console.log('\n' + '═'.repeat(60));
|
|
254
|
+
|
|
255
|
+
if (needsRestart) {
|
|
256
|
+
console.log('\n✅ Setup complete!\n');
|
|
257
|
+
console.log('⚠️ IMPORTANT: Please restart Claude Code to enable the MCP server.\n');
|
|
258
|
+
console.log('After restart, Claude will automatically:');
|
|
259
|
+
console.log(' • Search past conversations when you reference them');
|
|
260
|
+
console.log(' • Record important conversations for future recall');
|
|
261
|
+
console.log(' • Remember your preferences and decisions\n');
|
|
262
|
+
} else {
|
|
263
|
+
console.log('\n✅ Already configured! No changes needed.\n');
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
console.log('📁 Configuration locations:');
|
|
267
|
+
console.log(` MCP config: ${CLAUDE_SETTINGS_PATH}`);
|
|
268
|
+
console.log(` Skill: ${path.join(CLAUDE_SKILLS_PATH, 'memory-assistant', 'SKILL.md')}`);
|
|
269
|
+
console.log(` Memory storage: ${path.join(os.homedir(), '.ai_memory')}\n`);
|
|
270
|
+
|
|
271
|
+
} catch (error) {
|
|
272
|
+
console.error('\n❌ Setup failed:', error.message);
|
|
273
|
+
console.error('\nPlease configure manually. See README for instructions.');
|
|
274
|
+
process.exit(1);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
main();
|