pyBTMCP
A BLE fitness device simulator that enables AI agents to control simulated heart rate monitors, treadmills, and cycling trainers via the Model Context Protocol. It integrates ESP32 firmware, an MQTT broker, and a FastAPI backend for comprehensive device management and real-time interaction.
README
pyBTMCP - BLE Device Simulator with MCP Integration
A comprehensive BLE (Bluetooth Low Energy) fitness device simulator that enables AI agents like Claude to control simulated heart rate monitors, treadmills, and cycling trainers via the Model Context Protocol (MCP).
Overview
pyBTMCP consists of three integrated components:
- ESP32 Firmware - Runs on ESP32 microcontrollers to simulate BLE fitness devices
- Python Backend - FastAPI server with MQTT broker for device communication
- MCP Server - Enables Claude and other AI agents to control devices
┌─────────────────┐ ┌──────────────────────────────────────────┐
│ Claude/AI │ │ Docker Container │
│ (MCP Client) │◄───►│ ┌─────────┐ ┌───────┐ ┌──────────┐ │
└─────────────────┘ │ │ MCP │ │ MQTT │ │ FastAPI │ │
│ │ Server │◄►│Broker │◄►│ + Web │ │
│ └─────────┘ └───┬───┘ └──────────┘ │
└──────────────────│───────────────────────┘
│
┌──────────────────▼───────────────────────┐
│ ESP32 Devices │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ HR │ │Treadmill│ │ Bike │ │
│ │ Monitor │ │ │ │ Trainer │ │
│ └─────────┘ └─────────┘ └─────────┘ │
└──────────────────────────────────────────┘
Quick Start
Prerequisites
- Docker
- (Optional) ESP32 development board for hardware simulation
1. Build the Docker Image
docker build -t pybtmcp:latest .
2. Run the Container
docker run -it --rm \
-p 1883:1883 \
-p 8000:8000 \
--name pybtmcp \
pybtmcp:latest
This starts:
- MQTT Broker on port 1883 (for ESP32 device connections)
- Web UI / API on port 8000 (browser interface)
- MCP Server on stdio (for Claude integration)
3. Access the Web UI
Open http://localhost:8000 in your browser to see connected devices and control them manually.
MCP Integration (Claude Desktop)
To use pyBTMCP with Claude Desktop, add it to your MCP configuration:
Configuration File Location
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Add the Server Configuration
{
"mcpServers": {
"ble-simulator": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-p", "1883:1883",
"-p", "8000:8000",
"--name", "pybtmcp",
"pybtmcp:latest"
]
}
}
}
Restart Claude Desktop
After saving the configuration, restart Claude Desktop. You should see the "ble-simulator" MCP server available.
MCP Integration (Claude Code CLI)
To add pyBTMCP to Claude Code, run:
claude mcp add ble-simulator \
-s user \
-- docker run -i --rm -p 1883:1883 -p 8000:8000 --name pybtmcp pybtmcp:latest
This adds the MCP server to your user configuration. Use -s project instead to add it to the current project only.
To verify the server was added:
claude mcp list
MCP Tools Reference
Once configured, Claude can use these tools to control BLE devices:
list_devices
List all connected ESP32 BLE simulator devices.
No parameters required
configure_device
Configure an ESP32 to simulate a specific BLE device type.
| Parameter | Type | Required | Description |
|---|---|---|---|
| device_id | string | Yes | The ESP32 device ID |
| device_type | string | Yes | One of: heart_rate, treadmill, bike |
set_heart_rate
Set the simulated heart rate for a heart rate monitor device.
| Parameter | Type | Required | Description |
|---|---|---|---|
| device_id | string | Yes | The ESP32 device ID |
| bpm | integer | Yes | Heart rate (30-220 BPM) |
set_treadmill_values
Set simulated values for a treadmill device.
| Parameter | Type | Required | Description |
|---|---|---|---|
| device_id | string | Yes | The ESP32 device ID |
| speed | number | No | Speed in km/h (0-25) |
| incline | number | No | Incline percentage (-5 to 30) |
set_bike_values
Set simulated values for a bike/cycling trainer device.
| Parameter | Type | Required | Description |
|---|---|---|---|
| device_id | string | Yes | The ESP32 device ID |
| power | integer | No | Power in watts (0-2000) |
| cadence | integer | No | Cadence in RPM (0-200) |
| speed | number | No | Speed in km/h (0-80) |
get_device_status
Get the current status and values of a specific device.
| Parameter | Type | Required | Description |
|---|---|---|---|
| device_id | string | Yes | The ESP32 device ID |
Web UI Features
The web interface at http://localhost:8000 provides:
- Real-time device status via WebSocket (live updates)
- Device type configuration (Heart Rate, Treadmill, Bike)
- Preset values for quick testing (Rest, Warm Up, Cardio, etc.)
- Manual sliders for fine-grained control
- Unit switching (Metric/Imperial)
- HR variation toggle for realistic heart rate simulation
Connection Status Indicator
The UI shows WebSocket connection status:
- 🟢 Live - Connected and receiving real-time updates
- 🟡 Connecting... - Attempting to connect
- 🔴 Disconnected - Using polling fallback
REST API
The FastAPI backend provides these endpoints:
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/devices |
List all devices |
| GET | /api/devices/{id} |
Get device by ID |
| POST | /api/devices/{id}/configure |
Configure device type |
| POST | /api/devices/{id}/values |
Set device values |
| GET | /health |
Health check |
| WS | /ws |
WebSocket for real-time updates |
API documentation is available at http://localhost:8000/docs (Swagger UI).
ESP32 Firmware Setup
Hardware Requirements
- ESP32 development board (ESP32-DevKitC, ESP32-WROOM, etc.)
- USB cable for programming
Building the Firmware
- Install PlatformIO
- Navigate to the firmware directory:
cd firmware/esp32_ble_sim - Build and upload:
pio run -t upload
Initial Configuration
- On first boot, the ESP32 creates a WiFi access point:
BLE-Sim-XXXX - Connect to the AP and open http://192.168.4.1
- Enter your WiFi credentials and MQTT broker address
- The device will restart and connect to your network
MQTT Topics
The ESP32 devices communicate via MQTT:
| Topic | Direction | Description |
|---|---|---|
ble-sim/{id}/status |
Device → Server | Device online status |
ble-sim/{id}/values |
Device → Server | Current sensor values |
ble-sim/{id}/config |
Server → Device | Device type configuration |
ble-sim/{id}/set |
Server → Device | Set sensor values |
Development
Running Locally (without Docker)
-
Install dependencies:
pip install -r requirements.txt -
Start an MQTT broker (e.g., Mosquitto):
mosquitto -c config/mosquitto.conf -
Start the API server:
uvicorn src.api.main:app --reload --port 8000 -
Run the MCP server (for testing):
python -m src.mcp.server
Environment Variables
| Variable | Default | Description |
|---|---|---|
| MQTT_HOST | localhost | MQTT broker hostname |
| MQTT_PORT | 1883 | MQTT broker port |
Project Structure
pyBTMCP/
├── src/
│ ├── mcp/
│ │ └── server.py # MCP server implementation
│ ├── api/
│ │ ├── main.py # FastAPI app + WebSocket
│ │ ├── routes.py # REST API routes
│ │ ├── mqtt_client.py # MQTT connection manager
│ │ └── device_registry.py # Device state tracking
│ └── web/
│ └── static/
│ └── index.html # Web UI
├── firmware/
│ └── esp32_ble_sim/ # PlatformIO ESP32 project
├── config/
│ └── mosquitto.conf # MQTT broker config
├── Dockerfile
├── entrypoint.sh
├── requirements.txt
└── mcp-config.example.json # Example Claude Desktop config
Supported BLE Services
| Device Type | BLE Service | Characteristics |
|---|---|---|
| Heart Rate Monitor | Heart Rate Service (0x180D) | Heart Rate Measurement |
| Treadmill | Fitness Machine Service (0x1826) | Treadmill Data |
| Bike Trainer | Cycling Power Service (0x1818) | Cycling Power Measurement |
Troubleshooting
MCP server not appearing in Claude Desktop
- Ensure Docker is running
- Check the config file path is correct for your OS
- Restart Claude Desktop after saving config
- Check Docker logs:
docker logs pybtmcp
ESP32 not connecting
- Verify WiFi credentials are correct
- Ensure MQTT broker is reachable from ESP32's network
- Check MQTT broker is listening on port 1883
- Use
mosquitto_sub -t "ble-sim/#" -vto monitor MQTT traffic
Web UI not updating
- Check browser console for WebSocket errors
- Verify the container is running:
docker ps - The UI falls back to 5-second polling if WebSocket disconnects
License
MIT License
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。