memory_search
Search through stored memory files by substring to retrieve specific facts without loading entire memory. Quickly recall relevant information from agent memory.
Instructions
Search memory files for a substring. Use this to recall specific facts without loading everything.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes |
Implementation Reference
- src/index.ts:47-60 (handler)The searchMemory function that executes the tool logic: reads all .md files from the memory directory, searches for the query substring case-insensitively, and returns matching lines as markdown snippets.
async function searchMemory(query: string): Promise<string> { if (!existsSync(MEMORY_DIR)) return '(memory directory does not exist)'; const q = query.toLowerCase(); const files = (await readdir(MEMORY_DIR)).filter((f) => f.endsWith('.md')); const hits: string[] = []; for (const file of files) { const content = await readFile(join(MEMORY_DIR, file), 'utf-8'); if (content.toLowerCase().includes(q)) { const snippet = content.split('\n').filter((l) => l.toLowerCase().includes(q)).slice(0, 3).join('\n'); hits.push(`## ${file}\n${snippet}`); } } return hits.join('\n\n') || `(no matches for "${query}")`; } - src/index.ts:118-122 (handler)The CallTool request handler that dispatches 'memory_search' to the searchMemory function with the query argument.
if (name === 'memory_search') { const query = String(args?.query ?? ''); if (!query.trim()) throw new Error('query is required'); return { content: [{ type: 'text', text: await searchMemory(query) }] }; } - src/index.ts:91-99 (schema)Tool registration with inputSchema definition for memory_search: requires a single string property 'query'.
{ name: 'memory_search', description: 'Search memory files for a substring. Use this to recall specific facts without loading everything.', inputSchema: { type: 'object', properties: { query: { type: 'string' } }, required: ['query'], }, }, - src/index.ts:67-100 (registration)ListTools handler that registers memory_search among the available tools (name, description, inputSchema).
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: 'memory_read', description: 'Read the agent memory index (MEMORY.md) and optionally specific topic files. Call with no arguments to load only the lightweight index (cheap). Pass `topics` only when you need the full content of a specific topic file.', inputSchema: { type: 'object', properties: { topics: { type: 'array', items: { type: 'string' }, description: 'Optional topic file names to load in full (e.g., ["preferences", "projects"]). Omit to return the index only.' }, }, }, }, { name: 'memory_append_session', description: 'Append a session summary to the sessions directory. The daemon will later extract durable memories from it. Call this at the end of meaningful exchanges. Keep summaries focused on durable findings and decisions (target 300-800 tokens), not play-by-play — longer summaries cost more during consolidation.', inputSchema: { type: 'object', properties: { content: { type: 'string', description: 'Markdown-formatted session summary. Use structured headers and bullets for better extraction; avoid verbose prose.' }, source: { type: 'string', description: 'Origin tag, e.g., "kiro", "claude-desktop"' }, }, required: ['content'], }, }, { name: 'memory_search', description: 'Search memory files for a substring. Use this to recall specific facts without loading everything.', inputSchema: { type: 'object', properties: { query: { type: 'string' } }, required: ['query'], }, }, ],