led_control
Control LED lights on IoT devices through MQTT by setting them to on or off states using natural language commands.
Instructions
控制LED开关
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| state | Yes | LED状态(on/off) |
Implementation Reference
- src/mcp2mqtt/server.py:293-300 (handler)Handler logic for the 'led_control' tool: validates the 'state' parameter to be 'on' or 'off', constructs the MQTT message 'LED {state}', and returns error if invalid.elif name == "led_control": state = arguments.get("state", "").lower() if state not in ["on", "off"]: return [types.TextContent( type="text", text="Error: State must be 'on' or 'off'" )] message = f"LED {state}"
- src/mcp2mqtt/server.py:219-242 (registration)Registers all tools including 'led_control' from config.tools, providing name, description, and dynamically constructed inputSchema based on tool parameters defined in config.yaml.for tool_name, tool_config in config.tools.items(): tools.append( types.Tool( name=tool_config.name, description=tool_config.description, inputSchema={ "type": "object", "properties": { param["name"]: { "type": param["type"], "description": param["description"], **({"enum": param["enum"]} if "enum" in param else {}) } for param in tool_config.parameters }, "required": [ param["name"] for param in tool_config.parameters if param.get("required", False) ] } ) ) return tools
- src/mcp2mqtt/server.py:224-242 (schema)Dynamically generates the input schema for 'led_control' (and other tools) from the parameters defined in the configuration file.inputSchema={ "type": "object", "properties": { param["name"]: { "type": param["type"], "description": param["description"], **({"enum": param["enum"]} if "enum" in param else {}) } for param in tool_config.parameters }, "required": [ param["name"] for param in tool_config.parameters if param.get("required", False) ] } ) ) return tools