Serial MCP Server
Enables AI tools like Claude Code and Codex CLI to read and write serial port data, facilitating embedded development workflows such as coding, flashing, and debugging.
README
Serial MCP Server
嵌入式 AI 调试串口 MCP 服务,让 Claude Code / Codex CLI 等 AI 工具能够直接读写串口数据,实现编码→烧录→调试的完整闭环。
功能状态
| 功能 | 状态 |
|---|---|
| 串口连接/断开 | ✅ 稳定 |
| 数据收发 | ✅ 稳定 |
| SQLite 数据持久化 | ✅ 稳定 |
| 多串口并发 | ✅ 稳定 |
| 设备自动检测 | ✅ 稳定 |
| 监控窗口 TUI | ✅ 稳定 |
| 定时发送 | ✅ 稳定 |
| Modbus RTU | 🚧 开发中 |
| Web 监控面板 | 🚧 规划中 |
架构
AI (Claude Code / Codex CLI)
│ MCP Protocol
▼
┌─────────────────┐
│ serial-mcp │ MCP Server (9 tools)
│ server.js │
└────────┬────────┘
│ HTTP POST localhost:7070
▼
┌─────────────────┐ ┌──────────────────┐
│ serial-db │◄──────►│ SQLite │
│ listener.js │ 读写 │ serial.db │
└────────┬────────┘ └──────────────────┘
│ UART COM3
▼
┌─────────────────┐
│ 单片机 / 虚拟 │ COM2 ↔ COM3
│ serial-virtual │
└─────────────────┘
功能
- 实时接收串口数据,持久化到 SQLite
- AI 主动查询历史数据,按 session / 时间范围检索
- AI 发送指令并等待响应,120ms 内响应
- 支持多种响应边界模式(timeout / delimiter / length)
- 虚拟串口模拟器,无需真实硬件即可开发调试
- 一键启动/停止脚本
项目结构
serial-mcp/
├── serial-virtual/ 虚拟单片机模拟器
├── serial-db/ 串口监听 + SQLite 数据池 + HTTP 转发服务
├── serial-mcp/ MCP Server
├── start-all.bat 一键启动
├── stop-all.bat 一键停止
└── .mcp.json Claude Code MCP 配置
依赖
- Node.js v18+
- Windows 系统
- 虚拟串口驱动(开发调试用):ELTIMA VSP 或 com0com
安装
Claude Code
claude mcp add serial -- npx -y @lckandyou/serial-mcp
Codex CLI
codex mcp add serial -- npx -y @lckandyou/serial-mcp
验证是否安装成功
# Claude Code
claude mcp list
# Codex CLI
codex mcp list
看到 serial 状态为 connected 即成功。
使用方式
安装完成后,直接告诉 AI 你的串口信息: "我的设备接在 COM5,波特率 115200,帮我连接并开始调试"
AI 会自动完成连接,无需任何额外配置。
MCP 工具列表
| 工具 | 说明 |
|---|---|
list_ports |
扫描可用串口 |
connect_port |
连接指定串口并创建新会话 |
disconnect_port |
断开当前串口 |
send_data |
发送数据 |
read_latest |
读取最新 N 条数据 |
read_since |
读取指定时间后的数据 |
send_and_wait |
发送指令并等待响应 |
new_session |
创建新会话(烧录后调用) |
get_status |
获取当前串口状态 |
真实硬件接入
- 停止运行
serial-virtual - 把
serial-db/config.json的port改为实际串口号 - 重启
serial-db
无需修改 MCP Server,AI 调试方式完全一致。
FAQ
Q: 为什么 list_ports 看不到 COM2/COM3?
A: ELTIMA VSP 的虚拟端口不走标准 WMI 枚举,但实际通信正常,不影响使用。
Q: 支持 Linux/Mac 吗?
A: 串口通信部分支持,但 start-all.bat 仅限 Windows,Linux/Mac 需手动启动各服务。
Q: 数据库会无限增长吗?
A: 不会,超过 10000 条自动清理最老的数据,可在 serial-db/config.json 的 maxRows 调整。
Q: 如何判断烧录前后的数据?
A: 烧录完成后调用 new_session 创建新会话,后续用 session_id 过滤数据即可。
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.