chaingpt_get_chat_history
Retrieve chat history for a specific chat blob ID. Supports pagination with limit and offset, and sorting by creation date in ascending or descending order. Access history entries linked to your API key or a particular session.
Instructions
Get the chat history for a given chat blob id until the limit is reached retrieve saved chat history. By default, this will retrieve history entries associated with your API key. If you provide a specific sdkUniqueId, it will retrieve history entries associated with that chat blob id.
Args:
sdkUniqueId (str): The unique identifier for the chat.
limit (int, optional): The maximum number of chat history items to return. Default is 10.
offset (int, optional): The offset to start the chat history from. Default is 0.
sortBy (str, optional): The field to sort the chat history by. Default is 'createdAt'.
sortOrder (str, optional): The order to sort the chat history by. Default is 'ASC'.
Returns:
The chat history for the given chat blob id until the limit is reached.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sdkUniqueId | Yes | The unique id of the chat blob to get the history for. If not provided, it will return the chat history for all chat blobs until the limit is reached. | |
| limit | Yes | The maximum number of chat history items to return. Default is 10. | |
| offset | Yes | The offset to start the chat history from. Default is 0. | |
| sortBy | Yes | The field to sort the chat history by. Default is 'createdAt'. | |
| sortOrder | Yes | The order to sort the chat history by. Default is 'ASC'. |
Implementation Reference
- src/tools/chat.ts:70-120 (registration)Registration of the 'chaingpt_get_chat_history' tool on the MCP server, with its description and schema binding.
server.tool( "chaingpt_get_chat_history", `Get the chat history for a given chat blob id until the limit is reached retrieve saved chat history. By default, this will retrieve history entries associated with your API key. If you provide a specific sdkUniqueId, it will retrieve history entries associated with that chat blob id. Args: sdkUniqueId (str): The unique identifier for the chat. limit (int, optional): The maximum number of chat history items to return. Default is 10. offset (int, optional): The offset to start the chat history from. Default is 0. sortBy (str, optional): The field to sort the chat history by. Default is 'createdAt'. sortOrder (str, optional): The order to sort the chat history by. Default is 'ASC'. Returns: The chat history for the given chat blob id until the limit is reached. `, chatHistorySchema, async (params) => { try { const response = await generalchat.getChatHistory({ limit: params.limit, offset: params.offset, sortBy: params.sortBy, sortOrder: params.sortOrder, sdkUniqueId: params.sdkUniqueId, }); return { content: [ { type: "text", text: response.data.chatHistory, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : "get_chat_history_Unknown_Error"; return { content: [ { type: "text", text: errorMessage, }, ], isError: true, }; } } ); - src/tools/chat.ts:86-119 (handler)Handler function that executes the tool logic: calls generalchat.getChatHistory() with parameters and returns the chat history response.
async (params) => { try { const response = await generalchat.getChatHistory({ limit: params.limit, offset: params.offset, sortBy: params.sortBy, sortOrder: params.sortOrder, sdkUniqueId: params.sdkUniqueId, }); return { content: [ { type: "text", text: response.data.chatHistory, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : "get_chat_history_Unknown_Error"; return { content: [ { type: "text", text: errorMessage, }, ], isError: true, }; } } - src/types/schema.ts:8-14 (schema)Input schema (chatHistorySchema) defining the validation for sdkUniqueId, limit, offset, sortBy, and sortOrder parameters using Zod.
export const chatHistorySchema = { sdkUniqueId: z.string().describe("The unique id of the chat blob to get the history for. If not provided, it will return the chat history for all chat blobs until the limit is reached."), limit: z.number().describe("The maximum number of chat history items to return. Default is 10."), offset: z.number().describe("The offset to start the chat history from. Default is 0."), sortBy: z.string().describe("The field to sort the chat history by. Default is 'createdAt'."), sortOrder: z.string().describe("The order to sort the chat history by. Default is 'ASC'."), } - src/tools/index.ts:4-7 (registration)registerTools() calls registerChatTools(), which registers the tool on the server.
export const registerTools = () => { registerChatTools(); registerNewsTools(); } - src/index.ts:10-16 (registration)MCP server creation (name 'chaingpt-mcp') where tools are registered.
export const server = new McpServer({ name: 'chaingpt-mcp', version: '0.1.0', }); // Load the capabilities registerTools();