restore_session_context
Restores previous session context by recovering essential details, decisions, code snippets, or debugging information from a specified session ID.
Instructions
restore|revert|go back|recover session - Restore previous session context
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | Session ID to restore | |
| restoreLevel | No | Level of detail to restore | |
| filterType | No | Filter context by type |
Implementation Reference
- The handler function that executes the restore_session_context tool. It uses MemoryManager to list, filter, and limit context memories by sessionId, restoreLevel, and filterType, then returns a formatted text response.export async function restoreSessionContext(args: { sessionId: string; restoreLevel?: string; filterType?: string }): Promise<ToolResult> { const { sessionId, restoreLevel = 'detailed', filterType = 'all' } = args; try { const memoryManager = MemoryManager.getInstance(); // Get all context memories let memories = memoryManager.list('context'); // Filter by session ID memories = memories.filter(m => m.key.includes(sessionId)); // Filter by context type if not 'all' if (filterType !== 'all') { memories = memories.filter(m => { try { const contextData = JSON.parse(m.value); return contextData.contextType === filterType; } catch { return false; } }); } const maxItems = restoreLevel === 'essential' ? 3 : restoreLevel === 'detailed' ? 10 : 20; const limitedMemories = memories.slice(0, maxItems); if (limitedMemories.length === 0) { return { content: [{ type: 'text', text: `✗ No context found for session: ${sessionId}` }] }; } let response = `✓ Restored ${limitedMemories.length} context item(s) for session: ${sessionId}\n`; limitedMemories.forEach(m => { try { const data = JSON.parse(m.value); response += `\n• ${data.contextType || 'context'} (${data.urgency || 'medium'})`; if (data.summary) response += `: ${data.summary}`; response += `\n Time: ${new Date(m.timestamp).toLocaleString()}`; } catch { response += `\n• ${m.key}\n Time: ${new Date(m.timestamp).toLocaleString()}`; } }); return { content: [{ type: 'text', text: response }] }; } catch (error) { return { content: [{ type: 'text', text: `✗ Error: ${error instanceof Error ? error.message : 'Unknown error'}` }] }; } }
- The ToolDefinition schema defining input parameters (sessionId required, optional restoreLevel and filterType) and metadata for the restore_session_context tool.export const restoreSessionContextDefinition: ToolDefinition = { name: 'restore_session_context', description: 'restore|revert|go back|recover session - Restore previous session context', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Session ID to restore' }, restoreLevel: { type: 'string', description: 'Level of detail to restore', enum: ['essential', 'detailed', 'complete'] }, filterType: { type: 'string', description: 'Filter context by type', enum: ['all', 'progress', 'decisions', 'code-snippets', 'debugging', 'planning'] } }, required: ['sessionId'] }, annotations: { title: 'Restore Session', audience: ['user', 'assistant'] } };
- src/index.ts:132-132 (registration)Registration of the tool definition in the central tools array used for listing tools.restoreSessionContextDefinition,
- src/index.ts:650-651 (registration)Dispatch case in the executeToolCall switch statement that routes calls to the restoreSessionContext handler.case 'restore_session_context': return await restoreSessionContext(args as any) as CallToolResult;
- src/index.ts:64-64 (registration)Import statement bringing in the handler and definition for use in the main server.import { restoreSessionContext, restoreSessionContextDefinition } from './tools/memory/restoreSessionContext.js';