Skip to main content
Glama

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
NameRequiredDescriptionDefault
stateYesLED状态(on/off)

Implementation Reference

  • 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}"
  • 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"
  • 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

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mcp2everything/mcp2mqtt'

If you have feedback or need assistance with the MCP directory API, please join our Discord server