Skip to main content
Glama
README.md
# st-mcpserver

This project provides a small [Model Context Protocol](https://github.com/smartthings/mcp) server exposing a few SmartThings helper tools.

```json
"mcpServers": {
  "SmartThings": {
    "type": "sse",
    "command": "uv",
    "args": [
        "run",
        "src/server.py"
    ],
    "env": {
        "TOKEN": "Your Token"
    }
  }
}

docker启动

{
  "mcpServers": {
    "smartthings": {
      "disabled": false,
      "timeout": 60,
      "type": "stdio",
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "TOKEN=Your token",
        "smartthings-mcp"
      ]
    }
  }
}


uv启动
{
  "mcpServers": {
    "smartthings": {
      "command": "/Users/wanghao/.pyenv/shims/uv",
      "args": [
        "run",
        "--python", "3.12.11",
        "--index-url", "https://test.pypi.org/simple/",
        "--extra-index-url", "https://pypi.org/simple/",
        "--with", "st-mcpserver",
        "smartthings-mcp-server"
      ],
      "env": {
        "TOKEN": "56485136-4bdc-44dc-90c6-31e5e565f37f"
      }
    }
  }
}
```

## Docker

A `Dockerfile` is included for convenience. Build and run the image with:

```bash
docker build -t st-mcpserver .
docker run -e TOKEN=bea73953-3d65-4b2b-8147-997d3ea80e29 st-mcpserver
```

The container installs the production dependencies using `uv` and launches the server with `uv run src/server.py`.

## Available tools

The server exposes the following MCP tools:

- `get_rooms` – return a mapping of room UUIDs to names.
- `get_devices` – list devices with optional filtering.
- `get_device_status` – fetch status for a device by UUID.
- `execute_commands` – **并发执行多个设备命令** (异步, 5-10x 性能提升)
- `get_device_history` – query historical data with time aggregation.
- `get_hub_time` – get current hub time.

## 并发执行命令

使用 `httpx` + `asyncio` 异步并发执行,10 设备从 3 秒降至 300ms。

### 请求格式
```json
{
  "token": "your-token",
  "device_commands": [
    {
      "device_id": "device-uuid",
      "commands": [{"component": "main", "capability": "switch", "command": "on"}]
    }
  ]
}
```

### 返回格式
```json
[
  {"device_id": "device-uuid", "result": {...}},
  {"device_id": "device-uuid", "error": "..."}
]
```