Skip to main content

STM32 MCP Build Server

⚠️ 架构升级通知: 当前版本 (v1.0) 采用"复制代码到项目"的安装方式。 v2.0 将重构为 uvx + Docker 标准架构,实现零安装、零污染。 详见 ARCHITECTURE.md 和 Issue #1。

AI自动编译修复系统 - 基于 MCP (Model Context Protocol) 的 STM32 开发平台

🎯 项目目标

构建 MCP Server,实现完整的嵌入式开发闭环:

Agent修改代码 → Build MCP编译 → 解析错误自动修复 → 编译成功 → Flash MCP烧录 → MCU运行

🏗️ 架构版本

v1.0 (当前版本)

安装方式:复制MCP代码到用户项目 + pip install

{
  "mcpServers": {
    "stm32-build": {
      "command": "python3",
      "args": ["-m", "mcp_build.stm32_build_server"]
    }
  }
}

已知问题 (详见 Issue #1):

  • 需要手动安装ARM工具链
  • Makefile兼容性问题 (Windows路径、GCC版本)
  • 安装步骤繁琐 (6步, >20分钟首次安装)
  • 往用户项目复制代码 (非行业标准)

v2.0 (开发中 → feature/uvx-docker-refactor)

安装方式:uvx + Docker,零安装、零污染

{
  "mcpServers": {
    "stm32": {
      "command": "uvx",
      "args": ["stm32-mcp"]
    }
  }
}

改进:

  • ✅ 不复制代码到用户项目
  • ✅ 不污染用户Python环境
  • ✅ 预构建Docker镜像 (legogogoagent/stm32-toolchain:12.3)
  • ✅ Makefile自动修复 (容器内临时副本)
  • ✅ 符合MCP行业标准 (Playwright MCP、SQLite MCP同款模式)

详见 ARCHITECTURE.md


🚀 快速开始 (v1.0)

以下为 v1.0 安装方式。v2.0 发布后将大幅简化。

1. 构建 Docker 镜像

docker build -f docker/Dockerfile -t stm32-toolchain:latest .

2. 验证镜像

docker run --rm stm32-toolchain:latest arm-none-eabi-gcc --version
docker run --rm stm32-toolchain:latest make --version

3. 安装依赖

pip install -r requirements.txt

4. 启动 MCP Server

# STDIO 模式
python -m mcp_build.stm32_build_server

# 或使用 MCP Inspector 调试
uv run mcp dev mcp_build/stm32_build_server.py

5. Agent 调用示例

from agents import Agent
from agents.mcp import MCPServerStdio

async def main():
    async with MCPServerStdio(
        command="python",
        args=["-m", "mcp_build.stm32_build_server"],
        cwd="/path/to/your-project",
    ) as mcp_server:
        agent = Agent(
            name="STM32 Build Agent",
            instructions="...",
            mcp_servers=[mcp_server],
        )
        # ... agent 循环修复逻辑

📁 项目结构

STM32_Complier_MCP/
├── docker/                      # Docker编译环境
│   ├── Dockerfile              # arm-none-eabi-gcc工具链镜像
│   └── flash.Dockerfile        # 烧录工具镜像 (OpenOCD/ST-Link)
├── tools/                       # 编译工具脚本
│   ├── build.sh                # 容器内编译入口脚本
│   └── flash.sh                # 容器内烧录入口脚本
├── mcp_build/                   # Build MCP Server核心代码
│   ├── __init__.py
│   ├── stm32_build_server.py   # Build MCP主程序
│   └── gcc_parse.py            # GCC/LD错误解析器
├── mcp_flash/                   # Flash MCP Server核心代码
│   ├── __init__.py
│   └── stm32_flash_server.py   # Flash MCP主程序
├── ESP32_STM32_Bridge/          # ESP32远程烧录桥接器
│   ├── firmware/               # ESP32 Arduino固件
│   ├── scripts/                # Python客户端
│   └── tests/                  # Flash算法单元测试
├── Test_Data/                   # 测试工程
├── ARCHITECTURE.md             # 架构文档 (v1.0 → v2.0)
├── CHANGELOG.md                # 版本变更日志
└── requirements.txt            # Python依赖

🛡️ 核心原则

原则 说明
MCP只编译,不改代码 源码以只读方式挂载进Docker容器 (:ro)
Agent只改代码,不直接编译 所有编译动作都通过MCP工具调用
结构化错误返回 MCP解析GCC输出,返回file/line/col/message结构化数据
可重复构建环境 使用Docker容器保证编译环境一致性

📋 开发阶段

v1.0 已完成

  • Phase 0: 项目初始化与仓库搭建
  • Phase 1: Docker编译环境 (Dockerfile + build.sh)
  • Phase 2: Build MCP Server (stm32_build_server.py + gcc_parse.py)
  • Phase 3: Flash MCP Server (stm32_flash_server.py)
  • Phase 2.5: ESP32远程烧录桥接器
    • ESP32 Arduino固件 (SWD协议实现)
    • STM32F1xx Flash编程算法
    • STM32F4xx Flash编程算法
    • 73个单元测试
  • Skill: OpenCode Agent Skill (stm32-dev-workflow)

v2.0 开发中

  • 重构为 PyPI 包 (stm32-mcp)
  • uvx stm32-mcp 零安装启动
  • 预构建 Docker 镜像 (legogogoagent/stm32-toolchain:12.3)
  • 多架构支持 (x86_64 + ARM64)
  • Makefile自动修复 (容器内)
  • 增强错误提示 (头文件大小写检测)

🔧 技术栈

  • Language: Python 3.10+
  • MCP Framework: FastMCP (mcp[cli]>=1.26.0)
  • Container: Docker + Ubuntu 24.04
  • Toolchain: arm-none-eabi-gcc (GNU Arm Embedded Toolchain)
  • Build System: GNU Make
  • Target: STM32F1xx / F4xx 系列

📝 许可证

MIT License

🔗 参考文档

Metadata

Release files for stm32-mcp 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stm32-mcp 2.0.0
File Size Uploaded Provenance
stm32_mcp-2.0.0.tar.gz 1.7 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for stm32-mcp 2.0.0
File Interpreter ABI Platform
stm32_mcp-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.7 MB

Release files / stm32_mcp-2.0.0.tar.gz

Download URL stm32_mcp-2.0.0.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
8cc0ca8c5c6acc09965eb241a6a63ba38902e43964f0b435dbe020e5a770122f
BLAKE2b-256 checksum
How to use checksums
8a3c8ba605a3247bf0aa03a9d0972e2478c7eba06ba4a9d3f6aedba2259e6742
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / stm32_mcp-2.0.0-py3-none-any.whl

Download URL stm32_mcp-2.0.0-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa7a5a219d84db8b68b082acc0074b817d1a785e5d34f91a8121718e2e48b154
BLAKE2b-256 checksum
How to use checksums
51e623b978ec74ed4c2ece322167692060832b4f055a412f7361e9b5115fdf0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Security for stm32-mcp 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page