list_chats
Retrieve and manage chat data from Zendesk Chat API. Use pagination parameters to fetch specific chat pages and control the number of chats per page, up to a maximum of 100.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Page number for pagination | |
| per_page | No | Number of chats per page (max 100) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"page": {
"description": "Page number for pagination",
"type": "number"
},
"per_page": {
"description": "Number of chats per page (max 100)",
"type": "number"
}
},
"type": "object"
}
Implementation Reference
- src/tools/chat.js:12-27 (handler)The main handler function for the 'list_chats' tool. It accepts optional page and per_page parameters, calls zendeskClient.listChats, stringifies the result as JSON, and returns it in the expected content format, handling errors appropriately.handler: async ({ page, per_page }) => { try { const params = { page, per_page }; const result = await zendeskClient.listChats(params); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error listing chats: ${error.message}` }], isError: true }; }
- src/tools/chat.js:8-11 (schema)Input schema for the list_chats tool, defining optional numeric parameters for pagination using Zod validation.schema: { page: z.number().optional().describe("Page number for pagination"), per_page: z.number().optional().describe("Number of chats per page (max 100)") },
- src/tools/chat.js:4-30 (registration)Definition and export of the chatTools array containing the complete 'list_chats' tool configuration (name, description, schema, handler), which is later imported and registered.export const chatTools = [ { name: "list_chats", description: "List Zendesk Chat conversations", schema: { page: z.number().optional().describe("Page number for pagination"), per_page: z.number().optional().describe("Number of chats per page (max 100)") }, handler: async ({ page, per_page }) => { try { const params = { page, per_page }; const result = await zendeskClient.listChats(params); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error listing chats: ${error.message}` }], isError: true }; } } } ];
- src/zendesk-client.js:287-289 (helper)Supporting method in the ZendeskClient class that performs the actual API request to list chats using the /chats.json endpoint with provided parameters.async listChats(params) { return this.request("GET", "/chats.json", null, params); }
- src/server.js:48-52 (registration)Final registration of the 'list_chats' tool (included in allTools via ...chatTools) on the MCP server using server.tool(), passing name, schema, handler, and description.allTools.forEach((tool) => { server.tool(tool.name, tool.schema, tool.handler, { description: tool.description, }); });