control_lights
Manage robot lighting by turning lights on or off using the robot's IP address. Integrates with the Opentrons MCP Server for direct control of Opentrons Flex and OT-2 robots.
Instructions
Turn robot lights on or off
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| on | Yes | True to turn lights on, false to turn off | |
| robot_ip | Yes | Robot IP address |
Implementation Reference
- index.js:1982-2013 (handler)The handler function that implements the 'control_lights' tool logic. It makes a POST request to the Opentrons robot's /robot/lights API endpoint with the 'on' boolean parameter to turn the robot lights on or off.async controlLights(args) { const { robot_ip, on } = args; try { const body = { on }; const data = await this.makeApiRequest( 'POST', `http://${robot_ip}:31950/robot/lights`, { 'Content-Type': 'application/json' }, JSON.stringify(body) ); return { content: [ { type: "text", text: `✅ Lights turned ${on ? 'ON' : 'OFF'} successfully!` } ] }; } catch (error) { return { content: [ { type: "text", text: `❌ Failed to control lights: ${error.message}` } ] }; } }
- index.js:199-209 (registration)Tool registration in the ListToolsRequestSchema handler. Defines the tool name, description, and input schema for discovery by MCP clients.name: "control_lights", description: "Turn robot lights on or off", inputSchema: { type: "object", properties: { robot_ip: { type: "string", description: "Robot IP address" }, on: { type: "boolean", description: "True to turn lights on, false to turn off" } }, required: ["robot_ip", "on"] } },
- index.js:264-265 (registration)Handler dispatch in the CallToolRequestSchema switch statement that routes 'control_lights' calls to the controlLights method.case "control_lights": return this.controlLights(args);
- index.js:1476-1504 (helper)Generic helper method for making authenticated HTTP requests to the Opentrons robot API, used by the control_lights handler.async makeApiRequest(method, url, headers = {}, body = null) { try { const options = { method, headers: { 'Opentrons-Version': '*', ...headers } }; if (body) { options.body = body; } const response = await fetch(url, options); const data = await response.json(); if (!response.ok) { throw new Error(`API Error ${response.status}: ${data.message || JSON.stringify(data)}`); } return data; } catch (error) { if (error.code === 'ECONNREFUSED') { throw new Error(`Cannot connect to robot. Please check the IP address and ensure the robot is powered on.`); } throw error; } }
- index.js:484-494 (schema)Schema definition of the underlying Opentrons API endpoint POST /robot/lights that the tool calls, stored in the endpoints data structure.method: "POST", path: "/robot/lights", summary: "Control lights", description: "Turn rail lights on or off", tags: ["Control"], requestBody: { required: true, properties: { on: { type: "boolean", description: "True to turn lights on, false to turn off" } } }