### Install Python Dependencies with uv and pip Source: https://context7.com/aimanmadan/arduino_mcp_server/llms.txt Provides commands to install project dependencies using uv, a fast Python package installer, and falls back to standard pip. It includes verification steps to confirm successful installation and commands to check installed package versions. ```bash # Install dependencies with uv uv pip install # Alternative: Install with standard pip pip install fastmcp pyfirmata2 asyncio # Verify installation python -c "import fastmcp; import pyfirmata2; print('Dependencies installed')" # Expected output: # Dependencies installed # Check installed versions uv pip list | grep -E "fastmcp|pyfirmata2" # fastmcp 2.8.1 # pyfirmata2 2.5.1 ``` -------------------------------- ### Install Python Dependencies with uv Source: https://github.com/aimanmadan/arduino_mcp_server/blob/main/README.md Installs necessary Python libraries like `fastmcp` and `pyfirmata2` using the `uv` package manager. This command reads the `pyproject.toml` file to determine and install all required dependencies for the project. ```bash uv pip install ``` -------------------------------- ### Python Arduino MCP Server Setup and Control Source: https://github.com/aimanmadan/arduino_mcp_server/blob/main/README.md Sets up the main Python script for the Arduino MCP Server. It imports `FastMCP` for the server and `pyfirmata2` for Arduino communication. It defines functions to control LEDs and initializes the MCP server to listen for AI commands. Remember to update the Arduino's serial port path. ```python from fastmcp import FastMCP import pyfirmata2 # IMPORTANT: Change this to your Arduino's actual COM port Arduino = pyfirmata2.Arduino('/dev/cu.usbmodem212201') ArduinoMCP = FastMCP(Arduino) @ArduinoMCP.tool def white_led_ON(): Arduino.digital[12].write(1) @ArduinoMCP.tool def red_led_ON(): Arduino.digital[11].write(1) @ArduinoMCP.tool def led_OFF(): Arduino.digital[12].write(0) Arduino.digital[11].write(0) if __name__ == "__main__": ArduinoMCP.run() ``` -------------------------------- ### Run Arduino MCP Server Source: https://context7.com/aimanmadan/arduino_mcp_server/llms.txt Instructions for launching the Arduino MCP server using either uv for optimized performance or standard Python. The server facilitates communication between MCP clients and the Arduino. Includes expected console output and a testing scenario with Claude Desktop. ```bash # Run with uv (recommended) uv --directory /path/to/arduino_mcp_server run main.py # Run with Python directly cd /path/to/arduino_mcp_server python main.py # Expected console output: # MCP server started # Server name: Arduino Servers # Available tools: white_led_ON, red_led_ON, led_OFF # Listening for connections... # Test with Claude Desktop: # 1. Start Claude Desktop # 2. Check MCP connection status (should show "arduino" server) # 3. Send command: "Turn on the white LED" # 4. Observe Arduino: white LED should illuminate # 5. Send command: "Turn everything off" # 6. Observe Arduino: all LEDs should turn off ``` -------------------------------- ### Initialize Arduino MCP Server (Python) Source: https://context7.com/aimanmadan/arduino_mcp_server/llms.txt Initializes the MCP server and establishes a connection to the Arduino board. It requires PyFirmata2 for Arduino communication and FastMCP for the MCP server. Ensure the correct COM port or device path is specified for your Arduino. ```python from fastmcp import FastMCP import pyfirmata2 # Initialize Arduino connection - replace with your COM port # Windows: 'COM3', Linux: '/dev/ttyUSB0', macOS: '/dev/cu.usbmodem212201' Arduino = pyfirmata2.Arduino('/dev/cu.usbmodem212201') # Create MCP server instance ArduinoMCP = FastMCP('Arduino Servers') # LED pin definitions WHITE_LED_PIN = 12 RED_LED_PIN = 11 # Run the server if __name__ == "__main__": ArduinoMCP.run() ``` -------------------------------- ### Claude Desktop MCP Server Configuration Source: https://github.com/aimanmadan/arduino_mcp_server/blob/main/README.md Configures Claude Desktop to connect to the Arduino MCP Server. This JSON configuration specifies the command to execute (`uv run main.py`), the directory containing the Python script, and the path to the `uv` executable. Ensure all paths are updated to match your system. ```json { "mcpServers": { "arduino": { "command": "/Users/aiman/.local/bin/uv", "args": [ "--directory", "/Users/aiman/Dev/Arduino_MCP", "run", "main.py" ] } } } ``` -------------------------------- ### Claude Desktop Configuration (JSON) Source: https://context7.com/aimanmadan/arduino_mcp_server/llms.txt JSON configuration to enable Claude Desktop to discover and use the Arduino MCP server. This configuration file specifies the command to run the server and its arguments, including the project directory. ```json { "mcpServers": { "arduino": { "command": "/Users/username/.local/bin/uv", "args": [ "--directory", "/path/to/arduino_mcp_server", "run", "main.py" ] } } } // Steps to configure: // 1. Open Claude Desktop Settings > Developer > Edit Config // 2. Update "command" to your uv executable path // Windows: "C:\\Users\\username\\AppData\\Local\\uv\\uv.exe" // macOS/Linux: "/Users/username/.local/bin/uv" // 3. Update "--directory" to your project path // 4. Save and restart Claude Desktop // 5. Verify connection in Claude Desktop MCP section ``` -------------------------------- ### PyFirmata2 Digital Write to Arduino Source: https://context7.com/aimanmadan/arduino_mcp_server/llms.txt Demonstrates how to write digital HIGH/LOW values to specific Arduino pins using the pyfirmata2 library. This is fundamental for controlling outputs like LEDs. It includes basic usage, variable assignment, and error handling. ```python import pyfirmata2 # Initialize Arduino connection Arduino = pyfirmata2.Arduino('/dev/cu.usbmodem212201') # Write HIGH (5V) to pin 12 Arduino.digital[12].write(1) # Write LOW (0V) to pin 11 Arduino.digital[11].write(0) # Using variables pin_number = 13 state = 1 # 1 for HIGH, 0 for LOW Arduino.digital[pin_number].write(state) # Error handling example try: Arduino.digital[12].write(1) print("LED turned on successfully") except Exception as e: print(f"Error controlling Arduino: {e}") ``` -------------------------------- ### Control White LED with MCP Tool (Python) Source: https://context7.com/aimanmadan/arduino_mcp_server/llms.txt Defines a Python function decorated as an MCP tool to turn on a white LED connected to digital pin 12. This function can be invoked by AI clients through natural language commands. ```python @ArduinoMCP.tool def white_led_ON(): '''Turns on white LED in the Arduino''' Arduino.digital[WHITE_LED_PIN].write(1) return 'White LED ON' # Usage from Claude Desktop: # User: "Turn on the white LED" # Claude invokes: white_led_ON() # Arduino response: Pin 12 goes HIGH (5V) # Function returns: 'White LED ON' ``` -------------------------------- ### Control Red LED with MCP Tool (Python) Source: https://context7.com/aimanmadan/arduino_mcp_server/llms.txt Defines a Python function decorated as an MCP tool to activate a red LED connected to digital pin 11. AI clients can call this function via conversational interfaces. ```python @ArduinoMCP.tool def red_led_ON(): '''Turns on red LED in the Arduino''' Arduino.digital[RED_LED_PIN].write(1) return 'Red LED ON' # Usage from Claude Desktop: # User: "Switch on the red LED" # Claude invokes: red_led_ON() # Arduino response: Pin 11 goes HIGH (5V) # Function returns: 'Red LED ON' ``` -------------------------------- ### Turn Off All LEDs with MCP Tool (Python) Source: https://context7.com/aimanmadan/arduino_mcp_server/llms.txt Defines a Python function decorated as an MCP tool to turn off all LEDs by setting both red and white LED pins to LOW. This provides a simple way to reset the LED state via AI commands. ```python @ArduinoMCP.tool def led_OFF(): '''Turns off all LEDs in the Arduino''' Arduino.digital[RED_LED_PIN].write(0) Arduino.digital[WHITE_LED_PIN].write(0) return 'All LEDs OFF' # Usage from Claude Desktop: # User: "Turn off all the lights" # Claude invokes: led_OFF() # Arduino response: Pins 11 and 12 go LOW (0V) # Function returns: 'All LEDs OFF' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.