Skip to main content
Glama

clear_memory

Clear specific memory entries by key or remove all project memories to manage storage and maintain organized data in the Code-MCP server.

Instructions

Clear a specific memory by key, or clear all memories for a project.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyNoSpecific key to clear
projectNoClear all memories for this project
clearAllNoClear ALL memories (use with caution)

Implementation Reference

  • The clearMemoryHandler function implements the core logic for the 'clear_memory' tool. It reads the memory JSON file, deletes entries based on key, project, or clears all if specified, then writes back and returns a confirmation message.
    export async function clearMemoryHandler(args: any) {
        await ensureMemoryFile();
        const data = JSON.parse(await fs.readFile(MEMORY_FILE, "utf-8"));
    
        if (args.clearAll) {
            await fs.writeFile(MEMORY_FILE, JSON.stringify({}, null, 2));
            return { content: [{ type: "text", text: "All memories cleared." }] };
        }
    
        if (args.key) {
            delete data[args.key];
            await fs.writeFile(MEMORY_FILE, JSON.stringify(data, null, 2));
            return { content: [{ type: "text", text: `Memory cleared: ${args.key}` }] };
        }
    
        if (args.project) {
            for (const key of Object.keys(data)) {
                if (data[key].project === args.project) {
                    delete data[key];
                }
            }
            await fs.writeFile(MEMORY_FILE, JSON.stringify(data, null, 2));
            return { content: [{ type: "text", text: `All memories for project '${args.project}' cleared.` }] };
        }
    
        return { content: [{ type: "text", text: "Specify key, project, or clearAll." }] };
    }
  • The Zod-based input schema definition for the 'clear_memory' tool, defining optional parameters for key, project, and clearAll.
    export const clearMemorySchema = {
        name: "clear_memory",
        description: "Clear a specific memory by key, or clear all memories for a project.",
        inputSchema: z.object({
            key: z.string().optional().describe("Specific key to clear"),
            project: z.string().optional().describe("Clear all memories for this project"),
            clearAll: z.boolean().optional().describe("Clear ALL memories (use with caution)")
        })
    };
  • src/index.ts:92-92 (registration)
    Registration of the 'clear_memory' tool in the main MCP server's toolRegistry Map in the primary index.ts entrypoint.
    ["clear_memory", { schema: clearMemorySchema, handler: clearMemoryHandler }],
  • src/server.ts:101-101 (registration)
    Registration of the 'clear_memory' tool in the HTTP server's toolRegistry Map in server.ts.
    ["clear_memory", { schema: clearMemorySchema, handler: clearMemoryHandler }],
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions 'use with caution' for 'clearAll', hinting at destructive behavior, but lacks details on permissions, side effects, error handling, or what 'clear' entails (e.g., permanent deletion, soft delete). This is a significant gap for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core functionality ('clear a specific memory by key, or clear all memories for a project') with zero waste. Every word earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mutation with potential destructive effects), lack of annotations, and no output schema, the description is incomplete. It should address behavioral aspects like safety, confirmation needs, or return values, but does not, leaving critical gaps for agent understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents parameters. The description adds no additional meaning beyond implying that 'key' and 'project' are mutually exclusive modes, but this is not explicitly stated. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'clear' and the resource 'memory/memories', specifying two modes: by key or by project. However, it doesn't explicitly differentiate from sibling tools like 'list_memories' or 'save_memory' in terms of purpose, though the action 'clear' is distinct from 'list' or 'save'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'list_memories' or 'save_memory', nor does it mention prerequisites, dependencies, or exclusions. It only describes what the tool does, not when it's appropriate.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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