How yasu89/switch-bot-mcp-server works
Project type and purpose
• This is a standalone microservice (Model Context Protocol or MCP server) written in Go.
• It exposes a set of “tools” over MCP so that an MCP-aware client (e.g., Claude Desktop) can drive SwitchBot devices interactively.
File structure
• Top level:
• cmd/switch-bot-mcp-server/main.go → entry point for the MCP server binary
• tools/device_control.go, tools/devices.go → implement individual MCP “tools,” each encapsulating one kind of SwitchBot operation
• Config and dependency files: go.mod, go.sum, .gitignore, editorconfig
• No persistent database—state is fetched on demand from the SwitchBot-provided REST API.
README for additional insights
• The server acts as an MCP endpoint that:
• Retrieves device lists (get_switch_bot_devices)
• Retrieves device status (get_switch_bot_device_status)
• Sends turn-on/turn-off commands (turn_on_off_device)
• Requires environment-injected secrets: SWITCH_BOT_TOKEN and SWITCH_BOT_SECRET
• Integrates directly with SwitchBot’s REST API (via SwitchBotAPI library).
Components
a. Main components:
• MCP Client (e.g., Claude Desktop)
• SwitchBot MCP Server (the Go binary)
• Tools layer (device discovery, status query, on/off control modules)
• External SwitchBotAPI REST endpoint
• SwitchBot physical devices
b. Relationships and interactions:
1. Client sends an MCP request (e.g., “get devices”).
2. MCP Server routes to the corresponding tool.
3. Tool calls the SwitchBotAPI (HTTP + authentication).
4. API returns JSON response.
5. Tool transforms and returns it via MCP.
c. Architectural patterns and design principles:
• Modular “tools” plugin pattern: each operation is a separate Go module under /tools
• Single‐binary microservice: no database, stateless, relies on environment variables for config
• External integration via HTTP REST
d. Key technologies/libraries:
• Go (golang) for core server and tools
• Model Context Protocol (MCP) for RPC abstraction
• OpenWonderLabs/SwitchBotAPI Go client library
• JSON over HTTP
Detailed breakdown to capture all essential elements
• If desired, show the SwitchBotAPI Go library as a sub‐component within the server or tools.
• Error paths (e.g., authentication failures from API).