Firmware MCP Server

Firmware MCP Server

A local stdio MCP server for embedded firmware automation that exposes tools to build, flash, reset devices, and capture serial logs through a device configuration file.

Category
访问服务器

README

Firmware MCP Server

中文文档

<p align="center"> <img src="assets/mascot-catgirl.jpg" alt="Firmware MCP Server mascot" width="320"> </p>

Firmware MCP Server is a local stdio MCP server for embedded firmware automation. It exposes a small set of tools that let an MCP client build firmware, flash devices, reset devices, and collect timestamped serial logs through commands defined in a local device configuration file.

The server is designed for workstation-local automation. It does not start an HTTP service, does not execute commands through a shell, and keeps local device paths out of version control by default.

Features

  • Stdio-only MCP server for local clients.
  • Four firmware-oriented tools: build, flash, reset, and serial log capture.
  • Per-device async locks, so operations for the same device are serialized.
  • Concurrent operation across different devices.
  • Config hot reload when the device config file changes.
  • Subprocess execution through asyncio.create_subprocess_exec.
  • Command arguments are explicit arrays and are never passed to shell=True.
  • Serial capture through pyserial, with incremental JSON trace events on stderr.
  • Consistent JSON response envelope for success and failure cases.
  • Lightweight deterministic diagnostics based on tool traces and serial log patterns.

Tools

Tool Purpose
build_firmware Run the configured build command for a device.
flash_firmware Run the configured flash command for a device.
reset_device Run the optional reset command for a device.
read_serial_log Read timestamped serial lines from a device.

build_firmware, flash_firmware, and reset_device accept:

{
  "device_id": "demo",
  "timeout_ms": 300000
}

timeout_ms is optional.

read_serial_log accepts:

{
  "device_id": "demo",
  "duration_ms": 3000,
  "max_lines": 500
}

duration_ms and max_lines are optional.

Response Format

Every tool returns one JSON object encoded as MCP text content.

Success:

{
  "ok": true,
  "data": {},
  "error": null
}

Validation or runtime failure:

{
  "ok": false,
  "data": null,
  "error": {
    "error_type": "VALIDATION_ERROR",
    "type": "VALIDATION_ERROR",
    "message": "device_id must be a non-empty string",
    "recoverable": true
  }
}

Command failures keep captured process details in data:

{
  "ok": false,
  "data": {
    "device_id": "demo",
    "action": "build_firmware",
    "started_at": "2026-01-01T00:00:00.000Z",
    "finished_at": "2026-01-01T00:00:02.000Z",
    "command": ["make"],
    "cwd": "/path/to/project",
    "exit_code": 2,
    "timed_out": false,
    "stdout": "",
    "stderr": "make error"
  },
  "error": {
    "error_type": "BUILD_FAILED",
    "type": "BUILD_FAILED",
    "message": "build_firmware exited with code 2 for device: demo",
    "recoverable": true
  }
}

Requirements

  • Python 3.10 or newer.
  • A local MCP-compatible client.
  • pyserial when using serial log capture.
  • Local build, flash, or reset commands configured per device.

Installation

Clone the repository:

git clone https://github.com/Alooswr/firmware-mcp-server.git
cd firmware-mcp-server

Create a virtual environment:

python -m venv .venv

Activate it on Windows:

.venv\Scripts\activate

Activate it on Linux or macOS:

source .venv/bin/activate

Install the project in editable mode:

python -m pip install -e .

You can also install dependencies directly:

python -m pip install -r requirements.txt

Device Configuration

The default device config path is:

./config/devices.json

Create a local config from the example:

cp config/devices.example.json config/devices.json

On Windows Command Prompt:

copy config\devices.example.json config\devices.json

config/devices.json is intentionally ignored by git because it commonly contains local paths, serial ports, and private build commands.

You can override the config path with FIRMWARE_MCP_DEVICES_CONFIG.

Linux or macOS:

export FIRMWARE_MCP_DEVICES_CONFIG=/path/to/devices.json

Windows Command Prompt:

set FIRMWARE_MCP_DEVICES_CONFIG=C:\path\to\devices.json

Device entry shape:

{
  "device_id": "demo",
  "build": {
    "command": ["make"],
    "cwd": "/path/to/firmware/project"
  },
  "flash": {
    "command": ["make", "flash"],
    "cwd": "/path/to/firmware/project"
  },
  "reset": {
    "command": ["python", "scripts/reset.py"],
    "cwd": "/path/to/firmware/project"
  },
  "serial": {
    "port": "COM3",
    "baudrate": 115200,
    "timeout_ms": 3000
  }
}

Notes:

  • device_id must be unique.
  • build, flash, and serial are required.
  • reset is optional.
  • cwd is optional.
  • command must be a non-empty array of strings.
  • Commands are executed directly and are not interpreted by a shell.

MCP Client Configuration

Example client configuration when running from a cloned repository:

{
  "mcpServers": {
    "firmware": {
      "command": "python",
      "args": ["-m", "firmware_mcp_server"],
      "cwd": "/absolute/path/to/firmware-mcp-server"
    }
  }
}

Example with an explicit device config:

{
  "mcpServers": {
    "firmware": {
      "command": "python",
      "args": ["-m", "firmware_mcp_server"],
      "cwd": "/absolute/path/to/firmware-mcp-server",
      "env": {
        "FIRMWARE_MCP_DEVICES_CONFIG": "/absolute/path/to/devices.json"
      }
    }
  }
}

Run Locally

From the project root:

python -m firmware_mcp_server

The process uses stdio for MCP transport. Regular runtime traces are written to stderr as compact JSON log events.

Diagnostics

The runtime keeps an in-memory diagnostic timeline that combines tool execution traces and serial events. This internal layer does not add public MCP tools and does not change tool response formats.

Serial events are tagged with semantic states:

  • BOOT
  • CRASH
  • HANG
  • REBOOT_LOOP
  • UNKNOWN

The deterministic classifier can return failure types such as:

  • BUILD_FAILED
  • FLASH_FAILED
  • RESET_FAILED
  • CRASH_AFTER_FLASH
  • REBOOT_LOOP
  • NO_BOOT
  • UNKNOWN

Execution trace example:

{
  "event": "tool_execution_trace",
  "tool_name": "build_firmware",
  "device_id": "demo",
  "start_time": "2026-01-01T00:00:00.000Z",
  "end_time": "2026-01-01T00:00:02.000Z",
  "status": "ok"
}

Serial trace example:

{
  "event": "serial_log_line",
  "source": "serial",
  "device_id": "demo",
  "port": "COM3",
  "timestamp": "2026-01-01T00:00:00.000Z",
  "line": "boot",
  "state": "BOOT"
}

Development

Install development dependencies:

python -m pip install -e .

Run tests:

python -m unittest discover -s tests

Check ignored local files:

git status --ignored --short

Security Model

This server runs local commands from your device configuration. Treat devices.json as trusted local configuration and review commands before using them with an MCP client.

Important defaults:

  • No HTTP listener is started.
  • Commands are executed without shell=True.
  • Device-local configuration is excluded from git by default.
  • stdout is reserved for MCP protocol traffic.
  • logs and traces are emitted to stderr.

See SECURITY.md for vulnerability reporting and operational guidance.

Contributing

Contributions are welcome. Please read CONTRIBUTING.md before opening a pull request.

License

This project is licensed under the MIT License.

Image assets are documented separately in ASSETS.md.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选