Skip to main content

expty-mcp

Python Version License: MIT

expty-mcp is a high-performance Model Context Protocol (MCP) server that equips AI assistants (Claude Code, Cursor, Antigravity, VS Code) with persistent, zero-loss Interactive PTY Process and Serial Communication capabilities.

Engineered specifically for persistent SSH sessions, remote server administration, local shells, REPLs, container debugging, and hardware serial ports (UART/U-Boot). It features an Atomic Expect Engine, continuous background ingestion daemon, transport-level microsecond timestamping with intelligent 50ms continuation detection, and full cross-chunk ANSI sanitization.


Architecture Design

expty-mcp Architecture


Key Features

  • Zero-Loss Background Daemon: Dedicated reader daemon continuously ingests bytes into memory in real time—eliminating dropped output during LLM reasoning pauses.
  • Unified PTY & Serial Transports: Seamlessly spawn local processes (bash, python, gdb), SSH sessions (ssh user@router), or connect to physical UART devices (/dev/ttyUSB0, COM3).
  • Accurate Transport-Level Timestamping: Timestamps are stamped at the moment bytes leave the OS kernel/driver system call, avoiding queue or scheduling jitter.
  • Smart 50ms Packet Continuation:
    • Packet fragments arriving within < 50ms are smoothly merged into a single line.
    • Fragments arriving after >= 50ms (e.g. driver pause, slow command) are split into separate lines tagged with and their own timestamp—enabling effortless correlation against test framework logs (Pytest, RobotFramework).
  • Atomic Expect Engine (expect): Match regex or substring prompt patterns atomically (['password:', '# ', '>>>']) with buffer slicing and retention.
  • Prompt-Aware Execution (exec_expect): Send commands and wait for prompt return in a single call, returning structured JSON results with execution status and duration.
  • Causal Anchor Preservation: Preserves command echo in output streams, providing LLMs with an unbroken causal chain for self-correction without regex stripping bugs.
  • Cross-Chunk ANSI Sanitization: Intelligently handles split escape sequences (e.g. \x1b[ in chunk 1 and 31m in chunk 2), preventing terminal garbage from entering clean buffers.
  • Thread-Safe Multi-Session Management: Concurrently manage multiple terminal sessions with strict session guarding and double-checked locking auto-spawn.
  • Fast Process Exit Detection: Instantly detects when a child process or SSH connection terminates, returning exit codes immediately without waiting for timeouts.
  • Periodic Injection (poll_cmd): Inject keepalive characters or autoboot interrupt keys (e.g. spaces for U-Boot) at high frequency during expect wait windows.
  • 100% Cross-Platform: Native POSIX PTY on Linux & macOS (ptyprocess), leak-free Windows ConPTY worker queue (pywinpty), and cross-platform Serial support (pyserial).

Available MCP Tools

Tool Description
spawn Spawn a new interactive process (bash, ssh user@host, python, gdb, etc.) in a native PTY.
serial Connect to a physical or virtual serial port (/dev/ttyUSB0, COM3).
exec_expect Execute a command and wait for prompt to return, returning structured execution status and clean output.
expect Atomically send a command and wait for regex patterns (ideal for SSH login / prompt sync / bootloader interception).
send Send raw keys or escape sequences (e.g. \x03 for Ctrl+C, \x1b for Escape, Enter).
read_buffer Non-blocking read of newly accumulated stream buffer.
get_history Fetch recent line history. By default, formats with [YYYY-MM-DD HH:MM:SS.mmm] and continuation markers.
list_sessions List all active PTY and Serial sessions with runtime health status.
switch_session Switch the default active session.
close_session Terminate and cleanly shut down an active session.
list_ports Enumerate connected physical and virtual serial ports on the host.
status Query runtime diagnostics, buffer usage, and transport health.

Practical Examples

1. Persistent SSH Session (No repeated logins)

// Step 1: Spawn SSH connection
// Tool: spawn
{
  "command": "ssh root@192.168.1.1",
  "name": "openwrt-router"
}

// Step 2: Handle password prompt with Expect
// Tool: expect
{
  "patterns": ["password:", "# "],
  "command": "admin",
  "timeout": 10.0
}

// Step 3: Run interactive commands effortlessly
// Tool: exec_expect
{
  "command": "cat /etc/config/network"
}

2. Time-Correlated Log Analysis (Aligning with Test Frameworks)

// Tool: get_history
{
  "limit": 5,
  "with_timestamps": true
}

Output:

[2026-09-13 15:30:45.100] [Kernel] Initializing network interface eth0...
[2026-09-13 15:30:45.120] [Kernel] PHY driver link speed: 1000Mbps
[2026-09-13 15:30:45.300] [Kernel] Loading crypto module...
[2026-09-13 15:30:46.850] ↳ done (took 1550ms)
[2026-09-13 15:30:46.870] IPQ807x# 

Notice how the 1.55-second driver pause is clearly split with , immediately pinpointing where execution stalled relative to your test runner logs.

3. Interactive Python REPL / Debugger

// Tool: spawn
{
  "command": "python3",
  "name": "python-repl"
}

// Tool: exec_expect
{
  "command": "import math; math.factorial(10)"
}

4. Hardware UART Bootloader Interception

// Step 1: Open serial port
// Tool: serial
{
  "port": "/dev/ttyUSB0",
  "baudrate": 115200
}

// Step 2: Interrupt autoboot with high-frequency space injection
// Tool: expect
{
  "patterns": ["IPQ807x#", "U-Boot#"],
  "poll_cmd": " ",
  "poll_interval": 0.05,
  "timeout": 15.0
}

Installation & Configuration

No manual installation required. MCP clients can run expty-mcp directly via Astral uv:

# Run directly with uvx (from GitHub repository)
uvx --from git+https://github.com/weyou/expty-mcp.git expty

# Or after PyPI release
uvx expty-mcp

Option 2: Local Installation (with uv or pip)

git clone https://github.com/weyou/expty-mcp.git
cd expty-mcp

# Using uv (fastest)
uv pip install -e .

# Or using standard pip
pip install -e .

Client Configuration

1. Claude Desktop / Claude Code

Using uvx (Zero-Install):

{
  "mcpServers": {
    "expty": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/weyou/expty-mcp.git", "expty"]
    }
  }
}

Using local Python environment:

{
  "mcpServers": {
    "expty": {
      "command": "python3",
      "args": ["-m", "expty_mcp"]
    }
  }
}

2. Antigravity / Google AI Assistant

Add to ~/.gemini/config/mcp_config.json:

{
  "mcpServers": {
    "expty": {
      "command": "python3",
      "args": ["-m", "expty_mcp"]
    }
  }
}

3. Cursor IDE

Add to .cursor/mcp.json or Cursor Global Settings:

{
  "mcpServers": {
    "expty": {
      "command": "uvx",
      "args": ["--from", "git+https://github.com/weyou/expty-mcp.git", "expty"]
    }
  }
}

Testing & Code Quality

pytest -v
ruff check .

License

This project is licensed under the MIT License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

expty_mcp-0.1.0.tar.gz (490.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

expty_mcp-0.1.0-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file expty_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: expty_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 490.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for expty_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6f458cab1109ea737739f49e7bfd5cdb119aac30ff9abbee9887f4e18403f318
MD5 f3819d1d0e52e5ee7d1ee97f7b5d1bf7
BLAKE2b-256 280425b1b762f618d689005d7620b34e3fd57240b75817c9b6bf40c7162a073e

See more details on using hashes here.

Provenance

The following attestation bundles were made for expty_mcp-0.1.0.tar.gz:

Publisher: publish.yml on weyou/expty-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file expty_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: expty_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for expty_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c078ad53c77b5b5765722c53a6d53c3f81094845dcff96844eaf544a6723477
MD5 5c6cdac186c22d589cac9067bd7e8978
BLAKE2b-256 566af85594df4f7b87e33351747c5b856a7dd5351966f85468db1d9c48d453db

See more details on using hashes here.

Provenance

The following attestation bundles were made for expty_mcp-0.1.0-py3-none-any.whl:

Publisher: publish.yml on weyou/expty-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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