Skip to main content
Glama
Arduino MCP Server

Arduino MCP Server

by niradler

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 configuration

  • board-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)

Related MCP server: FastMCP Server

Prerequisites

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

  1. Clone this repository:

git clone <your-repo-url>
cd arduino-mcp
  1. Install dependencies with uv:

uv sync
  1. 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

# 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

# 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")
# 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 installation

  • list_connected_boards() - List all connected Arduino boards

  • list_serial_ports() - List all serial ports

  • find_arduino_ports() - Find Arduino-specific ports

  • get_best_port() - Auto-detect best port candidate

  • verify_port(port) - Verify if a port is accessible

Core Management

  • list_installed_cores() - List installed Arduino cores

  • search_cores(query) - Search for Arduino cores

  • install_core(core) - Install an Arduino core

Library Management

  • search_libraries(query) - Search for Arduino libraries

  • install_library(library) - Install an Arduino library

  • list_installed_libraries() - List installed libraries

Sketch Operations

  • create_new_sketch(name, path) - Create a new Arduino sketch

  • compile_sketch(path, fqbn) - Compile an Arduino sketch

  • upload_sketch(path, fqbn, port) - Upload sketch to board

Utilities

  • get_arduino_help(command) - Get help for Arduino CLI commands

  • initialize_config() - Initialize Arduino CLI configuration

  • clean_cache() - Clean Arduino CLI cache

  • check_imagemagick_installed() - Check ImageMagick installation

  • convert_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

License

MIT License

Available Tools

16 tools
arduino_cli_commandExecute Raw Arduino CLI CommandD

Inputs: command (required). Returns: result

clean_cacheD

Inputs: no named parameters. Returns: result

compile_sketchCompile Arduino SketchA

Compile an Arduino sketch.

TIP: If you used arduino-cli board attach on this sketch, FQBN is optional! The board settings will be read from sketch.yaml automatically.

For project-based workflows, use board attach first: arduino_cli_command("board attach -p COM3 -b arduino:avr:uno MySketch")

Then compile without specifying FQBN each time. See the sketch_project_workflow prompt for details.

Inputs: sketch_path (required), fqbn (required). Returns: result

convert_image_to_c_arrayConvert Image to C Array for Hardware DisplaysA

Convert images to C arrays for hardware displays (OLED, E-Paper, TFT, LEDs)

Supports: monochrome (1-bit), grayscale_2bit (4-level), grayscale_4bit (16-level), grayscale (8-bit), rgb565 (16-bit color), rgb888 (24-bit color)

Parameters:

  • rotation: 0, 90, 180, or 270 degrees (test all to find correct orientation)

  • threshold: Black/white cutoff for monochrome (e.g., "50%", "60%", "70%")

  • keep_aspect: True to maintain proportions, False to force exact size

Inputs: image_path (required), width (required), height (required), var_name (required), +6 more. Returns: result

create_new_sketchD

Inputs: sketch_name (required), path. Returns: result

install_coreInstall Arduino CoreD

Inputs: core (required). Returns: result

install_libraryInstall Arduino LibraryD

Inputs: library (required). Returns: result

lint_arduino_projectLint Arduino ProjectB
Read-only

Lint Arduino project for compliance and best practices.

Inputs: project_path (required), compliance, library_manager. Returns: result

list_connected_boardsD
Read-only

Inputs: no named parameters. Returns: result

list_installed_coresD
Read-only

Inputs: no named parameters. Returns: result

list_installed_librariesD
Read-only

Inputs: no named parameters. Returns: result

list_portsList Serial PortsD
Read-only

Inputs: arduino_only. Returns: result

serial_monitorEnhanced Serial Monitor with Bidirectional CommunicationD

Inputs: port (required), duration, baudrate, send_commands, +2 more. Returns: result

upload_sketchUpload Sketch to BoardA
Destructive

Upload a compiled sketch to an Arduino board.

TIP: If you used arduino-cli board attach on this sketch, FQBN and port are optional! The settings will be read from sketch.yaml automatically.

For project-based workflows, use board attach first: arduino_cli_command("board attach -p COM3 -b arduino:avr:uno MySketch")

Then upload without specifying FQBN/port each time. See the sketch_project_workflow prompt for details.

Inputs: sketch_path (required), fqbn (required), port (required). Returns: result

verify_portD
Read-only

Inputs: port (required). Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

    TDQS

    C2.2/5.0

    Scored across 16 tools

    Disambiguation2/5

    Many tools lack descriptions, and 'arduino_cli_command' is overly generic, potentially overlapping with other tools. Several tools like 'clean_cache' are ambiguous, making it hard for agents to distinguish purposes.

    Naming Consistency4/5

    Most tools follow a verb_noun pattern with snake_case, but 'arduino_cli_command' is noun_noun and 'search' is just a verb, causing minor inconsistency.

    Tool Count5/5

    16 tools cover a wide range of Arduino operations without being overwhelming. Each tool serves a distinct aspect of the development workflow.

    Completeness4/5

    Core CRUD and lifecycle operations for sketches, libraries, cores, boards, and serial monitoring are present. Missing explicit delete or update tools, but the generic 'arduino_cli_command' can cover gaps.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      MCP server for Arduino IDE 2.0 sketches. It exposes a small REST API plus an MCP stdio bridge so agents can read and write the main .ino file, list sources, and optionally compile with arduino-cli.
      61 npm
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      A high-performance personal Model Context Protocol (MCP) server built with the FastMCP Python framework.
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      A fully local MCP server for Mixly that lets AI clients discover boards, scan blocks, build/validate/open projects, generate code, and compile via Arduino CLIβ€”all without uploading source or relying on a remote server.
      3
      -
    • F
      license
      A
      quality
      C
      maintenance
      A local stdio MCP server wrapping arduino-cli to let agents detect boards, manage cores/libraries, compile and upload sketches, and communicate over serial, enabling hardware control without shell gymnastics.
      17
      -