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).

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.7.tar.gz (57.4 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.7-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pty_mcp-0.1.7.tar.gz
  • Upload date:
  • Size: 57.4 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.7.tar.gz
Algorithm Hash digest
SHA256 a493ba51ebf14ac47d571e0f45569b0b5b26dfeac803e8f39d94a5350a336224
MD5 289ca58b7d19190cc77aee3e23149eb0
BLAKE2b-256 d03c0f3ee6c96ef00a9f7309757a4bb249977d8036585f58d2c7c5e460f11ba9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pty_mcp-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 15.1 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 385bdf2f7eba4942b1fd0dcf331585f330cf1eada73e6c99babb279a56189f42
MD5 a3a896717f8c680999429209ba017541
BLAKE2b-256 16620b64af839f21029f70f2b18171fd1cf5a3d8cae5759fa86dc03603e739c8

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