m9k_delete_session
Remove a session from the index to delete all associated chunks and search data while preserving the original source file.
Instructions
Delete a session from the index. Removes all chunks and search data. Does NOT delete the source JSONL file.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | The session ID to delete |
Implementation Reference
- src/tools/manage.ts:70-150 (handler)The tool m9k_delete_session is registered and implemented in src/tools/manage.ts using the server.registerTool function. The handler verifies the session existence, prevents the deletion of a reserved session, and then cleans up chunks and updates the session status in the database.
server.registerTool( 'm9k_delete_session', { description: 'Delete a session from the index. Removes all chunks and search data. Does NOT delete the source JSONL file.', inputSchema: { sessionId: z.string().describe('The session ID to delete'), }, annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false, }, }, async ({ sessionId }) => { // Guard: never delete the manual memories session if (sessionId === '__manual_memories__') { return { content: [ { type: 'text' as const, text: JSON.stringify({ error: 'Cannot delete __manual_memories__ session. Use m9k_save to manage manual memories.', }), }, ], isError: true, }; } // Check if session exists const session = ctx.db .prepare('SELECT id, project FROM conv_sessions WHERE id = ?') .get(sessionId) as { id: string; project: string } | undefined; if (!session) { return { content: [ { type: 'text' as const, text: JSON.stringify({ error: 'Session not found', sessionId }), }, ], isError: true, }; } // Count chunks before deletion const chunkCount = ( ctx.db .prepare('SELECT COUNT(*) AS cnt FROM conv_chunks WHERE session_id = ?') .get(sessionId) as { cnt: number; } ).cnt; // Soft delete: hard-delete chunks (clean search), tombstone session row ctx.db.prepare('DELETE FROM conv_chunks WHERE session_id = ?').run(sessionId); ctx.db .prepare( "UPDATE conv_sessions SET deleted_at = datetime('now'), chunk_count = 0 WHERE id = ?", ) .run(sessionId); return { content: [ { type: 'text' as const, text: JSON.stringify({ deleted: true, sessionId, project: session.project, chunksRemoved: chunkCount, }), }, ], }; }, );