MCP Hub
Back to servers

pty-mcp

Interactive PTY sessions for AI agents — local shells, SSH with persistent sessions (ai-tmux daemon for attach/detach), and serial ports. Single Go binary, no tmux dependency.

glama
Stars
1
Forks
1
Updated
Mar 24, 2026
Validated
May 7, 2026

pty-mcp

pty-mcp MCP server

An MCP (Model Context Protocol) server that gives AI agents interactive terminal sessions — local shells, SSH, serial ports, and persistent remote sessions that survive disconnects.

AI agent interacting with Telehack BBS via pty-mcp

Why

AI coding agents run commands in non-interactive shells. They can't:

  • Interact with running programs (send stdin, ctrl+c)
  • Use REPLs (python3, node, psql)
  • Keep session state (cd, export, running processes)
  • Manage long-running tasks across reconnects

pty-mcp solves all of these by providing real PTY sessions over MCP.

Features

FeatureDescription
Local terminalInteractive bash/python/node sessions on local machine
SSH sessionsConnect to remote hosts with key/password auth, SSH config support
Serial portConnect to devices via serial (IoT, embedded, network gear)
Persistent sessionsSessions survive SSH disconnects via ai-tmux daemon
Attach/DetachDetach from a running session, reconnect later
Control keysSend ctrl+c, ctrl+d, arrow keys, tab, escape
Settle detectionWaits for output to settle before returning (smart timeout)

Architecture

┌─────────────────────────────────────────────────────┐
│ AI Agent (Claude Code, etc.)                        │
│                                                     │
│  MCP Tools: create_local_session, send_input,       │
│             send_control, read_output, close_session │
└──────────────────────┬──────────────────────────────┘
                       │ JSON-RPC stdio
┌──────────────────────┴──────────────────────────────┐
│ pty-mcp (MCP Server)                                │
│                                                     │
│  Session Manager                                    │
│  ├── LocalSession  (local PTY via creack/pty)       │
│  ├── SSHSession    (remote PTY via x/crypto/ssh)    │
│  ├── SerialSession (serial port via go.bug.st)      │
│  └── RemoteSession (persistent via ai-tmux)         │
└─────────────────────────────────────────────────────┘

Persistent mode (ai-tmux):

  pty-mcp ──SSH──▶ ai-tmux client ──Unix socket──▶ ai-tmux server (daemon)
                                                     ├── PTY: bash
                                                     ├── PTY: ssh admin@router
                                                     └── PTY: tail -f /var/log/syslog

Quick Start

One-line install + register (macOS / Linux / WSL2):

curl -fsSL https://raw.githubusercontent.com/raychao-oao/pty-mcp/main/install.sh | sh
claude mcp add pty-mcp -- /usr/local/bin/pty-mcp

That's it. Restart Claude Code and the tools are available.

Other install methods

Download from GitHub Releases:

Go to Releases, download the binary for your platform, and make it executable:

PlatformBinary
macOS (Apple Silicon)pty-mcp-darwin-arm64
macOS (Intel)pty-mcp-darwin-amd64
Linux (x86_64) / WSL2pty-mcp-linux-amd64
Linux (ARM64)pty-mcp-linux-arm64
chmod +x pty-mcp-*
sudo mv pty-mcp-* /usr/local/bin/pty-mcp
claude mcp add pty-mcp -- /usr/local/bin/pty-mcp

Build from source (requires Go 1.25+):

go install github.com/raychao-oao/pty-mcp@latest
claude mcp add pty-mcp -- $(go env GOPATH)/bin/pty-mcp

WSL2 Notes

pty-mcp works in WSL2 out of the box. Use the Linux binary:

# Inside WSL2
curl -fsSL https://raw.githubusercontent.com/raychao-oao/pty-mcp/main/install.sh | sh
claude mcp add pty-mcp -- /usr/local/bin/pty-mcp

Optional: Install ai-tmux on remote servers

For persistent sessions that survive SSH disconnects, install ai-tmux on your remote server:

# Download for your server's architecture
curl -fsSL https://raw.githubusercontent.com/raychao-oao/pty-mcp/main/install.sh | sh
# Or just copy the binary:
scp /usr/local/bin/ai-tmux your-server:/usr/local/bin/ai-tmux

Usage Examples

Once registered, the AI agent can use these MCP tools:

Local interactive shell:

create_local_session()                    → {session_id, type: "local"}
send_input(session_id, "cd /tmp && ls")   → {output: "...", is_complete: true}
send_input(session_id, "python3")         → start Python REPL
send_input(session_id, "print('hello')")  → {output: "hello\n>>>"}
send_control(session_id, "ctrl+d")        → exit Python
close_session(session_id)

SSH to remote server:

create_ssh_session(host: "myserver", user: "admin")
send_input(session_id, "top")
send_control(session_id, "ctrl+c")        → stop top

Persistent session (survives SSH disconnect):

create_ssh_session(host: "server", user: "admin", persistent: true)
send_input(session_id, "make build")      → start long build
detach_session(session_id)                → disconnect, build continues

# Later (even after restart):
list_remote_sessions(host: "server", user: "admin")  → see running sessions
create_ssh_session(host: "server", user: "admin", session_id: "abc123")  → reattach
send_input(session_id, "echo $?")         → check build result

MCP Tools

ToolDescription
create_local_sessionStart a local interactive terminal (bash, python3, node, etc.)
create_ssh_sessionSSH to a remote host (supports SSH config aliases)
create_serial_sessionConnect to a serial port device
send_inputSend a command and wait for output to settle
read_outputRead current screen output without sending input
send_controlSend control keys (ctrl+c, ctrl+d, arrows, tab, etc.)
list_sessionsList all active sessions
close_sessionClose a session (terminates remote PTY)
detach_sessionDisconnect but keep remote PTY running
list_remote_sessionsList persistent sessions on a remote host

ai-tmux: Persistent Terminal Daemon

ai-tmux is a lightweight daemon that runs on remote servers, keeping PTY sessions alive across SSH disconnects. Think of it as tmux designed for AI agents.

Install on remote server

# Cross-compile for Linux
GOOS=linux GOARCH=amd64 go build -o ai-tmux-linux ./cmd/ai-tmux/

# Copy to server
scp ai-tmux-linux server:~/ai-tmux
ssh server "chmod +x ~/ai-tmux && sudo mv ~/ai-tmux /usr/local/bin/ai-tmux"

How it works

  • ai-tmux server — daemon mode, listens on Unix socket, manages PTY sessions
  • ai-tmux client — bridge mode, forwards JSON protocol over stdin/stdout (used by pty-mcp over SSH)
  • ai-tmux list — list active sessions

The daemon auto-starts when pty-mcp connects with persistent: true. Sessions are reaped after 30 minutes of inactivity.

SSH Config Support

pty-mcp reads ~/.ssh/config to resolve host aliases:

# ~/.ssh/config
Host myserver
    HostName 192.168.1.100
    User admin
    Port 2222
    IdentityFile ~/.ssh/id_ed25519
create_ssh_session(host: "myserver", user: "admin")
# Automatically resolves hostname, port, and identity file

Requirements

  • Go 1.25+
  • For serial: appropriate device permissions
  • For persistent sessions: ai-tmux binary on remote server

License

MIT

Reviews

No reviews yet

Sign in to write a review