led_control
Control LED states (on/off) via the mcp2mqtt server. Integrates with IoT devices for natural language commands and real-time AI responses, enabling smart lighting management.
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 implementation for the 'led_control' MCP tool within the call_tool dispatcher. Validates the input 'state' parameter to be either 'on' or 'off', constructs the MQTT message payload, and proceeds to send it to the configured MQTT topic.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}"
- tests/responder.py:131-136 (helper)Supporting mock MQTT responder used for testing. Handles incoming 'LED {state}' messages on the led_control topic and generates the expected response format 'CMD LED {state} OK' or ERROR.elif cmd_name == 'led_control': # 解析LED状态 state = payload.split()[-1].lower() if state in ['on', 'off']: return f"{response_start} LED {state} OK" return f"{response_start} LED ERROR"
- src/mcp2mqtt/server.py:215-242 (registration)Tool registration via MCP standard list_tools() method. Dynamically generates tool objects including 'led_control' from configuration, providing name, description, and inputSchema based on configured parameters (e.g., 'state' with enum ['on','off']).@server.list_tools() async def handle_list_tools() -> List[types.Tool]: """List available tools.""" tools = [] 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