
pty-mcp
io.github.raychao-oao由 GitHub 账号 raychao-oao 发布v0.2.3更新于 Oct 24, 2026
Interactive PTY sessions over MCP: local shells, SSH, serial ports, and persistent remote sessions.
概览
一个本地 MCP 服务器,为 AI 助手提供真正的交互式终端会话:本地 shell、SSH 主机、串口以及可持久化的远程会话。
- 可以做什么
- 创建与管理会话:启动本地 shell、SSH 连接、串口控制台和持久远程会话,列出会话,调整窗口大小,分离或关闭会话,并稍后重新接入远程会话。发送输入与读取输出:执行命令、等待输出稳定,并按正则模式阻塞等待,可设置超时和上下文行数。操作交互式程序:发送 ctrl+c、ctrl+d、方向键、Tab 等控制键。处理凭据:通过原生对话框让操作员输入机密,并直接送入会话,不暴露给助手。可选审计:将 send_input 命令记录到收集器,并对凭据、认证头和私钥做脱敏。
- 适用场景
- 适用于服务器运维、通过串口控制台管理网络设备、对事件作出反应的日志监控,以及需要在断连后继续运行的长任务。面向希望助手在真实交互式 shell 中工作、而非只执行一次性命令的系统管理员和网络工程师。
- 运行要求
- 以本地进程形式运行在用户机器上(仅桌面端);提供 macOS 和 Linux(含 WSL2)预编译二进制,或用 Go 1.25+ 从源码构建。远程主机需要 SSH 访问及密钥或密码,会读取 SSH 配置别名。串口使用需要设备权限。持久会话需要在远程服务器上安装 ai-tmux 二进制。可选审计收集器使用通过 PTY_MCP_AUDIT_TOKEN 设置的令牌。
安装
在 SourceWeft 中
- 打开 控制台中的 pty-mcp,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
pty-mcp
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.
Built for sysadmins and network engineers who want AI to help with real server and device management, not just code generation.
[AI agent interacting with Telehack BBS via pty-mcp]
Why
AI agents run commands in non-interactive shells. They can't:
- SSH into a server and interact with running processes
- Connect to routers or switches via serial console
- Monitor logs and react when a specific event occurs
- Keep session state across multiple commands
- Wait for a server to reboot and detect when it's back up
pty-mcp solves all of these by providing real PTY sessions over MCP.
Without pty-mcp, AI agents resort to sleep 30 && check_status loops — burning CPU cycles and API calls waiting for things to happen. With wait_for, the agent blocks server-side until the event occurs. Less polling, less energy, better for polar bears. 🐻❄️
Use Cases
Server administration
Network device management
Log monitoring and alerting
Long-running tasks that survive disconnects
Features
Architecture
Quick Start
Claude Code Plugin (recommended)
Installs the binary automatically and registers the MCP server:
Restart Claude Code — the binary downloads automatically on session start, then restart once more to activate it. No manual claude mcp add needed.
Updating:
Restart Claude Code — the new binary downloads automatically on session start, then restart once more to apply the update.
Manual install
One-line install + register (macOS / Linux / WSL2):
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:
Build from source (requires Go 1.25+):
WSL2 Notes
pty-mcp works in WSL2 out of the box. Use the Linux binary:
Optional: Install ai-tmux on remote servers
For persistent sessions that survive SSH disconnects, install ai-tmux on your remote server:
Usage Examples
Once registered, the AI agent can use these MCP tools:
Local interactive shell:
SSH to remote server:
Wait for pattern (v0.2.0):
Send secret / password (v0.3.0):
Persistent session (survives SSH disconnect):
MCP Tools
¹
send_secretplatform support: macOS uses a native password dialog (osascript). WSL2 usespowershell.exe Get-Credential(Windows GUI dialog). Linux with a display server useszenityorkdialog. Headless Linux falls back to/dev/tty. On macOS/Linux, if the operator doesn't respond within 60 seconds, the dialog is dismissed and the call returns a timeout error instead of falling through to another dialog or waiting again; cancelling the call (e.g. pressing ESC in Claude Code) dismisses the dialog immediately the same way. WSL2 is the exception: its dialog has no timeout and is never force-closed, including on cancellation — killing a WSL-interop-launched process that owns an open Windows GUI window was found to freeze the hosting terminal (unresponsive to input, scrolling, and selection) until the operator closes that terminal, with no way to recover it short of that. The dialog just waits until the operator answers or clicks Cancel themselves, which exits normally.
Audit Log
pty-mcp includes an optional audit log feature that records every send_input command to a central collector. This lets teams review and trace what AI agents did during a session.
Important: This is a voluntary, self-reporting operation log. It relies on operators choosing to enable it and run the collector. Because pty-mcp runs on the operator's own machine, there is no technical mechanism to enforce logging — a non-compliant operator could simply run pty-mcp without audit enabled. This feature provides traceability for teams that want it, but it is not a substitute for system-level audit tools (e.g., auditd, syslog forwarding, SSH session recording) in environments where audit compliance is required.
What it records
- Timestamp, operator identity, session ID, session type (local/ssh/serial), target host
- The exact input sent via
send_input(includingraw=trueinputs like menu selections) - Output snippet (first 2 KB) after each command
- A
cmd_idlinking the command to its output
send_secret is never logged — secrets entered via the GUI dialog do not appear in the audit log.
Commands and output snippets are automatically redacted before being written. The following patterns are replaced with [REDACTED] or [PRIVATE KEY REDACTED]:
- Key-value credentials:
password=,passwd:,token=,api_key=,access_key=,auth_token=,secret= - HTTP Authorization headers:
Authorization: Bearer …,Authorization: Basic …,Authorization: Token … - PEM private key blocks:
-----BEGIN RSA PRIVATE KEY-----/-----BEGIN OPENSSH PRIVATE KEY-----
Setup
Each operator runs once to create their config and generate a token:
This creates ~/.config/pty-mcp/config (chmod 600) with a randomly generated token and prints the token to share with the collector admin.
The collector admin starts the server (using the token from init output):
Enable audit after setting the collector URL in the config:
To temporarily stop logging without losing your config:
Operators without a config file are unaffected — audit is off by default.
Audit modes
Reviewing logs
Logs are stored as JSONL (one JSON object per line), readable with standard tools:
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
How it works
ai-tmux server— daemon mode, listens on Unix socket, manages PTY sessionsai-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.
pty-mcp checks ai-tmux --version on the remote host before opening a session and returns a clear error if the binary is missing or below the minimum required version — no cryptic connection errors.
SSH Config Support
pty-mcp reads ~/.ssh/config to resolve host aliases:
Requirements
- Go 1.25+
- For serial: appropriate device permissions
- For persistent sessions:
ai-tmuxbinary on remote server
Changelog
See CHANGELOG.md for version history.
License
MIT
来源:README.md,提交 8cf84e0
工具
0版本历史
1- v0.2.3最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分