Ngày 1: "Xây dựng hệ thống xác thực người dùng"
Tác nhân: [Xây dựng xác thực JWT, tạo bảng người dùng, triển khai mã thông báo làm mới] Ngày 2: "Tiếp tục từ ngày hôm qua"
Tác nhân: "Tôi không có ngữ cảnh từ các phiên trước đó. Bạn có thể dán những gì chúng ta đã làm không?"
Ngày 1: "Xây dựng hệ thống xác thực người dùng"
Tác nhân: [Xây dựng xác thực JWT, tạo bảng người dùng, triển khai mã thông báo làm mới] Ngày 2: "Tiếp tục từ ngày hôm qua"
Tác nhân: "Tôi không có ngữ cảnh từ các phiên trước đó. Bạn có thể dán những gì chúng ta đã làm không?"
Ngày 1: "Xây dựng hệ thống xác thực người dùng"
Tác nhân: [Xây dựng xác thực JWT, tạo bảng người dùng, triển khai mã thông báo làm mới] Ngày 2: "Tiếp tục từ ngày hôm qua"
Tác nhân: "Tôi không có ngữ cảnh từ các phiên trước đó. Bạn có thể dán những gì chúng ta đã làm không?"
┌─────────────────┐ ┌──────────────────┐ ┌─────────────┐
│ Tác nhân AI │ │ Máy chủ bộ nhớ │ │ Lưu trữ │
│ (Claude Code) │◄───────►│ MCP │◄───────►│ (SQLite) │
└─────────────────┘ JSON └──────────────────┘ I/O └─────────────┘
┌─────────────────┐ ┌──────────────────┐ ┌─────────────┐
│ Tác nhân AI │ │ Máy chủ bộ nhớ │ │ Lưu trữ │
│ (Claude Code) │◄───────►│ MCP │◄───────►│ (SQLite) │
└─────────────────┘ JSON └──────────────────┘ I/O └─────────────┘
┌─────────────────┐ ┌──────────────────┐ ┌─────────────┐
│ Tác nhân AI │ │ Máy chủ bộ nhớ │ │ Lưu trữ │
│ (Claude Code) │◄───────►│ MCP │◄───────►│ (SQLite) │
└─────────────────┘ JSON └──────────────────┘ I/O └─────────────┘
npm install -g @example/mcp-memory-server
npm install -g @example/mcp-memory-server
npm install -g @example/mcp-memory-server
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import fs from "fs/promises";
import path from "path"; const MEMORY_FILE = path.join(process.env.HOME, ".mcp-memory", "memories.json"); const server = new McpServer({ name: "memory", version: "1.0.0"
}); // Ensure memory file exists
async function initMemory() { await fs.mkdir(path.dirname(MEMORY_FILE), { recursive: true }); try { await fs.access(MEMORY_FILE); } catch { await fs.writeFile(MEMORY_FILE, JSON.stringify([])); }
} // Tool: remember
server.tool( "remember", { content: z.string().describe("Thông tin cần lưu trữ"), tags: z.array(z.string()).describe("Thẻ để truy xuất (ví dụ: ['backend', 'auth'])"), agent: z.string().optional().describe("Tên tác nhân để gắn thẻ") }, async ({ content, tags, agent }) => { await initMemory(); const memories = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const memory = { id: Date.now().toString(), content, tags, agent, timestamp: new Date().toISOString() }; memories.push(memory); await fs.writeFile(MEMORY_FILE, JSON.stringify(memories, null, 2)); return { content: [{ type: "text", text: `Đã lưu bộ nhớ với các thẻ: ${tags.join(", ")}` }] }; }
); // Tool: recall
server.tool( "recall", { query: z.string().describe("Truy vấn tìm kiếm hoặc thẻ để tìm"), agent: z.string().optional().describe("Lọc theo tên tác nhân") }, async ({ query, agent }) => { await initMemory(); const memories = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const results = memories.filter(m => (m.content.toLowerCase().includes(query.toLowerCase()) || m.tags.some(t => t.toLowerCase().includes(query.toLowerCase()))) && (!agent || m.agent === agent) ); return { content: [{ type: "text", text: results.length === 0 ? "Không tìm thấy bộ nhớ nào" : results.map(m => `[${m.timestamp}] ${m.content}`).join("\n\n") }] }; }
); // Tool: search
server.tool( "search", { tags: z.array(z.string()).describe("Các thẻ cần tìm kiếm"), limit: z.number().optional().default(10) }, async ({ tags, limit }) => { await initMemory(); const memories = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const results = memories .filter(m => tags.some(t => m.tags.includes(t))) .slice(0, limit); return { content: [{ type: "text", text: results.map(m => `[${m.agent || "unknown"}] ${m.content}`).join("\n\n") }] }; }
); // Tool: rollback
server.tool( "rollback", { agent: z.string().describe("Tên tác nhân để khôi phục"), timestamp: z.string().describe("Khôi phục về thời điểm này") }, async ({ agent, timestamp }) => { await initMemory(); const memories = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const rolledBack = memories.filter(m => m.agent !== agent || new Date(m.timestamp) <= new Date(timestamp) ); await fs.writeFile(MEMORY_FILE, JSON.stringify(rolledBack, null, 2)); return { content: [{ type: "text", text: `Đã khôi phục ${agent} về ${timestamp}` }] }; }
); const transport = new StdioServerTransport();
await server.connect(transport);
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import fs from "fs/promises";
import path from "path"; const MEMORY_FILE = path.join(process.env.HOME, ".mcp-memory", "memories.json"); const server = new McpServer({ name: "memory", version: "1.0.0"
}); // Ensure memory file exists
async function initMemory() { await fs.mkdir(path.dirname(MEMORY_FILE), { recursive: true }); try { await fs.access(MEMORY_FILE); } catch { await fs.writeFile(MEMORY_FILE, JSON.stringify([])); }
} // Tool: remember
server.tool( "remember", { content: z.string().describe("Thông tin cần lưu trữ"), tags: z.array(z.string()).describe("Thẻ để truy xuất (ví dụ: ['backend', 'auth'])"), agent: z.string().optional().describe("Tên tác nhân để gắn thẻ") }, async ({ content, tags, agent }) => { await initMemory(); const memories = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const memory = { id: Date.now().toString(), content, tags, agent, timestamp: new Date().toISOString() }; memories.push(memory); await fs.writeFile(MEMORY_FILE, JSON.stringify(memories, null, 2)); return { content: [{ type: "text", text: `Đã lưu bộ nhớ với các thẻ: ${tags.join(", ")}` }] }; }
); // Tool: recall
server.tool( "recall", { query: z.string().describe("Truy vấn tìm kiếm hoặc thẻ để tìm"), agent: z.string().optional().describe("Lọc theo tên tác nhân") }, async ({ query, agent }) => { await initMemory(); const memories = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const results = memories.filter(m => (m.content.toLowerCase().includes(query.toLowerCase()) || m.tags.some(t => t.toLowerCase().includes(query.toLowerCase()))) && (!agent || m.agent === agent) ); return { content: [{ type: "text", text: results.length === 0 ? "Không tìm thấy bộ nhớ nào" : results.map(m => `[${m.timestamp}] ${m.content}`).join("\n\n") }] }; }
); // Tool: search
server.tool( "search", { tags: z.array(z.string()).describe("Các thẻ cần tìm kiếm"), limit: z.number().optional().default(10) }, async ({ tags, limit }) => { await initMemory(); const memories = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const results = memories .filter(m => tags.some(t => m.tags.includes(t))) .slice(0, limit); return { content: [{ type: "text", text: results.map(m => `[${m.agent || "unknown"}] ${m.content}`).join("\n\n") }] }; }
); // Tool: rollback
server.tool( "rollback", { agent: z.string().describe("Tên tác nhân để khôi phục"), timestamp: z.string().describe("Khôi phục về thời điểm này") }, async ({ agent, timestamp }) => { await initMemory(); const memories = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const rolledBack = memories.filter(m => m.agent !== agent || new Date(m.timestamp) <= new Date(timestamp) ); await fs.writeFile(MEMORY_FILE, JSON.stringify(rolledBack, null, 2)); return { content: [{ type: "text", text: `Đã khôi phục ${agent} về ${timestamp}` }] }; }
); const transport = new StdioServerTransport();
await server.connect(transport);
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import fs from "fs/promises";
import path from "path"; const MEMORY_FILE = path.join(process.env.HOME, ".mcp-memory", "memories.json"); const server = new McpServer({ name: "memory", version: "1.0.0"
}); // Ensure memory file exists
async function initMemory() { await fs.mkdir(path.dirname(MEMORY_FILE), { recursive: true }); try { await fs.access(MEMORY_FILE); } catch { await fs.writeFile(MEMORY_FILE, JSON.stringify([])); }
} // Tool: remember
server.tool( "remember", { content: z.string().describe("Thông tin cần lưu trữ"), tags: z.array(z.string()).describe("Thẻ để truy xuất (ví dụ: ['backend', 'auth'])"), agent: z.string().optional().describe("Tên tác nhân để gắn thẻ") }, async ({ content, tags, agent }) => { await initMemory(); const memories = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const memory = { id: Date.now().toString(), content, tags, agent, timestamp: new Date().toISOString() }; memories.push(memory); await fs.writeFile(MEMORY_FILE, JSON.stringify(memories, null, 2)); return { content: [{ type: "text", text: `Đã lưu bộ nhớ với các thẻ: ${tags.join(", ")}` }] }; }
); // Tool: recall
server.tool( "recall", { query: z.string().describe("Truy vấn tìm kiếm hoặc thẻ để tìm"), agent: z.string().optional().describe("Lọc theo tên tác nhân") }, async ({ query, agent }) => { await initMemory(); const memories = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const results = memories.filter(m => (m.content.toLowerCase().includes(query.toLowerCase()) || m.tags.some(t => t.toLowerCase().includes(query.toLowerCase()))) && (!agent || m.agent === agent) ); return { content: [{ type: "text", text: results.length === 0 ? "Không tìm thấy bộ nhớ nào" : results.map(m => `[${m.timestamp}] ${m.content}`).join("\n\n") }] }; }
); // Tool: search
server.tool( "search", { tags: z.array(z.string()).describe("Các thẻ cần tìm kiếm"), limit: z.number().optional().default(10) }, async ({ tags, limit }) => { await initMemory(); const memories = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const results = memories .filter(m => tags.some(t => m.tags.includes(t))) .slice(0, limit); return { content: [{ type: "text", text: results.map(m => `[${m.agent || "unknown"}] ${m.content}`).join("\n\n") }] }; }
); // Tool: rollback
server.tool( "rollback", { agent: z.string().describe("Tên tác nhân để khôi phục"), timestamp: z.string().describe("Khôi phục về thời điểm này") }, async ({ agent, timestamp }) => { await initMemory(); const memories = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const rolledBack = memories.filter(m => m.agent !== agent || new Date(m.timestamp) <= new Date(timestamp) ); await fs.writeFile(MEMORY_FILE, JSON.stringify(rolledBack, null, 2)); return { content: [{ type: "text", text: `Đã khôi phục ${agent} về ${timestamp}` }] }; }
); const transport = new StdioServerTransport();
await server.connect(transport);
node memory-server.js
node memory-server.js
node memory-server.js
Bạn có quyền truy cập vào các công cụ bộ nhớ MCP: remember, recall, search, rollback. Tuân thủ các quy tắc sau: **Khi bắt đầu một phiên:**
1. recall(query="ecommerce-api", agent="Backend Architect")
2. Xem lại các item pending từ phiên trước **Khi hoàn thành công việc:**
1. remember(content="Đã tạo bảng người dùng với UUID...", tags=["ecommerce-api", "database", "auth"], agent="Backend Architect")
2. Lưu lại quyết định, các mục pending **Khi chuyển giao cho agent khác:**
1. remember(content="Điểm cuối API: ...", tags=["ecommerce-api", "handoff"], agent="Backend Architect", for="Frontend Developer") **Khi có lỗi:**
1. recall/search checkpoint gần nhất
2. rollback về trạng thái ổn định
Bạn có quyền truy cập vào các công cụ bộ nhớ MCP: remember, recall, search, rollback. Tuân thủ các quy tắc sau: **Khi bắt đầu một phiên:**
1. recall(query="ecommerce-api", agent="Backend Architect")
2. Xem lại các item pending từ phiên trước **Khi hoàn thành công việc:**
1. remember(content="Đã tạo bảng người dùng với UUID...", tags=["ecommerce-api", "database", "auth"], agent="Backend Architect")
2. Lưu lại quyết định, các mục pending **Khi chuyển giao cho agent khác:**
1. remember(content="Điểm cuối API: ...", tags=["ecommerce-api", "handoff"], agent="Backend Architect", for="Frontend Developer") **Khi có lỗi:**
1. recall/search checkpoint gần nhất
2. rollback về trạng thái ổn định
Bạn có quyền truy cập vào các công cụ bộ nhớ MCP: remember, recall, search, rollback. Tuân thủ các quy tắc sau: **Khi bắt đầu một phiên:**
1. recall(query="ecommerce-api", agent="Backend Architect")
2. Xem lại các item pending từ phiên trước **Khi hoàn thành công việc:**
1. remember(content="Đã tạo bảng người dùng với UUID...", tags=["ecommerce-api", "database", "auth"], agent="Backend Architect")
2. Lưu lại quyết định, các mục pending **Khi chuyển giao cho agent khác:**
1. remember(content="Điểm cuối API: ...", tags=["ecommerce-api", "handoff"], agent="Backend Architect", for="Frontend Developer") **Khi có lỗi:**
1. recall/search checkpoint gần nhất
2. rollback về trạng thái ổn định
Bạn: "Kích hoạt chế độ Kiến trúc sư Backend. Thiết kế hệ thống người dùng cho API thương mại điện tử." [Tác nhân thiết kế, tạo lược đồ, triển khai xác thực] Tác nhân: "Hệ thống người dùng hoàn tất. Đang lưu bộ nhớ..."
→ remember("bảng người dùng với UUID, bcrypt, JWT + mã thông báo làm mới", tags: ["ecommerce-api", "auth", "database"]) [Kết thúc phiên] [Ngày hôm sau] Bạn: "Tiếp tục từ ngày hôm qua" Tác nhân: "Đang thu hồi ngữ cảnh..."
→ recall(query="ecommerce-api")
→ Trả về: "bảng người dùng với UUID, bcrypt, JWT + mã thông báo làm mới" Tác nhân: "Hôm qua tôi đã thiết kế bảng người dùng với UUID, bcrypt, JWT... Bước tiếp: lược đồ danh mục sản phẩm."
Bạn: "Kích hoạt chế độ Kiến trúc sư Backend. Thiết kế hệ thống người dùng cho API thương mại điện tử." [Tác nhân thiết kế, tạo lược đồ, triển khai xác thực] Tác nhân: "Hệ thống người dùng hoàn tất. Đang lưu bộ nhớ..."
→ remember("bảng người dùng với UUID, bcrypt, JWT + mã thông báo làm mới", tags: ["ecommerce-api", "auth", "database"]) [Kết thúc phiên] [Ngày hôm sau] Bạn: "Tiếp tục từ ngày hôm qua" Tác nhân: "Đang thu hồi ngữ cảnh..."
→ recall(query="ecommerce-api")
→ Trả về: "bảng người dùng với UUID, bcrypt, JWT + mã thông báo làm mới" Tác nhân: "Hôm qua tôi đã thiết kế bảng người dùng với UUID, bcrypt, JWT... Bước tiếp: lược đồ danh mục sản phẩm."
Bạn: "Kích hoạt chế độ Kiến trúc sư Backend. Thiết kế hệ thống người dùng cho API thương mại điện tử." [Tác nhân thiết kế, tạo lược đồ, triển khai xác thực] Tác nhân: "Hệ thống người dùng hoàn tất. Đang lưu bộ nhớ..."
→ remember("bảng người dùng với UUID, bcrypt, JWT + mã thông báo làm mới", tags: ["ecommerce-api", "auth", "database"]) [Kết thúc phiên] [Ngày hôm sau] Bạn: "Tiếp tục từ ngày hôm qua" Tác nhân: "Đang thu hồi ngữ cảnh..."
→ recall(query="ecommerce-api")
→ Trả về: "bảng người dùng với UUID, bcrypt, JWT + mã thông báo làm mới" Tác nhân: "Hôm qua tôi đã thiết kế bảng người dùng với UUID, bcrypt, JWT... Bước tiếp: lược đồ danh mục sản phẩm."
{ "mcpServers": { "memory": { "command": "node", "args": ["/absolute/path/to/memory-server.js"], "env": { "HOME": "/Users/your-username" } } }
}
{ "mcpServers": { "memory": { "command": "node", "args": ["/absolute/path/to/memory-server.js"], "env": { "HOME": "/Users/your-username" } } }
}
{ "mcpServers": { "memory": { "command": "node", "args": ["/absolute/path/to/memory-server.js"], "env": { "HOME": "/Users/your-username" } } }
}
remember "Bộ nhớ thử nghiệm cho dự án thương mại điện tử"
Thẻ: ["test", "ecommerce-api"]
remember "Bộ nhớ thử nghiệm cho dự án thương mại điện tử"
Thẻ: ["test", "ecommerce-api"]
remember "Bộ nhớ thử nghiệm cho dự án thương mại điện tử"
Thẻ: ["test", "ecommerce-api"]
recall "test"
recall "test"
recall "test"
{ "mcpServers": { "memory": { "command": "node", "args": ["/absolute/path/to/memory-server.js"] } }
}
{ "mcpServers": { "memory": { "command": "node", "args": ["/absolute/path/to/memory-server.js"] } }
}
{ "mcpServers": { "memory": { "command": "node", "args": ["/absolute/path/to/memory-server.js"] } }
}
@memory remember "Bắt đầu dự án API thương mại điện tử với PostgreSQL"
Thẻ: ["ecommerce-api", "setup"]
@memory remember "Bắt đầu dự án API thương mại điện tử với PostgreSQL"
Thẻ: ["ecommerce-api", "setup"]
@memory remember "Bắt đầu dự án API thương mại điện tử với PostgreSQL"
Thẻ: ["ecommerce-api", "setup"]
@memory recall query="ecommerce"
@memory recall query="ecommerce"
@memory recall query="ecommerce"
remember({ content: "Chọn PostgreSQL thay vì MySQL vì: (1) hỗ trợ JSONB, (2) tìm kiếm toàn văn tốt hơn, (3) hỗ trợ UUID gốc", tags: ["ecommerce-api", "database", "decision"], agent: "Backend Architect"
})
remember({ content: "Chọn PostgreSQL thay vì MySQL vì: (1) hỗ trợ JSONB, (2) tìm kiếm toàn văn tốt hơn, (3) hỗ trợ UUID gốc", tags: ["ecommerce-api", "database", "decision"], agent: "Backend Architect"
})
remember({ content: "Chọn PostgreSQL thay vì MySQL vì: (1) hỗ trợ JSONB, (2) tìm kiếm toàn văn tốt hơn, (3) hỗ trợ UUID gốc", tags: ["ecommerce-api", "database", "decision"], agent: "Backend Architect"
})
recall(query="quyết định PostgreSQL MySQL")
recall(query="quyết định PostgreSQL MySQL")
recall(query="quyết định PostgreSQL MySQL")
remember({ content: "Backend hoàn tất. Điểm cuối: POST /auth/login, ...", tags: ["ecommerce-api", "handoff", "backend-complete"], agent: "Backend Architect", for: "Frontend Developer"
})
remember({ content: "Backend hoàn tất. Điểm cuối: POST /auth/login, ...", tags: ["ecommerce-api", "handoff", "backend-complete"], agent: "Backend Architect", for: "Frontend Developer"
})
remember({ content: "Backend hoàn tất. Điểm cuối: POST /auth/login, ...", tags: ["ecommerce-api", "handoff", "backend-complete"], agent: "Backend Architect", for: "Frontend Developer"
})
recall(query="handoff", agent="Backend Architect")
recall(query="handoff", agent="Backend Architect")
recall(query="handoff", agent="Backend Architect")
remember({ content: "Phiên hoàn tất. Đã xong: bảng người dùng, điểm cuối xác thực, lược đồ sản phẩm. Phiên tiếp theo: hệ thống đặt hàng...", tags: ["ecommerce-api", "checkpoint", "session-1"], agent: "Backend Architect"
})
remember({ content: "Phiên hoàn tất. Đã xong: bảng người dùng, điểm cuối xác thực, lược đồ sản phẩm. Phiên tiếp theo: hệ thống đặt hàng...", tags: ["ecommerce-api", "checkpoint", "session-1"], agent: "Backend Architect"
})
remember({ content: "Phiên hoàn tất. Đã xong: bảng người dùng, điểm cuối xác thực, lược đồ sản phẩm. Phiên tiếp theo: hệ thống đặt hàng...", tags: ["ecommerce-api", "checkpoint", "session-1"], agent: "Backend Architect"
})
recall(query="checkpoint session-1")
recall(query="checkpoint session-1")
recall(query="checkpoint session-1")
remember({ content: "LỖI: Mã thông báo làm mới không hết hạn sau khi đăng xuất. Khắc phục: chuyển sang Redis với TTL.", tags: ["ecommerce-api", "bug", "auth"], agent: "Code Reviewer", severity: "high"
})
remember({ content: "LỖI: Mã thông báo làm mới không hết hạn sau khi đăng xuất. Khắc phục: chuyển sang Redis với TTL.", tags: ["ecommerce-api", "bug", "auth"], agent: "Code Reviewer", severity: "high"
})
remember({ content: "LỖI: Mã thông báo làm mới không hết hạn sau khi đăng xuất. Khắc phục: chuyển sang Redis với TTL.", tags: ["ecommerce-api", "bug", "auth"], agent: "Code Reviewer", severity: "high"
})
search(tags=["bug", "ecommerce-api"])
search(tags=["bug", "ecommerce-api"])
search(tags=["bug", "ecommerce-api"])
import crypto from 'crypto'; const ENCRYPTION_KEY = process.env.MEMORY_ENCRYPTION_KEY;
const ALGORITHM = 'aes-256-gcm'; function encrypt(text) { const iv = crypto.randomBytes(16); const cipher = crypto.createCipheriv(ALGORITHM, Buffer.from(ENCRYPTION_KEY), iv); const encrypted = cipher.update(text, 'utf8', 'hex'); return { encryptedData: encrypted + cipher.final('hex'), iv: iv.toString('hex'), authTag: cipher.getAuthTag().toString('hex') };
} function decrypt(encrypted) { const decipher = crypto.createDecipheriv( ALGORITHM, Buffer.from(ENCRYPTION_KEY), Buffer.from(encrypted.iv, 'hex') ); decipher.setAuthTag(Buffer.from(encrypted.authTag, 'hex')); return decipher.update(encrypted.encryptedData, 'hex', 'utf8') + decipher.final('utf8');
}
import crypto from 'crypto'; const ENCRYPTION_KEY = process.env.MEMORY_ENCRYPTION_KEY;
const ALGORITHM = 'aes-256-gcm'; function encrypt(text) { const iv = crypto.randomBytes(16); const cipher = crypto.createCipheriv(ALGORITHM, Buffer.from(ENCRYPTION_KEY), iv); const encrypted = cipher.update(text, 'utf8', 'hex'); return { encryptedData: encrypted + cipher.final('hex'), iv: iv.toString('hex'), authTag: cipher.getAuthTag().toString('hex') };
} function decrypt(encrypted) { const decipher = crypto.createDecipheriv( ALGORITHM, Buffer.from(ENCRYPTION_KEY), Buffer.from(encrypted.iv, 'hex') ); decipher.setAuthTag(Buffer.from(encrypted.authTag, 'hex')); return decipher.update(encrypted.encryptedData, 'hex', 'utf8') + decipher.final('utf8');
}
import crypto from 'crypto'; const ENCRYPTION_KEY = process.env.MEMORY_ENCRYPTION_KEY;
const ALGORITHM = 'aes-256-gcm'; function encrypt(text) { const iv = crypto.randomBytes(16); const cipher = crypto.createCipheriv(ALGORITHM, Buffer.from(ENCRYPTION_KEY), iv); const encrypted = cipher.update(text, 'utf8', 'hex'); return { encryptedData: encrypted + cipher.final('hex'), iv: iv.toString('hex'), authTag: cipher.getAuthTag().toString('hex') };
} function decrypt(encrypted) { const decipher = crypto.createDecipheriv( ALGORITHM, Buffer.from(ENCRYPTION_KEY), Buffer.from(encrypted.iv, 'hex') ); decipher.setAuthTag(Buffer.from(encrypted.authTag, 'hex')); return decipher.update(encrypted.encryptedData, 'hex', 'utf8') + decipher.final('utf8');
} - Kiểm tra file bộ nhớ (~/.mcp-memory/memories.json)
- Đảm bảo MCP server đang chạy
- Xác minh cấu hình MCP cho Claude Code/Cursor - Sử dụng thẻ chi tiết hơn
- Lọc theo tên agent
- Dùng cụm từ chính xác trong dấu ngoặc kép - Định kỳ lưu trữ bộ nhớ cũ
- Dùng rollback để dọn các dự án đã xong
- Thêm ngày hết hạn vào schema bộ nhớ - Thêm semantic search với embeddings
- Triển khai hết hạn bộ nhớ tự động (ví dụ: 30 ngày)
- Thêm tóm tắt bộ nhớ cho các phiên dài - Dùng chung một memory server cho cả team
- Gắn thẻ bộ nhớ theo dự án và developer
- Tạo quy trình onboarding cho thành viên mới - Tự động ghi nhật ký commit git thành memory
- Đồng bộ hóa với quản lý dự án (Jira, Linear)
- Xuất memory ra tài liệu - Đảm bảo MCP server chạy trước khi mở Claude Code
- Kiểm tra file: ls -la ~/.mcp-memory/memories.json
- Chỉnh quyền: chmod 644 ~/.mcp-memory/memories.json
- Kiểm tra cấu hình server trong ~/.claude/settings.json - Kiểm tra truy vấn đúng thẻ (có phân biệt chữ hoa/thường)
- Thử search rộng hơn hoặc search với thẻ cụ thể
- Kiểm tra file memory đã lưu: cat ~/.mcp-memory/memories.json
- Đảm bảo filter agent đúng (nếu có) - Tự động lưu trữ memory >30 ngày
- Thêm tool prune xóa theo ngày
- Chia nhỏ file theo project/ngày
- Dùng backend SQLite thay cho JSON nếu quy mô lớn - Kiểm tra Node.js: node --version (>=18)
- Cài đủ package: npm install @modelcontextprotocol/sdk zod
- Sửa lỗi syntax nếu có
- Chạy trực tiếp xem log: node memory-server.js - Luôn truyền trường agent khi remember
- Dùng thẻ đặc trưng cho từng project: ["project-x", "backend"]
- Lọc recall theo agent
- Cân nhắc file memory riêng cho từng project - Yêu cầu API key cho mỗi request
- Triển khai namespace memory cho từng user
- Ghi log mọi thao tác để audit
- Giới hạn tốc độ theo user