memory_read
Retrieve the agent memory index for a lightweight overview, or load full content of specific topic files for detailed information.
Instructions
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.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| topics | No | Optional topic file names to load in full (e.g., ["preferences", "projects"]). Omit to return the index only. |
Implementation Reference
- src/index.ts:106-111 (handler)Handler for the memory_read tool. Reads the memory index (MEMORY.md) and optionally specified topic files, returning their content as text.
if (name === 'memory_read') { const topics = (args?.topics as string[] | undefined) ?? []; const index = await readIndex(); const topicContent = topics.length > 0 ? `\n\n---\n\n${await readTopics(topics)}` : ''; return { content: [{ type: 'text', text: index + topicContent }] }; } - src/index.ts:17-21 (helper)Helper that reads the MEMORY.md index file from the memory directory.
async function readIndex(): Promise<string> { const indexPath = join(MEMORY_DIR, 'MEMORY.md'); if (!existsSync(indexPath)) return '(no memories yet)'; return readFile(indexPath, 'utf-8'); } - src/index.ts:23-34 (helper)Helper that reads one or more topic .md files from the memory directory, sanitizing file names for security.
async function readTopics(topics: string[]): Promise<string> { const parts: string[] = []; for (const topic of topics) { const safe = topic.replace(/[^a-zA-Z0-9_.-]/g, ''); if (!safe) continue; const path = join(MEMORY_DIR, safe.endsWith('.md') ? safe : `${safe}.md`); if (existsSync(path)) { parts.push(`# ${safe}\n\n${await readFile(path, 'utf-8')}`); } } return parts.join('\n\n---\n\n') || '(no matching topic files)'; } - src/index.ts:70-78 (registration)Registration of the memory_read tool in the ListTools handler, including its name, description, and input schema.
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.' }, }, }, },