conversation_history
Review previous conversations with AI models to understand context, check past responses, and continue discussions effectively. Automatically manages long conversations by shortening them.
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
| 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. |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"conversationId": {
"description": "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.",
"type": "string"
}
},
"required": [
"conversationId"
],
"type": "object"
}
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 the ConversationManager and returns a JSON string containing the conversationId, modelId, and messages.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)Registers the "conversation_history" MCP tool with title, description, input schema (requiring conversationId), and inline 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 tool handler.export interface ConversationHistoryResponse { conversationId: string; modelId: string; messages: ChatMessage[]; }
- src/conversation-manager.ts:62-69 (helper)Helper method in ConversationManager that retrieves the conversation messages and applies truncation if necessary.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:113-129 (helper)Private helper method that truncates long conversation histories by keeping first and last halves of messages and inserting a truncation marker.private truncateMessages(messages: ChatMessage[]): ChatMessage[] { if (messages.length <= this.truncateLimit) { return messages; } const kept = Math.floor(this.truncateLimit / 2); const first = messages.slice(0, kept); const last = messages.slice(-kept); // Add marker for truncated content const marker: ChatMessage = { role: "assistant", content: "[... conversation history truncated to save context ...]", }; return [...first, marker, ...last]; }