papilio_mcp_server

GadgetFactory/papilio_mcp_server

3.2

If you are the rightful owner of papilio_mcp_server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The Papilio Arcade MCP Server is a system that enables AI assistants to control the Papilio Arcade FPGA board through a Model Context Protocol server and debug firmware.

Tools
5
Resources
0
Prompts
0

Papilio Arcade MCP Server

An MCP (Model Context Protocol) server and debug firmware that allows AI assistants like GitHub Copilot to directly control the Papilio Arcade FPGA board.

Components

This library contains:

  1. MCP Server (Python) - Runs on host PC, translates MCP tool calls to serial commands
  2. PapilioMCP.h (Arduino) - Header-only library to add MCP debug to any sketch
  3. Example Firmware - Ready-to-use debug firmware sketches

Quick Start - Adding MCP Debug to Any Sketch

The easiest way to add MCP debug capability is with the header library:

// Add BEFORE setup() - comment out to disable
#define PAPILIO_MCP_ENABLED
#include <PapilioMCP.h>

void setup() {
  Serial.begin(115200);
  // ... your setup code ...
  
  PapilioMCP.begin();  // Initialize MCP (does nothing if disabled)
}

void loop() {
  PapilioMCP.update();  // Process MCP commands (does nothing if disabled)
  
  // ... your loop code ...
}

When PAPILIO_MCP_ENABLED is NOT defined, PapilioMCP.begin() and PapilioMCP.update() compile to empty stubs - zero overhead.

Quick Start - Using the Debug Firmware

1. Upload the Debug Firmware

# From project root
pio run -e mcp_debug_firmware -t upload

Or use the Makefile:

make mcp_debug_firmware-upload

2. Configure VS Code MCP

The .vscode/mcp.json should already be configured. If not, add:

{
  "servers": {
    "papilio": {
      "type": "stdio",
      "command": "python",
      "args": ["libs/papilio_mcp_server/server/papilio_mcp_server.py", "--port", "COM4"]
    }
  }
}

3. Install Python Dependencies

pip install pyserial opencv-python

PlatformIO Build Environments

In your platformio.ini, you can add MCP debug to any environment via build flags:

; Normal build - MCP disabled
[env:my_project]
extends = env:papilio_arcade

; Debug build - MCP enabled
[env:my_project_debug]
extends = env:papilio_arcade
build_flags = ${env:papilio_arcade.build_flags}
              -DPAPILIO_MCP_ENABLED

Features

  • RGB LED Control: Set and read RGB LED colors
  • Wishbone Bus Access: Read/write to any Wishbone bus address
  • FPGA Status: Get debug dumps and status information
  • Serial Port Management: List ports and connect to the board
  • Screenshot Capture: Capture webcam images of HDMI output
  • Video Mode Control: Switch between test patterns, text mode, and framebuffer
  • Text Mode: Write text to 80x26 text display
  • JTAG Bridge: Enable USB JTAG passthrough for FPGA programming

Serial Commands (via PapilioMCP.h)

CommandDescription
HHelp
W AAAA DDWrite DD to Wishbone address AAAA
R AAAARead from Wishbone address AAAA
M AAAA NNRead NN bytes starting at AAAA
DDump debug registers
J [1|0]Enable/disable JTAG bridge

Available MCP Tools

RGB LED Control

ToolDescription
set_rgb_ledSet the RGB LED color (0-255 per channel)
get_rgb_ledRead the current RGB LED color values

Wishbone Bus Access

ToolDescription
wishbone_readRead a byte from a Wishbone bus address
wishbone_writeWrite a byte to a Wishbone bus address

Board Management

ToolDescription
list_serial_portsList available serial ports
connect_boardConnect to board on specific port
disconnect_boardDisconnect from board (free serial port)
get_fpga_statusGet debug status and register dump
send_raw_commandSend raw command with streaming output

Screenshot Capture

ToolDescription
capture_screenshotCapture webcam image of HDMI monitor
list_camerasList available camera indices
set_cameraSelect which camera to use
set_screenshot_cropSet crop region for screenshots
clear_screenshot_cropClear crop region

Video Mode Control

ToolDescription
set_video_modeSet video mode (0-4)
get_video_modeGet current video mode

Video modes:

  • 0: Color bars
  • 1: Grid pattern
  • 2: Grayscale gradient
  • 3: Text mode (80x26)
  • 4: Framebuffer (160x120 RGB332)

Text Mode

ToolDescription
text_clearClear text screen
text_set_cursorSet cursor position
text_set_colorSet text color (CGA 16-color palette)
text_writeWrite text at cursor
text_write_atWrite text at specific position with color

Wishbone Address Map

Address RangePeripheral
0x8010Video mode register
0x8020-0x802BText mode control
0x8100-0x8103RGB LED Controller
0x0000-0x4B00Framebuffer (160x120 RGB332)

Usage Examples

Once the MCP server is configured, you can ask Copilot:

  • "Set the RGB LED to red"
  • "Make the LED blue"
  • "Read the current LED color"
  • "Write 0xFF to address 0x8100"
  • "Switch to text mode"
  • "Write 'Hello World' at position 10,5"
  • "Capture a screenshot"
  • "Run raw command H"

File Structure

papilio_mcp_server/
├── library.json           # PlatformIO library manifest
├── README.md              # This file
├── src/
│   └── PapilioMCP.h       # Header-only library for sketches
├── server/
│   └── papilio_mcp_server.py  # Main MCP server
└── examples/
    ├── mcp_debug_simple/      # Minimal debug firmware
    └── mcp_debug_firmware_full/  # Full-featured debug firmware