send_message
Deliver a text message to a designated Chatwork room. Provide the room ID and message content to post updates, notifications, or replies directly.
Instructions
Allows the agent to send messages to a room.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| room_id | Yes | The unique identifier of the Chatwork room. | |
| body | Yes | The message content to send. |
Implementation Reference
- src/tools/sendMessage.ts:5-20 (handler)The tool executor/handler that calls client.sendMessage and formats the response as MCP content.
export const sendMessageTool = { name: "send_message", description: "Allows the agent to send messages to a room.", schema: SendMessageSchema, executor: async (client: ChatworkClient, args: z.infer<typeof SendMessageSchema>) => { const result = await client.sendMessage(args.room_id, args.body); return { content: [ { type: "text" as const, text: JSON.stringify(result, null, 2), }, ], }; }, }; - src/schemas/messages.ts:8-11 (schema)Zod schema defining input validation for send_message tool: room_id (number) and body (string).
export const SendMessageSchema = z.object({ room_id: z.number().describe("The unique identifier of the Chatwork room."), body: z.string().describe("The message content to send."), }); - src/index.ts:44-52 (registration)Registration of the send_message tool with the MCP server, linking name, description, schema, and executor.
server.tool( sendMessageTool.name, sendMessageTool.description, sendMessageTool.schema.shape, async (args) => { // @ts-ignore return sendMessageTool.executor(client, args); } ); - src/api/client.ts:47-60 (helper)Helper method in ChatworkClient that sends the actual HTTP POST request to Chatwork API to send a message.
async sendMessage(roomId: number, body: string): Promise<{ message_id: string }> { try { const response = await this.client.post<{ message_id: string }>( `/rooms/${roomId}/messages`, new URLSearchParams({ body }) ); return response.data; } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`Chatwork API Error (Send Message Room ${roomId}): ${error.message} - ${JSON.stringify(error.response?.data)}`); } throw error; } } - src/tools/index.ts:3-3 (registration)Re-exports the sendMessageTool from the tools barrel module so it can be imported by index.ts.
export * from "./sendMessage.js";