Skip to main content

A PTY runner for MCP

Project description

pty-mcp

A lightweight PTY runner for MCP (Model Context Protocol).

pty-mcp provides terminal session tools over MCP so clients can spawn commands in a pseudo-terminal, read interactive output, send input, resize terminal windows, and manage process lifecycle safely.

Features

  • Spawn shell commands in a real PTY
  • Read incremental output from a ring buffer
  • Wait for pattern matching (read_until)
  • Wait for any pattern (read_until_any)
  • Send interactive input (write)
  • Send input and wait for prompt (prompt)
  • Resize terminal (cols / rows)
  • Process control (status, wait, signal, close)
  • Stream split reads (read_stdout, read_stderr)
  • Read with offset (read_at)
  • Session tags (tag, owner)
  • Dynamic defaults (set_default_cwd)
  • Runtime limits (set_limits)
  • Metrics and health (metrics, health)

Requirements

  • Python 3.10+

Installation

pip install pty-mcp

CLI Entrypoint

After installation, the package exposes:

pty-mcp

This starts the MCP server over stdio.

MCP Tools

  • pty_spawn
  • pty_read
  • pty_read_stdout
  • pty_read_stderr
  • pty_read_at
  • pty_read_until
  • pty_read_until_any
  • pty_prompt
  • pty_write
  • pty_resize
  • pty_close
  • pty_close_all
  • pty_status
  • pty_wait
  • pty_signal
  • pty_list
  • set_default_cwd
  • get_default_cwd
  • set_limits
  • get_limits
  • pty_metrics
  • pty_health

New Parameters

pty_spawn

  • cwd — working directory
  • separate_streams — split stdout/stderr into separate buffers
  • tag, owner — session labels for filtering
  • scoperead-only or read-write
  • max_output_bytes — ring buffer cap
  • spawn_timeout_sec — session runtime cap
  • rate_limit_bps — output rate limit
  • input_rate_bps — input rate limit
  • read_timeout_ms — default read timeout per session
  • env — per-session environment overrides

pty_read / pty_read_stdout / pty_read_stderr

  • formatjson or text (default)

Examples

Set default cwd

{"name":"set_default_cwd","arguments":{"cwd":"/root/aa"}}

Spawn with stream split

{"name":"pty_spawn","arguments":{"command":"ls","separate_streams":true}}

Read stdout only

{"name":"pty_read_stdout","arguments":{"session_id":"..."}}

Wait for any prompt

{"name":"pty_read_until_any","arguments":{"session_id":"...","patterns":["OK","ERROR"]}}

Prompt helper

{"name":"pty_prompt","arguments":{"session_id":"...","data":"y\n","patterns":["done","error"]}}

Notes

  • PTY sessions are in-memory and have idle timeout cleanup.
  • The server is intended for local trusted environments.
  • separate_streams=true makes stdout/stderr non-tty (some commands may change output).
  • If command is an absolute path, cwd is inferred from its directory.

License

MIT

Project details


Download files

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

Source Distribution

pty_mcp-0.1.8.tar.gz (57.6 kB view details)

Uploaded Source

Built Distribution

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

pty_mcp-0.1.8-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file pty_mcp-0.1.8.tar.gz.

File metadata

  • Download URL: pty_mcp-0.1.8.tar.gz
  • Upload date:
  • Size: 57.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pty_mcp-0.1.8.tar.gz
Algorithm Hash digest
SHA256 9f5f8f25f3c756e0ef29b2d673233a75000e1a0cb8af5d895df11d9af7f334da
MD5 f869a92c693e2f01de243fee958a589b
BLAKE2b-256 e3975fe176b714db1ec7c1972ee8c736fb5e03b88db36928485e6804d0fa3af7

See more details on using hashes here.

File details

Details for the file pty_mcp-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: pty_mcp-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pty_mcp-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 1fea886552890d446309b969351075d1c906097fb9c39bef5502a3837f9f3066
MD5 4be89614df70458d9cc0956c32d7e7db
BLAKE2b-256 2315466bc839e5492bbe733ecab2ad330588cca487dd8c5c7864d89f417204ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page