control_device
Control SwitchBot smart devices by sending commands like turnOn or turnOff to manage home automation through the MCP server.
Instructions
デバイスを制御します
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deviceId | Yes | デバイスID | |
| command | Yes | コマンド(turnOn, turnOff) |
Implementation Reference
- src/index.ts:170-196 (handler)Handler for the 'control_device' tool. Validates deviceId and command arguments, issues a POST request to the SwitchBot API endpoint `/devices/${deviceId}/commands` with the specified command, and returns the JSON response.case 'control_device': { const args = request.params.arguments; if (!args || typeof args.deviceId !== 'string' || typeof args.command !== 'string') { throw new McpError( ErrorCode.InvalidParams, 'デバイスIDとコマンドが必要です' ); } const response = await this.axiosInstance.post( `/devices/${args.deviceId}/commands`, { command: args.command, parameter: 'default', commandType: 'command', } ); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; }
- src/index.ts:110-128 (registration)Registration of the 'control_device' tool in the server's tools list, including name, description, and input schema definition.{ name: 'control_device', description: 'デバイスを制御します', inputSchema: { type: 'object', properties: { deviceId: { type: 'string', description: 'デバイスID', }, command: { type: 'string', description: 'コマンド(turnOn, turnOff)', enum: ['turnOn', 'turnOff'], }, }, required: ['deviceId', 'command'], }, },
- src/index.ts:113-127 (schema)Input schema for the 'control_device' tool, defining required deviceId (string) and command (string enum: turnOn/turnOff).inputSchema: { type: 'object', properties: { deviceId: { type: 'string', description: 'デバイスID', }, command: { type: 'string', description: 'コマンド(turnOn, turnOff)', enum: ['turnOn', 'turnOff'], }, }, required: ['deviceId', 'command'], },