clear_session
Clear session data to free memory in the verifiable-thinking-mcp server. Remove specific or all sessions using session_id or all parameters.
Instructions
Clear session(s) to free memory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | No | Session ID to clear (omit for all) | |
| all | Yes | Clear all sessions |
Implementation Reference
- src/tools/sessions.ts:112-140 (handler)Main handler for clear_session tool. Exports clearSessionTool with name 'clear_session', description, zod schema for parameters (session_id optional, all boolean), and execute function that clears either a specific session or all sessions using SessionManager.clear/clearAll and clearTracker helpers.
export const clearSessionTool = { name: "clear_session", description: "Clear session(s) to free memory", parameters: z.object({ session_id: z.string().optional().describe("Session ID to clear (omit for all)"), all: z.boolean().default(false).describe("Clear all sessions"), }), execute: async (args: { session_id?: string; all?: boolean }) => { let result: string; if (args.all) { const count = SessionManager.clearAll(); result = `Cleared ${count} session(s).`; } else if (!args.session_id) { result = "Provide session_id or set all=true"; } else { // Also clear concept tracker for this session clearTracker(args.session_id); const cleared = SessionManager.clear(args.session_id); result = cleared ? `Cleared session: ${args.session_id}` : `Session not found: ${args.session_id}`; } const tokens = calculateTokenUsage(args, result); return `${result}\n\n---\n_tokens: ${tokens.input_tokens} in, ${tokens.output_tokens} out, ${tokens.total_tokens} total_`; }, }; - src/tools/sessions.ts:115-118 (schema)Zod schema defining input parameters for clear_session tool: session_id (optional string) and all (boolean default false).
parameters: z.object({ session_id: z.string().optional().describe("Session ID to clear (omit for all)"), all: z.boolean().default(false).describe("Clear all sessions"), }), - src/index.ts:24-24 (registration)Registers clearSessionTool with the FastMCP server using server.addTool(clearSessionTool).
server.addTool(clearSessionTool); - src/session/manager.ts:426-440 (helper)SessionManager.clear() and clearAll() methods used by clear_session tool to remove sessions from memory.
clear(sessionId: string): boolean { // Clear active session tracking if this is the active session if (this.activeSessionId === sessionId) { this.activeSessionId = null; } return this.sessions.delete(sessionId); } clearAll(): number { const count = this.sessions.size; this.sessions.clear(); // Also clear the active session tracking this.activeSessionId = null; return count; } - src/session/concepts.ts:109-111 (helper)clearTracker() helper function that removes the concept tracker for a specific session when clearing.
export function clearTracker(sessionId: string): void { trackers.delete(sessionId); }