parkerdorris/ArduinoButtonMonitorMCP
If you are the rightful owner of ArduinoButtonMonitorMCP and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) server that monitors Arduino button states and provides real-time event streaming via HTTP.
Arduino MCP Button Monitor
A real-time Arduino button monitoring system using the Model Context Protocol (MCP) standard with WebSocket transport and optional LLM-powered intelligent narration.
🚀 Features
- MCP Standard Compliant - Follows Anthropic's Model Context Protocol specification
- WebSocket Transport - Real-time bidirectional communication
- Arduino Integration - Automatic port detection and serial communication
- LLM Enhancement - GPT-4o powered intelligent event narration
- Real-time Events - Instant button press/release detection and streaming
- Cross-platform - Works on Windows, macOS, and Linux
🏗️ Architecture
Arduino (button_monitor.ino)
↓ Serial Communication
MCP WebSocket Server (mcp_websocket_server.py)
↓ WebSocket MCP Protocol
MCP WebSocket Client (mcp_websocket_client.py)
↓ Optional LLM Integration
LLM MCP Client (llm_mcp_client_standard.py)
📋 Requirements
Hardware
- Arduino board (Arduino Uno, MKR WiFi 1010, etc.)
- Push button
- Breadboard and jumper wires
- USB cable
Software
- Python 3.8+
- Arduino IDE
- OpenAI API key (for LLM features)
🛠️ Installation
-
Clone the repository
git clone <repository-url> cd ArduinoMCP -
Install Python dependencies
pip install -r requirements.txt -
Set up environment variables
# Create .env file echo "OPENAI_API_KEY=your_api_key_here" > .env
🔌 Hardware Setup
-
Connect the button to Arduino:
- Button pin 1 → Arduino pin 2
- Button pin 2 → Arduino GND
- Arduino pin 2 has internal pull-up resistor enabled
-
Upload the Arduino sketch:
- Open
button_monitor.inoin Arduino IDE - Select your board and port
- Upload the sketch
- Open
🚀 Quick Start
1. Start the MCP Server
python3 mcp_websocket_server.py
The server will start on http://localhost:5001 and automatically detect your Arduino.
2. Test Basic MCP Functionality
python3 demo_mcp_standards.py
This tests the basic MCP connection without requiring an OpenAI API key.
3. Run the LLM-Enhanced Client
python3 llm_mcp_client_standard.py
This provides intelligent narration of button events using GPT-4o.
📚 Usage Examples
Basic MCP Client
from mcp_websocket_client import MCPWebSocketClient
async def main():
client = MCPWebSocketClient()
# Connect to server
await client.connect()
# List available tools
tools = await client.list_tools()
print(f"Available tools: {tools}")
# Connect to Arduino
result = await client.connect_arduino()
print(f"Arduino connection: {result}")
# Get button state
state = await client.get_button_state()
print(f"Button state: {state}")
await client.disconnect()
asyncio.run(main())
LLM-Enhanced Monitoring
from llm_mcp_client_standard import LLMMCPClient
async def main():
client = LLMMCPClient()
await client.start_monitoring(duration=300) # 5 minutes
asyncio.run(main())
🔧 MCP Protocol Methods
The server implements the following MCP standard methods:
mcp/servers/list- List available serversmcp/servers/read- Read server informationmcp/tools/list- List available toolsmcp/tools/call- Call tools with argumentsmcp/tools/subscribe- Subscribe to tool updatesmcp/notifications/subscribe- Subscribe to notifications
Available Tools
get_button_state- Get current button state (0 or 1)subscribe_button_edges- Subscribe to button edge eventsconnect_arduino- Connect to Arduino (auto-detects port)disconnect_arduino- Disconnect from Arduino
📡 Real-time Events
Button events are streamed in real-time via MCP notifications:
{
"jsonrpc": "2.0",
"method": "button_event",
"params": {
"event": "RISING",
"timestamp": 1755367431.522897
}
}
RISING- Button pressed (state changes from 0 to 1)FALLING- Button released (state changes from 1 to 0)
🧪 Testing
Test MCP Compliance
python3 test_mcp_protocol_compliance.py
Test Basic Functionality
python3 mcp_websocket_client.py
🔍 Troubleshooting
Common Issues
-
Arduino not detected
- Check USB connection
- Verify Arduino IDE port selection
- Restart the server
-
Connection refused
- Ensure server is running on port 5001
- Check firewall settings
-
LLM narration fails
- Verify
OPENAI_API_KEYis set - Check internet connection
- Verify API key has sufficient credits
- Verify
Debug Mode
Enable detailed logging by modifying the logging level in any Python file:
logging.basicConfig(level=logging.DEBUG)
📖 API Reference
MCPWebSocketClient
connect()- Connect to MCP serverdisconnect()- Disconnect from serverlist_servers()- List available serverslist_tools()- List available toolscall_tool(name, arguments)- Call a specific toolsubscribe_to_tool(name)- Subscribe to tool updatesget_button_state()- Get current button stateconnect_arduino(port)- Connect to Arduino
LLMMCPClient
start_monitoring(duration)- Start monitoring with LLM narrationconnect()- Connect to MCP server and Arduinosubscribe_to_events()- Subscribe to button events
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.