stm32-mcp
stm32-mcp is a headless MCP server that drives the official STM32 toolchain from the command line, letting AI coding agents create, configure, build, and flash STM32 firmware without any GUI.
Check the environment (
stm32_doctor): reports resolved tool paths, versions, installed HAL firmware packages, ST-LINK probe connectivity, and any problems (missing packages, non-ASCII home path, missing driver).Create projects (
stm32_create_project): generates a full STM32 project from name, MCU (e.g. STM32F103C8Tx), path, optional pins, clock settings/preset, and debug interface (SWD/JTAG/none).Inspect projects (
stm32_read_project): summarizes an existing.ioc— MCU, clock tree, configured pins, enabled peripherals, and FreeRTOS status.Configure pins (
stm32_configure_pins): idempotently applies/updates pin assignments, modes, and labels in the.iocand regenerates code.Generate HAL code (
stm32_generate_code): runs STM32CubeMX headlessly (config load + project generate) on an existing.ioc.Safely edit user code (
stm32_patch_user_code): inserts content only inside matching/* USER CODE BEGIN/END */blocks (replace or append), failing loudly on missing/unbalanced markers so regeneration never wipes logic.Build firmware (
stm32_build): headless CubeIDE compilation returning structured GCC diagnostics (severity, file, line, column, message), a short summary, and Flash/RAM usage instead of raw logs.Clean artifacts (
stm32_clean): deletes build output folders; requires explicitconfirm: true.Flash hardware (
stm32_flash): programs the target MCU via STM32_Programmer_CLI over SWD/JTAG with optional reset; requires explicitconfirm: true.
Backed by pre-flight ASCII path validation, shell-free spawn execution, safety confirmation gates, and zero credential scraping.
Provides integration with the STMicroelectronics STM32 toolchain, enabling headless creation, configuration, code generation, building, cleaning, and flashing of STM32 firmware projects via CubeMX, CubeIDE, and STM32 Programmer CLI.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@stm32-mcp @stm32-mcp build the firmware in my project directory"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
stm32-mcp
Headless Model Context Protocol (MCP) server driving the official STMicroelectronics STM32 toolchain from the command line.
Automates project creation, pin configuration, HAL code generation, compilation, diagnostics parsing, and hardware flashing for AI coding assistants—including Claude Code and Google Antigravity—without launching a GUI.
Quick Start
1. Install & Build
This package is currently built from source:
git clone https://github.com/irrumi/stm32-mcp.git
cd stm32-mcp
npm install
npm run build
npm test2. Configure Your AI Client
Claude Code
Add to your project or user configuration:
{
"mcpServers": {
"stm32": {
"command": "node",
"args": ["<ABSOLUTE_PATH_TO_STM32_MCP>/dist/index.js"]
}
}
}Or install the packaged manifest:
claude plugin add <ABSOLUTE_PATH_TO_STM32_MCP>Google Antigravity
Add to ~/.gemini/antigravity/mcp_config.json (or workspace MCP settings):
{
"mcpServers": {
"stm32": {
"command": "node",
"args": ["C:/path/to/stm32-mcp/dist/index.js"]
}
}
}Install the firmware development skill:
# Windows PowerShell
Copy-Item -Recurse -Path ".\skills\stm32-firmware" -Destination "$HOME\.gemini\antigravity\skills\"Generic MCP Clients (Cursor, Claude Desktop)
Add to your MCP client config (claude_desktop_config.json):
{
"mcpServers": {
"stm32": {
"command": "node",
"args": ["/path/to/stm32-mcp/dist/index.js"]
}
}
}Related MCP server: stmctl-mcp
What Happens When You Run It
In your AI chat, ask your assistant:
"Run stm32_doctor to check my STM32 toolchain health."
The assistant calls stm32_doctor and receives structured JSON:
{
"status": "ok",
"discovery": {
"cubeIdePath": "C:\\ST\\STM32CubeIDE_1.19.0\\STM32CubeIDE\\stm32cubeidec.exe",
"cubeMxJarPath": "C:\\ST\\STM32CubeIDE_1.19.0\\STM32CubeIDE\\plugins\\...\\STM32CubeMX.jar",
"programmerCliPath": "C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeProgrammer\\bin\\STM32_Programmer_CLI.exe",
"gccPath": "C:\\ST\\STM32CubeIDE_1.19.0\\STM32CubeIDE\\plugins\\...\\arm-none-eabi-gcc.exe",
"installedFamilies": [
{ "family": "F1", "version": "1.8.6", "path": "C:\\Users\\user\\STM32Cube\\Repository\\STM32Cube_FW_F1_V1.8.6" }
],
"stlinkDetected": true
},
"problems": [],
"recommendations": []
}When building a project (stm32_build), instead of dumping thousands of raw log lines, the server parses GCC output and returns structured diagnostics with Flash and RAM usage:
{
"success": true,
"summary": "Build completed successfully for blinky-f103/Debug. (0 errors, 0 warnings)\nMemory usage: Flash: 4548 bytes, RAM: 1592 bytes.",
"diagnostics": [],
"memory": {
"text": 4528,
"data": 20,
"bss": 1572,
"total": 6120,
"flashBytes": 4548,
"ramBytes": 1592
}
}Why stm32-mcp?
Developing embedded firmware on STM32 has traditionally relied on desktop graphical interfaces: the Eclipse-based STM32CubeIDE and the Java-based STM32CubeMX.
AI coding assistants cannot interact with desktop GUIs, and driving the ST command-line utilities directly presents severe practical obstacles:
Path-Encoding Crashes: ST's legacy CLI tools fail or produce corrupted builds when file paths contain non-ASCII characters (e.g. Cyrillic or accented Latin) on Windows.
Headless Build Complexity: The Eclipse CDT headless builder requires specific console binaries (
stm32cubeidec.exe), isolated workspace arguments (-data), and explicit target MCU metadata in.cproject.Destructive Regeneration: Running STM32CubeMX code generation permanently wipes application logic unless code is strictly isolated inside matching
/* USER CODE BEGIN */and/* USER CODE END */comments.Context Window Exhaustion: Compiler stdout often exceeds 10,000 lines of build chatter, wasting tokens and degrading agent reasoning.
stm32-mcp wraps the entire ST toolchain in a clean, typed Model Context Protocol interface with pre-flight path validation, safe code-block patching, structured diagnostics, and safety confirmation gates.
Architecture & Workflow
flowchart LR
Agent["AI Coding Agent<br/>(Claude Code / Antigravity / Cursor)"] <-->|"MCP (JSON-RPC stdio)"| Server["stm32-mcp Server"]
Server --> Doctor["Toolchain Discovery<br/>(Auto-detects IDE, MX, CLI, GCC)"]
Server --> CubeMX["STM32CubeMX (-q)<br/>Headless Code Generation"]
Server --> CubeIDE["Eclipse CDT Builder<br/>Headless Compilation"]
Server --> Programmer["STM32_Programmer_CLI<br/>Target Flashing (SWD/JTAG)"]
CubeIDE --> Parser["Diagnostics & Memory Parser<br/>Flash / RAM Metrics"]
Programmer --> Hardware["Target STM32 Hardware<br/>(Blue Pill, Nucleo, Discovery)"]Key Features
100% Headless Operation: Never launches a GUI. Executes STM32CubeMX in quiet script mode (
-q), Eclipse CDT via the console runner (stm32cubeidec.exe), and flashing viaSTM32_Programmer_CLI.exe.Structured Compiler Diagnostics: Parses GCC warnings, errors, and notes into typed
{ severity, file, line, column, message }records. Reports Flash and RAM memory metrics fromarm-none-eabi-size.Pre-Flight ASCII Path Guard: Intercepts and rejects non-ASCII paths immediately with diagnostic guidance before invoking external ST tools.
Safe User Code Injection:
stm32_patch_user_codevalidates marker pairing and balance before modifying files, guaranteeing that CubeMX regeneration never destroys application logic.Safety Confirmation Gates: Destructive operations (
stm32_cleanandstm32_flash) require explicitconfirm: trueto prevent unintended file deletion or unwanted hardware programming.Zero Credential Scraping: Never requests, stores, or scrapes ST account logins. If an MCU firmware package is missing, the tool returns a direct link and folder location for manual download.
Tool Reference
The server exposes 9 dedicated MCP tools:
Tool | Parameters | Description |
| (none) | Reports paths, tool versions, installed MCU HAL firmware packages, and ST-LINK probe connectivity. |
|
| Generates a complete STM32 project: |
|
| Reads and parses |
|
| Idempotently updates pin assignments, modes, and labels in |
|
| Runs STM32CubeMX in headless script mode to generate HAL initialization and peripheral code. |
|
| Safely inserts code inside matching |
|
| Headless compilation via CubeIDE builder; returns structured diagnostics and Flash/RAM usage. |
|
| Deletes build output folders ( |
|
| Programs target MCU via ST-LINK ( |
End-to-End Walkthrough: Blinky on STM32F103
A verified reference project is included at examples/blinky-f103. Here is the typical workflow:
1. Verify Environment
// Tool: stm32_doctor
{}2. Create Project
// Tool: stm32_create_project
{
"name": "blinky-f103",
"mcu": "STM32F103C8Tx",
"path": "C:/projects/stm32/blinky-f103",
"debug": "swd"
}3. Configure Status LED Pin
// Tool: stm32_configure_pins
{
"projectPath": "C:/projects/stm32/blinky-f103",
"pins": [
{ "pin": "PC13", "mode": "GPIO_Output", "label": "LED_STATUS" }
]
}4. Generate HAL Initialization Code
// Tool: stm32_generate_code
{
"projectPath": "C:/projects/stm32/blinky-f103"
}5. Add Non-Blocking Superloop Logic
// Tool: stm32_patch_user_code
{
"file": "C:/projects/stm32/blinky-f103/Core/Src/main.c",
"section": "WHILE",
"mode": "replace",
"content": " static uint32_t last_tick = 0;\n if (HAL_GetTick() - last_tick >= 500) {\n last_tick = HAL_GetTick();\n HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);\n }"
}6. Build Firmware
// Tool: stm32_build
{
"projectPath": "C:/projects/stm32/blinky-f103",
"configuration": "Debug"
}7. Flash Target Microcontroller
// Tool: stm32_flash
{
"elfPath": "C:/projects/stm32/blinky-f103/Debug/blinky-f103.elf",
"port": "SWD",
"reset": true,
"confirm": true
}Supported Environments & Prerequisites
System Requirements
Node.js: >= 20.0.0
Operating Systems: Windows 10/11 (primary target), Linux, macOS
STM32CubeIDE: 1.15.0 through 1.19.0 (installed at default path
C:\ST\STM32CubeIDE_*or/opt/st/stm32cubeide)STM32Cube MCU Packages: Download target packages (e.g.
STM32Cube_FW_F1_V1.8.6) from st.com and extract into~/STM32Cube/Repository.
Environment Variable Overrides
If tools are installed in custom locations, set the corresponding environment variables:
Variable | Target Executable / Directory |
| Directory containing |
| Path to |
| Path to |
| Path to |
Safety & Process Security
Process Execution: All external commands are executed using
child_process.spawnwith discrete argument arrays andshell: false. Shell interpolation is strictly prevented.Safety Gates: Deleting build artifacts (
stm32_clean) or programming hardware flash (stm32_flash) requires an explicitconfirm: trueparameter.Path Sanitization: All file paths are validated against ASCII characters prior to filesystem or process execution.
Repository Structure
stm32-mcp/
├── .claude-plugin/ # Claude Code plugin manifest
├── antigravity/ # Google Antigravity MCP configuration & docs
├── examples/
│ └── blinky-f103/ # Reference STM32F103 Blue Pill project
├── skills/
│ └── stm32-firmware/ # Agent skill definitions and firmware lifecycle guide
├── src/
│ ├── discovery.ts # ST toolchain auto-discovery
│ ├── index.ts # CLI entry point (stdio transport)
│ ├── server.ts # MCP server setup & tool registration
│ ├── ioc/ # .ioc parser, writer, and CDT project generator
│ ├── parsers/ # GCC diagnostic & size output parsers
│ ├── patcher/ # Safe USER CODE block extraction and patching
│ ├── tools/ # 9 MCP tool implementations
│ └── utils/ # ASCII path validator & safe process spawn
├── test/ # 45 Vitest unit and integration tests
├── CONTRIBUTING.md # Contribution guide & architecture rules
└── package.jsonDevelopment & Testing
# Run unit and integration tests
npm test
# Build TypeScript to dist/
npm run build
# Run in watch mode during development
npm run watchSee CONTRIBUTING.md for architecture rules, coding standards, and guidelines for adding MCU presets.
License
Available Tools
9 toolsstm32_buildA
Headless build. Returns structured diagnostics: {severity, file, line, column, message} parsed out of the GCC output, plus a short summary and the flash/RAM usage from the size output. Do not dump raw logs into the model context.
Inputs: projectPath (required), clean, configuration.
stm32_cleanA
Clean build artifacts. Flashing hardware and deleting files require an explicit confirm: true argument. Default is refuse.
Inputs: projectPath (required), confirm.
stm32_configure_pinsA
Patches pin config in an existing .ioc and regenerates. Idempotent.
Inputs: pins (required), projectPath (required).
stm32_create_projectA
Args: name, mcu (e.g. STM32F103C8Tx), path, pins[] ({pin, mode, label}), clock ({hse_hz, sysclk_hz} or a named preset), debug (swd/jtag/none). Writes a valid .ioc and generates the CubeIDE project.
Inputs: mcu (required), name (required), path (required), pins, +2 more.
stm32_doctorA
Reports resolved paths, versions, installed FW packages, and every problem found (missing package, non-ASCII home path, missing ST-LINK driver). Run this first; every other tool should suggest it on failure.
Inputs: no named parameters.
stm32_flashC
STM32_Programmer_CLI -c port=SWD -w -rst. Requires confirm: true. Default is refuse.
Inputs: elfPath (required), port, reset, confirm.
stm32_generate_codeA
Runs CubeMX config load + project generate on an existing .ioc.
Inputs: projectPath (required).
stm32_patch_user_codeA
Args: file, section (e.g. PD, 2, WHILE, 4), content, mode (replace/append). Writes only between /* USER CODE BEGIN x / and / USER CODE END x */. Must fail loudly if the markers are missing or unbalanced, and must never touch generated init functions.
Inputs: file (required), content (required), section (required), mode.
stm32_read_projectA
Summarises an existing project: MCU, clock tree, configured pins, enabled peripherals, whether FreeRTOS is on. Reads the .ioc, not the generated code.
Inputs: projectPath (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Each tool maps to a distinct lifecycle phase: diagnose, create, configure pins, generate, patch user code, build, clean, flash, and read project state. Even create_project and generate_code are clearly separated by whether an .ioc already exists, so an agent can select appropriately.
All tools share a consistent stm32_ prefix and use snake_case, with the majority following verb_noun pattern (create_project, configure_pins, generate_code, patch_user_code, read_project). The stm32_doctor name is the main deviation, since it is noun-like rather than verb_object, but it remains recognizable and consistent with the set's style.
The set has 9 tools, which is well within the ideal range and matches the server's stated purpose of covering an STM32 project workflow from diagnostics through flashing. Each tool has a clear role and none feel redundant or superficial.
The tool surface covers the main project lifecycle well: create, configure, generate, patch, build, clean, flash, and read state. A minor gap is that clock or peripheral configuration cannot be changed after project creation except through existing pin configuration, and there is no explicit erase/reset tool, but these are workable limitations.
Maintenance
Related MCP Connectors
Run, build, and validate firmware on virtual hardware from your AI agent. Hardware knowledge corpus.
Design circuits, simulate and verify embedded firmware, and lay out PCBs with AI agents.
Create, run and manage Homemade dev VMs and projects from your AI agent.
Build, validate, test-run and publish AIOS workflows from Claude Code, Codex, Cursor or VS Code.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables Claude Code to build, flash, and communicate with STM32 hardware over SWD and serial, including multi-board management, live memory monitoring, and hardware sequences.26MIT
- AlicenseAqualityDmaintenanceEnables AI assistants to flash firmware, program memory, modify option bytes, erase chips, reset boards, and capture SWO printf traces for STM32 microcontrollers via STM32CubeCLT.12MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that lets AI coding agents drive the full STM32 development loop—code generation, build, flash, debug, serial monitoring, and fault diagnosis—end to end via CubeIDE, CubeMX, CubeProgrammer, OpenOCD, and GDB.1MIT
- AlicenseAqualityCmaintenanceThis server enables AI agents to fully control STM32CubeIDE and STMicroelectronics hardware, including GUI automation, headless builds, flashing, GDB debugging, option bytes, serial telemetry, and CubeMX .ioc engineering.342Apache 2.0