Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
keyYesKey to retrieve

Implementation Reference

  • 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) }] };
    }
  • 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 }],
  • 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));
        }
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/millsydotdev/Code-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server