list_memories
List all stored memories in a project with stats on namespace, type, key, and priority. Use this to review and understand what knowledge is stored.
Instructions
List all stored memories for the current project with stats. Shows namespace, type, key, priority. Useful for understanding what knowledge is stored.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespace | No | Filter by namespace | |
| projectId | No | Project ID (defaults to current project) |
Implementation Reference
- server/src/mcp/tools.js:522-564 (handler)The tool handler for 'list_memories' — registers with server.tool(), receives optional namespace and projectId params, calls memoryService.list() and memoryService.getStats(), returns JSON with stats and memories (mapped to namespace, type, key, priority, confidence, updatedAt, expires).
// ─── list_memories ────────────────────────────────────────────── server.tool( 'list_memories', 'List all stored memories for the current project with stats. Shows namespace, type, key, priority. Useful for understanding what knowledge is stored.', { namespace: z.string().optional().describe('Filter by namespace'), projectId: z.string().optional().describe('Project ID (defaults to current project)'), }, async ({ namespace, projectId }) => { try { const { memoryService, currentProjectId } = await getServices() const targetProjectId = projectId || currentProjectId const [memories, stats] = await Promise.all([ memoryService.list({ projectId: targetProjectId, namespace }), memoryService.getStats(targetProjectId), ]) return { content: [{ type: 'text', text: JSON.stringify({ projectId: targetProjectId, stats, memories: memories.map(m => ({ namespace: m.namespace, type: m.memory_type, key: m.key, priority: m.priority, confidence: m.confidence, updatedAt: m.updated_at, expires: m.expires_at, })), }, null, 2), }], } } catch (error) { return { content: [{ type: 'text', text: `Error listing memories: ${error.message}` }], isError: true, } } } - server/src/mcp/tools.js:526-529 (schema)Input schema for list_memories using Zod: namespace (optional string) and projectId (optional string).
{ namespace: z.string().optional().describe('Filter by namespace'), projectId: z.string().optional().describe('Project ID (defaults to current project)'), }, - The MemoryService.list() method — queries the project_memories table filtering by projectId and optional namespace, only returns non-expired rows, ordered by namespace, priority DESC, updated_at DESC.
async list({ projectId, namespace }) { let sql = ` SELECT namespace, memory_type, key, priority, confidence, updated_at, expires_at FROM project_memories WHERE project_id = ? AND (expires_at IS NULL OR expires_at > datetime('now')) ` const params = [projectId] if (namespace) { sql += ' AND namespace = ?' params.push(namespace) } sql += ' ORDER BY namespace, priority DESC, updated_at DESC' return this.searchDb.db.all(sql, params) } - The MemoryService.getStats() method — returns total count and count by namespace for a given projectId (excluding expired memories).
async getStats(projectId) { const total = await this.searchDb.db.get( 'SELECT COUNT(*) as count FROM project_memories WHERE project_id = ?', [projectId] ) const byNamespace = await this.searchDb.db.all(` SELECT namespace, COUNT(*) as count FROM project_memories WHERE project_id = ? AND (expires_at IS NULL OR expires_at > datetime('now')) GROUP BY namespace `, [projectId]) return { total: total?.count || 0, byNamespace: Object.fromEntries(byNamespace.map(r => [r.namespace, r.count])), } } - server/src/mcp/index.js:106-108 (registration)Registration call: registerTools(server, getServices) connects the tools module to the MCP server, executed at server startup.
registerTools(server, getServices) registerResources(server, getServices) registerPrompts(server)