cache_clear
Clear all cached entries or specific namespaces to free memory and ensure data freshness in MCP workflows.
Instructions
Clear all entries from the cache or a specific namespace
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespace | No | Clear only this namespace, or all if not specified |
Implementation Reference
- src/index.ts:341-354 (handler)Handler implementation for the cache_clear tool. Clears the entire cache using cache.clear() and returns the number of entries cleared before clearing.case "cache_clear": { const size = cache.size; cache.clear(); return { content: [{ type: "text", text: JSON.stringify({ success: true, cleared_entries: size }) }] }; }
- src/index-v2.ts:482-519 (handler)Enhanced handler for cache_clear tool supporting optional namespace clearing. Iterates and deletes keys with matching prefix if namespace provided, otherwise clears all. Returns count of cleared entries.case "cache_clear": { const { namespace } = args as any; if (namespace) { let cleared = 0; const prefix = `${namespace}:`; for (const key of cache.keys()) { if (key.startsWith(prefix)) { cache.delete(key); cleared++; } } return { content: [{ type: "text", text: JSON.stringify({ success: true, namespace, cleared_entries: cleared }) }] }; } else { const size = cache.size; cache.clear(); return { content: [{ type: "text", text: JSON.stringify({ success: true, cleared_entries: size }) }] }; } }
- src/index.ts:136-143 (registration)Tool registration in the tools list, including name, description, and empty input schema.{ name: "cache_clear", description: "Clear all entries from the cache", inputSchema: { type: "object", properties: {} } },
- src/index-v2.ts:163-175 (registration)Tool registration for v2 with support for namespace parameter in input schema.{ name: "cache_clear", description: "Clear all entries from the cache or a specific namespace", inputSchema: { type: "object", properties: { namespace: { type: "string", description: "Clear only this namespace, or all if not specified" } } } },
- src/index.ts:18-18 (helper)Cache storage Map used by cache_clear and other cache tools. Defined identically in index-v2.ts.const cache = new Map<string, CacheEntry>();