list_messages
Retrieve the list of messages from a specified Chatwork room. Optionally force retrieval of the latest 100 messages regardless of read status.
Instructions
Retrieves the list of messages for a specified room.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| room_id | Yes | The unique identifier of the Chatwork room. | |
| force | No | If true, retrieves the latest 100 messages regardless of read status. |
Implementation Reference
- src/tools/listMessages.ts:5-20 (handler)The `listMessagesTool` object defining the tool executor. It calls `client.listMessages(args.room_id, args.force)` and returns the messages as a JSON string.
export const listMessagesTool = { name: "list_messages", description: "Retrieves the list of messages for a specified room.", schema: ListMessagesSchema, executor: async (client: ChatworkClient, args: z.infer<typeof ListMessagesSchema>) => { const messages = await client.listMessages(args.room_id, args.force); return { content: [ { type: "text" as const, text: JSON.stringify(messages, null, 2), }, ], }; }, }; - src/schemas/messages.ts:3-6 (schema)The `ListMessagesSchema` Zod schema defining inputs: `room_id` (number, required) and `force` (boolean, optional, defaults to false).
export const ListMessagesSchema = z.object({ room_id: z.number().describe("The unique identifier of the Chatwork room."), force: z.boolean().optional().default(false).describe("If true, retrieves the latest 100 messages regardless of read status."), }); - src/index.ts:34-42 (registration)Registration of the `list_messages` tool with the MCP server via `server.tool()` using the tool's name, description, schema shape, and executor wrapper.
server.tool( listMessagesTool.name, listMessagesTool.description, listMessagesTool.schema.shape, async (args) => { // @ts-ignore return listMessagesTool.executor(client, args); } ); - src/tools/index.ts:2-2 (registration)Re-export of `listMessagesTool` from the tools barrel module.
export * from "./listMessages.js"; - src/api/client.ts:30-45 (helper)The `ChatworkClient.listMessages()` API helper that makes the GET request to `/rooms/{roomId}/messages` with an optional `force` parameter.
async listMessages(roomId: number, force: boolean = false): Promise<ChatworkMessage[]> { try { const response = await this.client.get<ChatworkMessage[]>( `/rooms/${roomId}/messages`, { params: { force: force ? 1 : 0 }, } ); return response.data; } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`Chatwork API Error (Room ${roomId}): ${error.message} - ${JSON.stringify(error.response?.data)}`); } throw error; } }