Serial Mcp Server

io.github.es617由 GitHub 帳號 es617 發布v0.1.3更新於 Oct 24, 2026

Let AI agents interact with serial devices — list ports, connect, send, and read.

已驗證STDIO僅桌面檔案與儲存開發者工具

概覽

AI 產生的概覽

一個本機 MCP 伺服器,讓 AI 助理列出、開啟、讀寫並控制電腦上的真實序列埠裝置。

可以做什麼
列出序列埠,依可設定的鮑率、同位檢查、停止位與編碼開啟或關閉連線,並查看連線狀態或已開啟的連線清單。以文字、十六進位或 base64 讀寫資料,支援 readline 與讀到指定分隔符,並可清空輸入輸出緩衝區。設定或脈衝 DTR、RTS 控制線,用於硬體重置與進入開機模式。註冊、附加、搜尋與讀取描述裝置指令與訊息格式的 Markdown 協定規格。載入與重新載入裝置外掛以增加高階快捷工具,並檢視工具呼叫追蹤。可將工作階段鏡像到 PTY,讓 screen、minicom 或腳本同時接入。
適用情境
適合嵌入式工程師、創客、測試與現場工程師,讓助理與微控制器等序列埠硬體對話:偵錯開機訊息與提示字元、迭代韌體、執行可重複的重置加指令測試流程,或探索未知裝置的協定。
執行需求
以 PyPI 套件 serial-mcp-server 透過 stdio 在本機執行(用 pip 安裝後註冊 serial_mcp 指令)。需要 Python 與本機序列埠存取權限,支援 macOS、Windows 與 Linux。選用環境變數可設定連線上限、外掛策略、PTY 鏡像、追蹤與工具名稱分隔符。
安裝前請注意
它會操作真實硬體:錯誤的寫入可能抹除快閃記憶體、進入開機模式或觸發致動器。外掛以伺服器完整權限執行任意 Python 程式碼,且助理可自行產生外掛,載入前應審查,並優先指定具體外掛而非 all。工具呼叫追蹤預設開啟並寫入本機追蹤檔;除非啟用 SERIAL_MCP_TRACE_PAYLOADS,寫入內容會被移除。未啟用 PTY 鏡像時,伺服器獨占該序列埠。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Serial Mcp Server,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

Serial MCP Server

[MCP] [License: MIT] [Python] [Serial]

A stateful serial port Model Context Protocol (MCP) server for developer tooling and AI agents. Works out of the box with Claude Code, VS Code with Copilot, and any MCP-compatible runtime. Communicates over stdio and uses pyserial for cross-platform serial on macOS, Windows, and Linux.

Example: Let Claude Code list available serial ports, connect to your microcontroller, reset it via DTR, and read the boot banner from your hardware.

Demo

Video walkthrough — connecting to a serial device, sending commands, reading responses, and creating plugins.


Why this exists

If you’ve ever copy-pasted commands into screen or minicom, guessed baud rates, toggled DTR to kick a bootloader, and re-run the same test sequence 20 times — this is for you.

You have a serial device. You want an AI agent to talk to it — open a port, send commands, read responses, debug protocols. This server makes that possible.

It gives any MCP-compatible agent a full set of serial tools: listing ports, opening connections, reading, writing, line-oriented I/O, control line manipulation — plus protocol specs and device plugins, so the agent can reason about higher-level device behavior instead of just raw bytes.

The agent calls these tools, gets structured JSON back, and reasons about what to do next — without you manually typing commands into a terminal for every step.

What agents can do with it:

  • Develop and debug — connect to your device, send commands, read responses, and diagnose issues conversationally (boot banners, prompts, error codes).
  • Iterate on new firmware — attach a protocol spec so the agent understands your command set, boot modes, and output format as they evolve.
  • Automate test flows — reset device via DTR, wait for prompt, run a command sequence, validate output.
  • Explore unknown devices — probe command sets, discover prompts, infer message formats.
  • Build serial automation — long-running test rigs, manufacturing bring-up, CI hardware smoke tests.

Who is this for?

  • Embedded engineers — faster iteration on serial protocols, conversational debugging, automated test sequences
  • Hobbyists and makers — interact with serial devices without writing boilerplate; let the agent help reverse-engineer simple protocols
  • QA and test engineers — build repeatable serial test suites with plugin tools
  • Support and field engineers — diagnose serial device issues interactively without specialized tooling
  • Researchers — automate data collection from serial devices, explore device capabilities systematically

Quickstart (Claude Code)

bash
pip install serial-mcp-server
# Register the MCP server with Claude Codeclaude mcp add serial -- serial_mcp

Then in Claude Code, try:

"List available serial ports and connect to the one on /dev/ttyUSB0 at 115200 baud."

[Scanning serial ports]


What the agent can do

Once connected, the agent has full serial capabilities:

  • List ports to find available serial devices
  • Open and close connections with configurable baud rate, parity, stop bits, and encoding
  • Read and write data in text, hex, or base64 format
  • Line-oriented I/O — readline and read-until-delimiter for text protocols
  • Control lines — set or pulse DTR and RTS for hardware reset and boot mode entry
  • Flush input and output buffers
  • Attach protocol specs to understand device-specific commands and data formats
  • Use plugins for high-level device operations instead of raw reads/writes
  • Create specs and plugins for new devices so future sessions start "knowing" your protocol
  • PTY mirroring — attach screen, minicom, or custom scripts to the same serial session the agent is using

The agent can coordinate multi-step flows automatically — e.g., toggle reset, wait for prompt, send init sequence, stream output.

At a high level:

Raw Serial → Protocol Spec → Plugin

You can start with raw serial tools, then move up the stack as your device protocol becomes understood and repeatable.


Install (development)

bash
# Editable install from repo rootpip install -e .
# Or with uvuv pip install -e .

MCP is a protocol — this server works with any MCP-compatible client. Below are setup instructions for the most common ones.

Add to Claude Code

bash
# Standard setupclaude mcp add serial -- serial_mcp
# Or run as a moduleclaude mcp add serial -- python -m serial_mcp_server
# Enable all pluginsclaude mcp add serial -e SERIAL_MCP_PLUGINS=all -- serial_mcp
# Enable specific plugins onlyclaude mcp add serial -e SERIAL_MCP_PLUGINS=mydevice,ota -- serial_mcp
# Debug loggingclaude mcp add serial -e SERIAL_MCP_LOG_LEVEL=DEBUG -- serial_mcp

Add to VS Code / Copilot

Add to your project's .vscode/mcp.json (or create it):

json
{  "servers": {    "serial": {      "type": "stdio",      "command": "serial_mcp",      "args": [],      "env": {        "SERIAL_MCP_PLUGINS": "all"      }    }  }}

Adjust env to match your needs — set SERIAL_MCP_PLUGINS to specific plugin names, or add SERIAL_MCP_MIRROR for PTY mirroring.

Add to Cursor

Add to your project's .cursor/mcp.json (or create it). Cursor does not support dots in tool names, so SERIAL_MCP_TOOL_SEPARATOR must be set to _:

json
{  "mcpServers": {    "serial": {      "command": "serial_mcp",      "args": [],      "env": {        "SERIAL_MCP_PLUGINS": "all",        "SERIAL_MCP_TOOL_SEPARATOR": "_"      }    }  }}

Environment variables

VariableDefaultDescription
SERIAL_MCP_MAX_CONNECTIONS10Maximum simultaneous open serial connections.
SERIAL_MCP_PLUGINSdisabledPlugin policy: all to allow all, or name1,name2 to allow specific plugins. Unset = disabled.
SERIAL_MCP_MIRRORoffPTY mirror mode: off, ro (read-only), or rw (read-write). macOS and Linux only.
SERIAL_MCP_MIRROR_LINK/tmp/serial-mcpBase path for PTY symlinks. Connections get numbered: /tmp/serial-mcp0, /tmp/serial-mcp1, etc.
SERIAL_MCP_LOG_LEVELWARNINGPython log level (DEBUG, INFO, WARNING, ERROR). Logs go to stderr.
SERIAL_MCP_TRACEenabledJSONL tracing of every tool call. Set to 0, false, or no to disable.
SERIAL_MCP_TRACE_PAYLOADSdisabledInclude write data in traced args (stripped by default).
SERIAL_MCP_TRACE_MAX_BYTES16384Max payload chars before truncation (only applies when TRACE_PAYLOADS is on).
SERIAL_MCP_TOOL_SEPARATOR.Character used to separate tool name segments. Set to _ for MCP clients that reject dots in tool names (e.g. Cursor).

Tools

CategoryTools
Serial Coreserial.list_ports, serial.open, serial.close, serial.connection_status, serial.read, serial.write, serial.readline, serial.read_until, serial.flush, serial.set_dtr, serial.set_rts, serial.pulse_dtr, serial.pulse_rts
Introspectionserial.connections.list
Protocol Specsserial.spec.template, serial.spec.register, serial.spec.list, serial.spec.attach, serial.spec.get, serial.spec.read, serial.spec.search
Tracingserial.trace.status, serial.trace.tail
Pluginsserial.plugin.template, serial.plugin.list, serial.plugin.reload, serial.plugin.load

Protocol Specs

Specs are markdown files that describe a serial device's protocol — connection settings, message format, commands, and multi-step flows. They live in .serial_mcp/specs/ and teach the agent what the byte stream means.

Without a spec, the agent can still open a port and exchange data. With a spec, it knows what commands to send, what responses to expect, and what the data means.

You can create specs by telling the agent about your device — paste a datasheet, describe the protocol, or just let it explore and document what it finds. The agent generates the spec file, registers it, and references it in future sessions. You can also write specs by hand.


Plugins

Plugins add device-specific shortcut tools to the server. Instead of the agent composing raw read/write sequences, a plugin provides high-level operations like mydevice.read_temp or ota.upload_firmware.

The agent can also generate Python plugins (with your approval). It explores a device, writes a plugin based on what it learns, and future sessions get shortcut tools — no manual coding required.

To enable plugins:

bash
# Enable all pluginsclaude mcp add serial -e SERIAL_MCP_PLUGINS=all -- serial_mcp
# Enable specific plugins onlyclaude mcp add serial -e SERIAL_MCP_PLUGINS=mydevice,ota -- serial_mcp

Editing an already-loaded plugin only requires serial.plugin.reload — no restart needed.


Tracing

Every tool call is traced to .serial_mcp/traces/trace.jsonl and an in-memory ring buffer (last 2000 events). Tracing is on by default — set SERIAL_MCP_TRACE=0 to disable.

Event format

Two events per tool call:

jsonl
{"ts":"2025-01-01T00:00:00.000Z","event":"tool_call_start","tool":"serial.read","args":{"connection_id":"s1"},"connection_id":"s1"}{"ts":"2025-01-01T00:00:00.050Z","event":"tool_call_end","tool":"serial.read","ok":true,"error_code":null,"duration_ms":50,"connection_id":"s1"}
  • connection_id is extracted from args when present
  • Write data is stripped from traced args by default (enable with SERIAL_MCP_TRACE_PAYLOADS=1)

Inspecting the trace

Use serial.trace.status to check config and event count, and serial.trace.tail to retrieve recent events — no need to read the file directly.


PTY Mirror

When the MCP server owns a serial port, most OSes prevent any other process from opening it. PTY mirroring creates a virtual clone port that external tools (screen, minicom, logic analyzers, custom scripts) can connect to simultaneously.

bash
# Enable read-only mirrorclaude mcp add serial \  -e SERIAL_MCP_MIRROR=ro \  -- serial_mcp
# After opening a connection, the response includes the mirror path:# { "mirror": { "pty_path": "/dev/ttys004", "link": "/tmp/serial-mcp0", "mode": "ro" } }
# In another terminal:screen /tmp/serial-mcp0 115200
ModeBehavior
offNo mirror (default). Only the MCP server can access the port.
roExternal tools see all serial data but cannot write to the device.
rwExternal tools can both see data and write to the device.

Platform: macOS and Linux only. On Windows, setting SERIAL_MCP_MIRROR to ro/rw logs a warning and is silently ignored.


Try without an agent

You can test the server interactively using the MCP Inspector — no Claude or other agent needed:

bash
npx @modelcontextprotocol/inspector python -m serial_mcp_server

Open the URL with the auth token from the terminal output. The Inspector gives you a web UI to call any tool and see responses in real time.


Known limitations

  • Single-client only. The server handles one MCP session at a time (stdio transport). Multi-client transports (HTTP/SSE) may be added later.
  • Exclusive access. Without PTY mirroring, the MCP server must own the serial port exclusively.

Safety

This server connects an AI agent to real hardware. That's the point — and it means the stakes are higher than pure-software tools.

Plugins execute arbitrary code. When plugins are enabled, the agent can create and run Python code on your machine with full server privileges. Review agent-generated plugins before loading them. Use SERIAL_MCP_PLUGINS=name1,name2 to allow only specific plugins rather than all.

Writes affect real devices. A bad command sent to a serial device can trigger unintended behavior, disrupt other connected systems, or cause hardware damage (e.g., wiping flash, entering bootloader mode, triggering actuators). Consider what the agent can reach.

Use tool approval deliberately. When your MCP client prompts you to approve a tool call, consider whether you want to allow it once or always. "Always allow" is convenient but means the agent can repeat that action without further confirmation.

This software is provided as-is under the MIT License. You are responsible for what the agent does with your hardware.


License

This project is licensed under the MIT License — see LICENSE for details.

Acknowledgements

This project is built on top of the excellent pyserial library for cross-platform serial communication in Python.

來源:README.md,提交 b940b84

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.1.3最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分