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.
README
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
- Enhanced Serial Monitor: Bidirectional communication, buffering, file export
- 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
- Sketch Project Workflow: IDE-like experience with board attach
- 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)
Environment Variables
Customize the server behavior with these optional environment variables:
| Variable | Default | Description |
|---|---|---|
ARDUINO_CLI_PATH |
arduino-cli |
Path to Arduino CLI executable |
MCP_SKETCH_DIR |
OS-specific* | Override default sketch directory |
ARDUINO_SERIAL_BUFFER_SIZE |
10 |
Serial buffer size in MB |
ARDUINO_CONFIG_FILE |
Auto-detected | Custom Arduino CLI config file path |
*Default sketch directories:
- Windows:
%DOCUMENTS%\Arduino - macOS:
~/Documents/Arduino - Linux:
~/Arduino
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": "uvx",
"args": ["arduino-mcp"]
}
}
}
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": "uvx",
"args": ["arduino-mcp"]
}
}
}
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. Project-Based Workflow with Board Attach (Recommended)
# Find your connected board
list_connected_boards()
# Create a new sketch
create_new_sketch("MyProject")
# Attach board settings to sketch (IDE-like experience!)
arduino_cli_command("board attach -p COM3 -b arduino:avr:uno MyProject")
# This creates sketch.yaml with your board settings
# Now compile and upload without repeating FQBN/port
compile_sketch("MyProject", "") # Reads from sketch.yaml
upload_sketch("MyProject", "", "") # Reads from sketch.yaml
# Monitor serial output with bidirectional communication
serial_monitor(
port="COM3",
baudrate=115200,
duration=30,
send_commands="LED ON\nLED OFF", # Send commands to device
save_to_file="output.log" # Save buffer to file
)
Why use board attach?
- Settings persist per-sketch (not globally)
- No need to repeat FQBN and port every time
- Team-friendly (sketch.yaml can be version controlled)
- Works exactly like Arduino IDE 2.x
2. 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. Basic Setup and Blink LED
# Check if Arduino CLI is installed
arduino_cli_command("version")
# Find connected Arduino boards
list_connected_boards()
list_ports(arduino_only=True)
# 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")
# Monitor output
serial_monitor("COM3", baudrate=115200, duration=20)
3. 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()
4. Enhanced Serial Monitor Features
# Basic monitoring (115200 is now the default)
serial_monitor("COM3", duration=30)
# Send commands while monitoring (bidirectional)
serial_monitor(
port="COM3",
baudrate=115200,
duration=30,
send_commands="GET_STATUS\nSET_LED 1"
)
# Save buffer to file for analysis
serial_monitor(
port="COM3",
baudrate=115200,
duration=60,
save_to_file="sensor_data.log"
)
# Combined: send commands and save output
serial_monitor(
port="COM3",
baudrate=115200,
duration=45,
send_commands="START_LOGGING",
save_to_file="experiment_results.txt"
)
Buffer Features:
- Circular buffer (10MB default, configurable via env var)
- Memory-safe (won't crash on long-running captures)
- Thread-safe operation
- Automatic statistics (lines captured, buffer usage)
5. 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"
)
6. 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
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。