Skip to main content
Glama

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
NameRequiredDescriptionDefault
conversationIdYesThe 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

  • 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}`, }, ], }; } }
  • 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}`, }, ], }; } } );
  • 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[]; }
  • 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); }
  • 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); }
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/danielwpz/polybrain-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server