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
| Name | Required | Description | Default |
|---|---|---|---|
| key | No | Specific key to clear | |
| project | No | Clear all memories for this project | |
| clearAll | No | Clear ALL memories (use with caution) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"clearAll": {
"description": "Clear ALL memories (use with caution)",
"type": "boolean"
},
"key": {
"description": "Specific key to clear",
"type": "string"
},
"project": {
"description": "Clear all memories for this project",
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/tools/memory.ts:90-116 (handler)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." }] }; }
- src/tools/memory.ts:43-51 (schema)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 }],