MCP server for Arduino CLI interactions
Project description
Arduino MCP Server
A comprehensive Model Context Protocol (MCP) server for Arduino CLI interactions, built with FastMCP. This server enables AI agents to seamlessly interact with Arduino CLI for development, debugging, code verification, and more.
Features
🛠️ Tools (All 3 MCP Pillars)
- CLI Management: Check installation, get help for commands
- Board Detection: List connected boards, find Arduino ports, auto-detect best port
- Core Management: Search, install, and list Arduino cores
- Library Management: Search, install, and list Arduino libraries
- Sketch Operations: Create, compile, and upload sketches
- Image Conversion: Convert images to C arrays for display applications (requires ImageMagick)
- Configuration: Initialize config, clean cache
📚 Resources
sketch://{path}- Read Arduino sketch files (.ino, .cpp, .h)arduino-config://main- Access Arduino CLI configurationboard-info://{fqbn}- Get detailed board information
💡 Prompts
- Blink LED Example: Basic LED blinking sketch template
- Sensor Reading Example: Analog sensor reading template
- Full Development Workflow: Complete Arduino development guide
- Troubleshooting Guide: Common issues and solutions
🚀 Advanced Features
- Logging: Comprehensive logging with info, warning, error levels (source)
- Progress Reporting: Real-time progress updates for long operations (source)
- Context Integration: Full MCP context support for enhanced interactions (source)
- Annotations: Proper tool annotations for better UX (readOnly, destructive, openWorld hints)
Prerequisites
- Python 3.10+
- uv (Python package manager)
- Arduino CLI
- ImageMagick (optional, for image conversion)
Installation
- Clone this repository:
git clone <your-repo-url>
cd arduino-mcp
- Install dependencies with uv:
uv sync
- Install Arduino CLI:
# Windows (using winget)
winget install ArduinoSA.CLI
# macOS
brew install arduino-cli
# Linux
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh
Usage
Running the Server
Using uv:
uv run python -m arduino_mcp.server
Using FastMCP CLI:
uv run fastmcp run arduino_mcp/server.py:mcp
For HTTP transport:
uv run fastmcp run arduino_mcp/server.py:mcp --transport http --port 8000
Configuration for MCP Clients
For Cursor IDE
The project includes .cursor/mcp.json configuration. Cursor will automatically detect it when you open the project.
Alternatively, add to your global Cursor settings:
{
"mcpServers": {
"arduino": {
"command": "uv",
"args": [
"--directory",
"C:/Projects/mcp/arduino-mcp",
"run",
"python",
"-m",
"arduino_mcp.server"
]
}
}
}
For Claude Desktop
Add to your MCP configuration file:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"arduino": {
"command": "uv",
"args": [
"--directory",
"C:/Projects/mcp/arduino-mcp",
"run",
"python",
"-m",
"arduino_mcp.server"
]
}
}
}
Testing
To verify the Arduino MCP server is working:
# Test import
uv run python -c "from arduino_mcp import mcp; print('Server imports successfully')"
# Start the server
uv run fastmcp run arduino_mcp/server.py:mcp
Once running in Cursor IDE, you can test the tools directly in the chat interface.
Example Workflows
1. Basic Setup and Blink LED
# Check if Arduino CLI is installed
check_arduino_cli_installed()
# Find connected Arduino boards
list_connected_boards()
find_arduino_ports()
get_best_port()
# Create a new sketch
create_new_sketch("BlinkLED", "./sketches")
# Use the blink_led_example prompt for code template
# Compile the sketch
compile_sketch("./sketches/BlinkLED", "arduino:avr:uno")
# Upload to board
upload_sketch("./sketches/BlinkLED", "arduino:avr:uno", "COM3")
2. Library Installation and Usage
# Search for a library
search_libraries("Adafruit SSD1306")
# Install the library
install_library("Adafruit SSD1306")
# List installed libraries
list_installed_libraries()
3. Image to C Array Conversion
# Check ImageMagick installation
check_imagemagick_installed()
# Convert image to C array for Arduino displays
convert_image_to_c_array(
"logo.png",
width=128,
height=64,
var_name="logo_bitmap",
output_file="logo.h"
)
4. Resource Access
# Read a sketch file
read_resource("sketch://./BlinkLED/BlinkLED.ino")
# Get Arduino configuration
read_resource("arduino-config://main")
# Get board details
read_resource("board-info://arduino:avr:uno")
Tools Reference
Board & Port Detection
check_arduino_cli_installed()- Verify Arduino CLI installationlist_connected_boards()- List all connected Arduino boardslist_serial_ports()- List all serial portsfind_arduino_ports()- Find Arduino-specific portsget_best_port()- Auto-detect best port candidateverify_port(port)- Verify if a port is accessible
Core Management
list_installed_cores()- List installed Arduino coressearch_cores(query)- Search for Arduino coresinstall_core(core)- Install an Arduino core
Library Management
search_libraries(query)- Search for Arduino librariesinstall_library(library)- Install an Arduino librarylist_installed_libraries()- List installed libraries
Sketch Operations
create_new_sketch(name, path)- Create a new Arduino sketchcompile_sketch(path, fqbn)- Compile an Arduino sketchupload_sketch(path, fqbn, port)- Upload sketch to board
Utilities
get_arduino_help(command)- Get help for Arduino CLI commandsinitialize_config()- Initialize Arduino CLI configurationclean_cache()- Clean Arduino CLI cachecheck_imagemagick_installed()- Check ImageMagick installationconvert_image_to_c_array(...)- Convert images to C arrays
Common FQBNs
- Arduino Uno:
arduino:avr:uno - Arduino Mega 2560:
arduino:avr:mega - Arduino Nano:
arduino:avr:nano - Arduino Leonardo:
arduino:avr:leonardo - ESP32:
esp32:esp32:esp32 - ESP8266:
esp8266:esp8266:generic
Architecture
arduino-mcp/
├── arduino_mcp/
│ ├── __init__.py # Package initialization
│ ├── server.py # Main MCP server with tools, resources, prompts
│ ├── cli_wrapper.py # Arduino CLI wrapper
│ ├── port_detector.py # Serial port detection utilities
│ ├── image_converter.py # ImageMagick image conversion
│ └── platform_utils.py # Cross-platform OS detection & handling
├── pyproject.toml # Project configuration
└── README.md # This file
Cross-Platform Design
- platform_utils.py: Centralized OS detection and platform-specific behavior
- Automatic detection: Windows (COM*), macOS (/dev/tty.), Linux (/dev/ttyUSB, /dev/ttyACM*)
- Serial keywords: Platform-specific Arduino device identification
- Error handling: PermissionError for Linux, graceful fallbacks
- Path handling: OS-appropriate path separators and formats
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
References
- FastMCP Documentation
- Arduino CLI Documentation
- Model Context Protocol
- FastMCP Tools
- FastMCP Resources
- FastMCP Prompts
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file arduino_mcp-0.1.0.tar.gz.
File metadata
- Download URL: arduino_mcp-0.1.0.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74389bd07df83c35389e974a489e8e0b7e64aaea5c0c45bd89e07465d80a7c71
|
|
| MD5 |
35e7c187042a30246d72b1673e88f9b5
|
|
| BLAKE2b-256 |
40fd160e4bd64fc02e51afbbdef997680464ab966357c56445bafffd90be0f27
|
File details
Details for the file arduino_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: arduino_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e46ae04addeb8d7326297bdbfb80531de90c496396243a0a8e0febf21351a36
|
|
| MD5 |
88d11d22ddb972751f5e64f04e33c5b5
|
|
| BLAKE2b-256 |
4ab153d5ace1570a002c136574d46252088b0608903daeae9742253ce3a1ee75
|