conversation_history
Review previous conversations with AI models to understand context, check past responses, and prepare for continuing discussions.
Instructions
See what you've already discussed with a specific model. Useful for understanding context before continuing a conversation, reviewing advice you got, or checking previous responses. Long conversations are automatically shortened to save context.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| conversationId | Yes | The ID of the conversation you want to review. Get this from the response of the chat tool when you first talk to a model. |
Implementation Reference
- src/mcp-tools.ts:220-269 (handler)The handler function for the 'conversation_history' tool. It retrieves the conversation state and history using ConversationManager and returns them as a JSON string in the MCP response format.async ({ conversationId }) => { try { const conversation = conversationManager.getConversationState(conversationId); if (!conversation) { return { content: [ { type: "text" as const, text: `Error: Conversation not found: ${conversationId}`, }, ], }; } const history = conversationManager.getHistory(conversationId); logger.debug("Retrieved conversation history", { conversationId, messageCount: history.length, }); return { content: [ { type: "text" as const, text: JSON.stringify({ conversationId, modelId: conversation.modelId, messages: history, }), }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); logger.error( "Conversation history tool error", error instanceof Error ? error : new Error(errorMessage) ); return { content: [ { type: "text" as const, text: `Error: ${errorMessage}`, }, ], }; } }
- src/mcp-tools.ts:206-270 (registration)Registration of the 'conversation_history' tool on the MCP server, including title, description, input schema (Zod), and reference to the handler function.server.registerTool( "conversation_history", { title: "Review Your Conversation with Another Model", description: "See what you've already discussed with a specific model. Useful for understanding context before continuing a conversation, reviewing advice you got, or checking previous responses. Long conversations are automatically shortened to save context.", inputSchema: z.object({ conversationId: z .string() .describe( "The ID of the conversation you want to review. Get this from the response of the chat tool when you first talk to a model." ), }), }, async ({ conversationId }) => { try { const conversation = conversationManager.getConversationState(conversationId); if (!conversation) { return { content: [ { type: "text" as const, text: `Error: Conversation not found: ${conversationId}`, }, ], }; } const history = conversationManager.getHistory(conversationId); logger.debug("Retrieved conversation history", { conversationId, messageCount: history.length, }); return { content: [ { type: "text" as const, text: JSON.stringify({ conversationId, modelId: conversation.modelId, messages: history, }), }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); logger.error( "Conversation history tool error", error instanceof Error ? error : new Error(errorMessage) ); return { content: [ { type: "text" as const, text: `Error: ${errorMessage}`, }, ], }; } } );
- src/types.ts:47-51 (schema)TypeScript interface defining the structure of the conversation history response, matching the JSON returned by the handler.export interface ConversationHistoryResponse { conversationId: string; modelId: string; messages: ChatMessage[]; }
- src/conversation-manager.ts:62-69 (helper)Helper method in ConversationManager that retrieves and truncates the message history for a given conversation ID. Used by the tool handler.getHistory(conversationId: string): ChatMessage[] { const conversation = this.conversations.get(conversationId); if (!conversation) { throw new Error(`Conversation not found: ${conversationId}`); } return this.truncateMessages(conversation.messages); }
- src/conversation-manager.ts:105-107 (helper)Helper method in ConversationManager that gets the full conversation state (including modelId) for a given conversation ID. Used by the tool handler.getConversationState(conversationId: string): ConversationState | null { return this.getConversation(conversationId); }