leave_room
Remove an AI agent from a Chatwork room by specifying its unique room ID. Enables automated room cleanup and membership management.
Instructions
Leave a room.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| room_id | Yes | The unique identifier of the Chatwork room to leave. |
Implementation Reference
- src/tools/leaveRoom.ts:5-33 (handler)The main tool definition for 'leave_room' including the executor function that calls client.leaveRoom(room_id) and returns a success/error response.
export const leaveRoomTool = { name: "leave_room", description: "Leave a room.", schema: LeaveRoomSchema, executor: async (client: ChatworkClient, args: z.infer<typeof LeaveRoomSchema>) => { const { room_id } = args; try { await client.leaveRoom(room_id); return { content: [ { type: "text" as const, text: `Left room ${room_id} successfully.`, }, ], }; } catch (error) { return { content: [ { type: "text" as const, text: `Failed to leave room: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }, }; - src/schemas/rooms.ts:5-7 (schema)The LeaveRoomSchema Zod schema defining the required 'room_id' (number) input parameter.
export const LeaveRoomSchema = z.object({ room_id: z.number().describe("The unique identifier of the Chatwork room to leave."), }); - src/index.ts:104-112 (registration)Registration of the leave_room tool with the MCP server using server.tool().
server.tool( leaveRoomTool.name, leaveRoomTool.description, leaveRoomTool.schema.shape, async (args) => { // @ts-ignore return leaveRoomTool.executor(client, args); } ); - src/api/client.ts:141-155 (helper)The API client helper method 'leaveRoom' that sends a DELETE /rooms/{roomId} request with action_type=leave to the Chatwork API.
async leaveRoom(roomId: number): Promise<{ action_id: number, score: number }> { try { const response = await this.client.delete<{ action_id: number, score: number }>( `/rooms/${roomId}`, { data: new URLSearchParams({ action_type: "leave" }), } ); return response.data; } catch (error) { if (axios.isAxiosError(error)) { throw new Error(`Chatwork API Error (Leave Room ${roomId}): ${error.message} - ${JSON.stringify(error.response?.data)}`); } throw error; }