read_memory
Retrieve stored data from persistent memory using a specific key to access previously saved information.
Instructions
Read a value from persistent memory by key.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Key to retrieve |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"key": {
"description": "Key to retrieve",
"type": "string"
}
},
"required": [
"key"
],
"type": "object"
}
Implementation Reference
- src/tools/memory.ts:61-67 (handler)The handler function that implements the core logic of the 'read_memory' tool. It reads the persistent memory JSON file, retrieves the value by key, and returns it formatted as JSON or a 'not found' message.export async function readMemoryHandler(args: any) { await ensureMemoryFile(); const data = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8")); const item = data[args.key]; if (!item) return { content: [{ type: "text", text: "Key not found." }] }; return { content: [{ type: "text", text: JSON.stringify(item, null, 2) }] }; }
- src/tools/memory.ts:27-33 (schema)The Zod schema definition for the 'read_memory' tool, specifying the input parameters (key) and metadata.export const readMemorySchema = { name: "read_memory", description: "Read a value from persistent memory by key.", inputSchema: z.object({ key: z.string().describe("Key to retrieve") }) };
- src/index.ts:90-90 (registration)Registration of the 'read_memory' tool in the main stdio server's tool registry map, associating the schema and handler.["read_memory", { schema: readMemorySchema, handler: readMemoryHandler }],
- src/server.ts:99-99 (registration)Registration of the 'read_memory' tool in the HTTP server's tool registry map, associating the schema and handler.["read_memory", { schema: readMemorySchema, handler: readMemoryHandler }],
- src/tools/memory.ts:9-15 (helper)Helper function used by readMemoryHandler to ensure the memory file exists before reading.async function ensureMemoryFile() { try { await fs.access(MEMORY_FILE); } catch { await fs.writeFile(MEMORY_FILE, JSON.stringify({}, null, 2)); } }