Skip to main content
Glama

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.


Related MCP server: UART MCP Server

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)

pip install serial-mcp-server

# Register the MCP server with Claude Code
claude 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."


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)

# Editable install from repo root
pip install -e .

# Or with uv
uv 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

# Standard setup
claude mcp add serial -- serial_mcp

# Or run as a module
claude mcp add serial -- python -m serial_mcp_server

# Enable all plugins
claude mcp add serial -e SERIAL_MCP_PLUGINS=all -- serial_mcp

# Enable specific plugins only
claude mcp add serial -e SERIAL_MCP_PLUGINS=mydevice,ota -- serial_mcp

# Debug logging
claude 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):

{
  "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 _:

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

Environment variables

Variable

Default

Description

SERIAL_MCP_MAX_CONNECTIONS

10

Maximum simultaneous open serial connections.

SERIAL_MCP_PLUGINS

disabled

Plugin policy: all to allow all, or name1,name2 to allow specific plugins. Unset = disabled.

SERIAL_MCP_MIRROR

off

PTY mirror mode: off, ro (read-only), or rw (read-write). macOS and Linux only.

SERIAL_MCP_MIRROR_LINK

/tmp/serial-mcp

Base path for PTY symlinks. Connections get numbered: /tmp/serial-mcp0, /tmp/serial-mcp1, etc.

SERIAL_MCP_LOG_LEVEL

WARNING

Python log level (DEBUG, INFO, WARNING, ERROR). Logs go to stderr.

SERIAL_MCP_TRACE

enabled

JSONL tracing of every tool call. Set to 0, false, or no to disable.

SERIAL_MCP_TRACE_PAYLOADS

disabled

Include write data in traced args (stripped by default).

SERIAL_MCP_TRACE_MAX_BYTES

16384

Max 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

Category

Tools

Serial Core

serial.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

Introspection

serial.connections.list

Protocol Specs

serial.spec.template, serial.spec.register, serial.spec.list, serial.spec.attach, serial.spec.get, serial.spec.read, serial.spec.search

Tracing

serial.trace.status, serial.trace.tail

Plugins

serial.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:

# Enable all plugins
claude mcp add serial -e SERIAL_MCP_PLUGINS=all -- serial_mcp

# Enable specific plugins only
claude 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:

{"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.

# Enable read-only mirror
claude 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

Mode

Behavior

off

No mirror (default). Only the MCP server can access the port.

ro

External tools see all serial data but cannot write to the device.

rw

External 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:

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.

Available Tools

27 tools
serial.closeB

Close a serial port connection and release the port.

Inputs: connection_id (required).

serial.connections.listA

List all open serial connections with their status, port, configuration, and timestamps. Useful for recovering connection IDs after context loss.

Inputs: no named parameters.

serial.connection_statusA

Check whether a serial connection is still open and return its configuration.

Inputs: connection_id (required).

serial.flushB

Flush serial port buffers (discard pending input/output data).

Inputs: connection_id (required), what.

serial.list_portsA

List available serial ports on the system.

Inputs: no named parameters.

serial.openA

Open a serial port connection. Returns a connection_id for use with other serial tools. The port stays open across tool calls until serial.close is called or the server exits. Defaults are 115200 baud, 8N1, \r\n line terminator — the most common settings. If you don't know the correct settings, check for a protocol spec with serial.spec.list or ask the user. Wrong baud rate is the most common cause of garbled data. After opening: 1) Use serial.spec.list to check for a matching protocol spec. If a match is found, attach it with serial.spec.attach. 2) Use serial.plugin.list to check for a plugin that matches the device. If a matching plugin is loaded, its tools are available to use directly. 3) Do a serial.read to check for any buffered data — many devices send a boot banner, prompt, or status message on connection.

Inputs: port (required), baudrate, bytesize, parity, +6 more.

serial.plugin.listA

List loaded plugins with their tool names and metadata. Each plugin may include a 'meta' dict with matching hints like device_name_contains or description — use these to determine which plugin fits the connected device. Also returns whether plugins are enabled and the current policy. Plugins require SERIAL_MCP_PLUGINS env var — set to 'all' for all or 'name1,name2' to allow specific plugins. If disabled, tell the user to set this variable when adding the MCP server.

Inputs: no named parameters.

serial.plugin.loadB

Load a new plugin from a file or directory path. Requires SERIAL_MCP_PLUGINS env var to be set.

Inputs: path (required).

serial.plugin.reloadA

Hot-reload a plugin by name. Re-imports the module and refreshes tools. Requires SERIAL_MCP_PLUGINS env var to be set.

Inputs: name (required).

serial.plugin.templateA

Return a Python plugin template. Use this when creating a new plugin. Optionally pre-fill with a device name. Save the result to .serial_mcp/plugins/.py, fill in the tools and handlers, then load with serial.plugin.load.

Inputs: device_name.

serial.pulse_dtrA

Pulse the DTR line: sets low, waits duration_ms, then sets high. Commonly used to reset microcontrollers (e.g. Arduino, ESP32). Check the protocol spec or ask the user before pulsing — effect is device-specific.

Inputs: connection_id (required), duration_ms.

serial.pulse_rtsA

Pulse the RTS line: sets low, waits duration_ms, then sets high. Some devices use RTS to enter bootloader mode. Check the protocol spec or ask the user before pulsing — effect is device-specific.

Inputs: connection_id (required), duration_ms.

serial.readA

Read up to nbytes from a serial port. Returns immediately with whatever data is available within the timeout. Use serial.readline or serial.read_until for line-oriented reads.

Inputs: connection_id (required), nbytes, timeout_ms, as.

serial.readlineA

Read a line from the serial port (reads until the newline character is received or max_bytes is reached). Uses the connection's newline setting by default.

Inputs: connection_id (required), timeout_ms, max_bytes, newline, +1 more.

serial.read_untilB

Read from the serial port until a delimiter string is received or max_bytes is reached.

Inputs: connection_id (required), delimiter, timeout_ms, max_bytes, +1 more.

serial.set_dtrB

Set the DTR (Data Terminal Ready) control line. Usage is device-specific — check the protocol spec or ask the user.

Inputs: connection_id (required), value (required).

serial.set_rtsB

Set the RTS (Request To Send) control line. Usage is device-specific — check the protocol spec or ask the user.

Inputs: connection_id (required), value (required).

serial.spec.attachA

Attach a registered spec to a connection session (in-memory only). The spec will be available via serial.spec.get for the duration of this connection. After attaching, check serial.plugin.list for a matching plugin, then present the user with their options: interact with the device using the spec (send commands, execute flows), use plugin shortcut tools if a plugin is loaded, extend an existing plugin with new tools, or create a new plugin using serial.plugin.template.

Inputs: connection_id (required), spec_id (required).

serial.spec.getA

Get the attached spec for a connection (returns null if none attached).

Inputs: connection_id (required).

serial.spec.listA

List all registered specs with their metadata and matching hints.

Inputs: no named parameters.

serial.spec.readC

Read full spec content, file path, and metadata by spec_id.

Inputs: spec_id (required).

serial.spec.registerA

Register a spec file in the index. Validates YAML front-matter (requires kind: serial-protocol and name). The file path can be absolute or relative to CWD.

Inputs: path (required).

serial.spec.searchA

Full-text search over a spec's content. Returns matching snippets with line numbers and surrounding context.

Inputs: spec_id (required), query (required), k.

serial.spec.templateB

Return a markdown template for a new serial protocol spec. Optionally pre-fill with a device name.

Inputs: device_name.

serial.trace.statusA

Return tracing config and event count.

Inputs: no named parameters.

serial.trace.tailB

Return last N trace events (default 50).

Inputs: n.

serial.writeB

Write data to a serial port. Returns the number of bytes written.

Inputs: connection_id (required), data (required), encoding, append_newline, +2 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.8/5.0

    Scored across 27 tools

    Disambiguation5/5

    Each tool has a distinct purpose: serial I/O, connection management, plugin control, spec management, and tracing are all clearly separated. No two tools overlap in functionality.

    Naming Consistency5/5

    All tools follow a consistent prefix pattern 'serial.<category>.<action>' with snake_case (e.g., serial.open, serial.plugin.list, serial.spec.register). This makes the hierarchy predictable and easy to navigate.

    Tool Count4/5

    27 tools cover many sub-domains (basic I/O, plugins, specs, tracing), which is on the higher side but each tool is justified for a comprehensive serial MCP server. Slightly over-scoped but still well-organized.

    Completeness5/5

    The tool set covers all necessary serial operations: open/close, read/write (including line and until), flush, port listing, DTR/RTS control, pulse, plus extensibility via plugins and protocol specs, and debugging with tracing. No obvious gaps.

    Maintenance

    ActivityInactive
    ResponsivenessLimited data

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      Not graded
      maintenance
      Enables AI assistants to interact with physical serial port devices across platforms (Windows COM/Linux tty) with support for asynchronous communication, URC pattern recognition, and structured logging.
      1
      -
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to communicate with serial port devices, supporting port management, data transmission in text/binary modes, interactive terminal sessions, and automatic reconnection.
      14
      12
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables LLMs to communicate with hardware devices via serial ports. Provides tools for listing ports, opening/closing connections, reading/writing data, and controlling serial signals.
      8
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to communicate with UART/serial devices, offering tools for port management, data read/write, and protocol handling.
      MIT