pty-mcp

pty-mcp

Provides a pseudo-terminal (PTY) interface that allows AI agents to interact with command-line tools requiring interactive prompts. It enables agents to autonomously spawn processes, read output, and send inputs for workflows like database migrations and project scaffolding.

Category
访问服务器

README

pty-mcp

MCP server that gives AI coding agents a real pseudo-terminal (PTY) for handling interactive CLI prompts. Spawn processes, read their output, and send intelligent responses — no human in the loop.

Why I Built This

I was using Claude Code with Drizzle ORM and hit a wall: drizzle-kit generate asks interactive questions like "Is this table created or renamed?" that Claude Code couldn't answer. It just hung. I wanted something minimal and self-contained, so I built one.

It works for way more than just Drizzle though — any CLI tool with interactive prompts becomes fully autonomous:

  • Database migrations — Drizzle Kit, Prisma, TypeORM, Knex
  • Project scaffoldingnpm init, create-next-app, create-vite, npx degit
  • Package managersnpm install peer dep prompts, yarn resolutions
  • Git operations — interactive rebase, merge conflict resolution, git add -p
  • Cloud CLIsaws configure, gcloud init, firebase init, vercel
  • Dockerdocker build prompts, docker compose confirmations
  • System toolsssh-keygen, gpg --gen-key, certbot
  • Linters/formatters — ESLint --init, Prettier setup, stylelint config

The Problem

AI coding agents like Claude Code can run shell commands, but they can't handle interactive prompts. When a CLI tool asks "Is this table created or renamed?" or "Pick a preset:", the agent gets stuck — it can't read the prompt or type an answer. This blocks any CLI workflow that requires human input — database migrations, project scaffolding, package configuration, and more.

The Solution

pty-mcp gives the agent a real pseudo-terminal via the Model Context Protocol. The agent can:

  1. Spawn a command in a PTY
  2. Read the interactive prompt output
  3. Write an intelligent response
  4. Repeat until the process exits

Setup

Add to your Claude Code MCP settings (~/.claude/settings.json):

{
  "mcpServers": {
    "pty-mcp": {
      "command": "npx",
      "args": ["-y", "pty-mcp"]
    }
  }
}

Requirements

  • Node.js 20+
  • Build tools for native addon compilation (Python 3, make, g++)
    • macOS: xcode-select --install
    • Ubuntu/Debian: sudo apt install build-essential python3
    • Windows: Pre-built binaries included, no extra tools needed

Tools

pty_spawn

Spawn a command in a pseudo-terminal.

Parameter Type Default Description
command string (required) Command to run
args string[] [] Command arguments
cwd string server CWD Working directory
env_vars object {} Extra environment variables (merged with system env)
idle_timeout_ms number 3000 Wait for output to settle before returning

Returns: { session_id, output, is_running, exit_code }

pty_write

Send input to a running PTY session.

Parameter Type Default Description
session_id string (required) Session ID from pty_spawn
input string (required) Text to send
press_enter boolean true Append Enter after input
idle_timeout_ms number 2000 Wait for output to settle before returning

Returns: { output, is_running, exit_code }

pty_kill

Kill a running session.

Parameter Type Default Description
session_id string (required) Session ID to kill

Returns: { success: true }

Example: Handling Interactive Prompts

Agent calls pty_spawn({ command: "npx", args: ["drizzle-kit", "generate"] })
→ Returns output: "Is 'users' table created or renamed from another table? ❯ create / rename"

Agent reads the prompt, understands context, decides "create"
→ Calls pty_write({ session_id: "abc-123", input: "" })

Process continues, agent answers more prompts as needed...

Process exits → agent gets final output with results

How It Works

  • Uses node-pty (Microsoft, powers VS Code's terminal) for real PTY allocation
  • ANSI escape codes are stripped automatically for clean output
  • Sessions auto-expire after 5 minutes of inactivity
  • All sessions are cleaned up on server shutdown
  • No shell wrapping — commands are spawned directly (no injection risk)

Security

  • Local only — stdio transport, no network exposure, no ports opened
  • No shell injection — uses pty.spawn(command, args) directly, not bash -c
  • No secrets stored — environment variables are passed through, not logged
  • Session isolation — each spawn gets its own PTY with a unique session ID
  • Session limits — max 20 concurrent sessions, 30s max idle timeout per request
  • Auto-cleanup — idle sessions killed after 5 minutes, graceful shutdown on crash

Trust model: This server grants command execution to the connected MCP client. Only connect it to clients you trust (e.g., Claude Code on your local machine). The server inherits your shell environment — spawned processes have access to the same env vars as your terminal.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选