Clear Conversations
clear_conversationsClear all conversation history to start fresh and reset the context for new queries.
Instructions
Clear all conversation history and start fresh
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/clear-conversations.ts:4-25 (handler)The main handler function for the clear_conversations tool. It calls conversationManager.clearAll() and returns a formatted result message.
export function clearConversationsTool( conversationManager: ConversationManager, _args: Record<string, unknown> ) { const result = conversationManager.clearAll(); logger.info(`User cleared ${result.conversationsCleared} conversations`); const message = result.conversationsCleared === 0 ? 'š§¹ No conversations to clear - memory is already empty!' : `š§¹ Cleared ${result.conversationsCleared} conversation${result.conversationsCleared === 1 ? '' : 's'} (${result.messagesCleared} message${result.messagesCleared === 1 ? '' : 's'})`; return { content: [ { type: 'text', text: `${message}\n\nš¦ All ducks now have a fresh start! Previous conversation context has been removed.`, }, ], }; } - src/services/conversation.ts:125-144 (helper)Helper method on ConversationManager that clears all conversations and returns counts of what was cleared.
clearAll(): { conversationsCleared: number; messagesCleared: number } { let totalMessages = 0; // Count total messages across all conversations for (const conversation of this.conversations.values()) { totalMessages += conversation.messages.length; } const conversationsCleared = this.conversations.size; this.conversations.clear(); logger.info( `Cleared ${conversationsCleared} conversations with ${totalMessages} total messages` ); return { conversationsCleared, messagesCleared: totalMessages, }; } - src/server.ts:319-338 (registration)Registration of the clear_conversations tool with the MCP server, including schema metadata and the handler wrapper.
// clear_conversations this.server.registerTool( 'clear_conversations', { title: 'Clear Conversations', description: 'Clear all conversation history and start fresh', annotations: { destructiveHint: true, idempotentHint: true, openWorldHint: false, }, }, () => { try { return this.toolResult(clearConversationsTool(this.conversationManager, {})); } catch (error) { return this.toolErrorResult(error); } } );