Skip to main content

PiloTY: AI pilot for PTY operations via MCP - enables AI agents to control interactive terminals like a human.

Project description

PiloTY logo

PiloTY

PiloTY (PTY for your AI Copilot) is an MCP server that gives an agent a persistent, interactive terminal.

If you have used Claude Code / Codex to run shell commands, you have probably hit the same wall: tool calls tend to be stateless. Each call starts "fresh", so environment variables disappear, interactive programs cannot be driven reliably, and long-running processes get cut off or orphaned while the agent is thinking.

PiloTY exists to make the agent's terminal behave more like a human's: start something in a real terminal, come back later, and keep going.

Warning: PiloTY exposes unrestricted terminal access. Treat it like giving the agent your keyboard.

What it enables

  • Long-running commands: builds, installs, migrations, test suites. Start once, check output later.
  • Log monitoring: tail -f, journalctl -f, kubectl logs -f, CI logs, service restarts.
  • "Vibe debugging": keep a REPL/debugger open while the agent reads code and tries ideas (python, ipython, pdb).
  • Privileged operations: handle interactive password prompts (sudo, SSH passwords, key passphrases).
  • SSH-based devops: keep a remote login session alive across tool calls; run remote commands in the same shell.
  • Terminal UIs: less, man, top, vim can work, but cursor-heavy programs often require screen snapshots instead of plain text output.

Quickstart

PiloTY is meant to be launched by an MCP client over stdio.

Add it to Codex CLI as an MCP server:

codex mcp add piloty -- uvx --from git+https://github.com/yiwenlu66/PiloTY.git piloty

If you prefer SSH-based Git fetch:

codex mcp add piloty -- uvx --from git+ssh://git@github.com/yiwenlu66/PiloTY.git piloty

If you already have a local clone:

codex mcp add piloty -- uv --directory /path/to/PiloTY run piloty

Run the server command directly (without adding it to an MCP client):

uvx --from git+https://github.com/yiwenlu66/PiloTY.git piloty

Mental model

One session is one real interactive terminal that stays alive across tool calls.

  • State persists: cwd, environment variables, foreground process, remote SSH connection, REPL/debugger state.
  • PiloTY tracks both the raw output stream and a rendered screen/scrollback view.

PiloTY keeps two representations:

  • output: incremental text stream (optionally ANSI-stripped)
  • Rendered screen/scrollback: what a human would see in a terminal

Sessions are addressed by a session_id string. Reusing the same id is what keeps state.

Tool reference (for MCP integrators)

All tools take a session_id string. MCP does not expose client cwd as a standard field, so call create_session(session_id, cwd) before terminal I/O.

Input/output:

  • create_session(...): create a session with explicit cwd
  • run(...): send a line (adds newline)
  • poll_output(...): wait up to timeout for new output without sending input
  • send_input(...): send text without newline
  • send_control(...): send a control key (c, d, z, l, [ for escape)
  • send_password(...): send a password (no transcript logging; echo suppressed for this send)
  • expect_prompt(...): wait for a shell prompt (useful after ssh/login output where the prompt appears later)

Rendered view:

  • get_screen(...): rendered screen snapshot (cursor position, rendering status)
  • get_scrollback(...): rendered scrollback (best-effort)

Session management:

  • get_metadata(...): cwd, foreground pid, dimensions, timestamps, tag
  • transcript(...): transcript path (includes on-disk path if a session was evicted/restarted)
  • terminate(...): terminate a session (final; later calls reject the id)

For tool signatures and return fields, read piloty/mcp_server.py.

Limitations

  • Status/prompt detection is best-effort and can be wrong (especially for custom prompts and cursor-heavy TUIs).
  • Plain text output can be misleading for full-screen programs; use screen snapshots when layout matters.
  • send_password() suppresses transcript logging and terminal echo for that send. It does not prevent other prompts/programs from echoing secrets later.
  • Quiescence-based output collection can be confused by programs that print periodic noise. Tune with PILOTY_QUIESCENCE_MS (default 1000).

Logs

Each session writes logs under ~/.piloty/:

  • ~/.piloty/sessions/<session-id>/transcript.log: raw PTY bytes (combined stdout/stderr)
  • ~/.piloty/sessions/<session-id>/commands.log: inputs sent (best-effort)
  • ~/.piloty/sessions/<session-id>/interaction.log: inputs plus captured output (best-effort)
  • ~/.piloty/sessions/<session-id>/session.json: metadata snapshot
  • ~/.piloty/active/<session-id>: symlink to the current session directory (when symlinks are supported)

Server logs default to /tmp/piloty.log.

tools/session_viewer.py can inspect sessions:

python tools/session_viewer.py list
python tools/session_viewer.py info <session-id>
python tools/session_viewer.py tail -f <session-id>

Development

Repository layout:

piloty/
  core.py        # PTY + terminal renderer + session logs
  mcp_server.py  # MCP tools + state inference
tests/
tools/
  pty_playground.py
  session_viewer.py

Run tests:

python -m pytest -q

License: Apache License 2.0, see LICENSE.

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

iflow_mcp_yiwenlu66_piloty-0.3.0.tar.gz (76.9 kB view details)

Uploaded Source

Built Distribution

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

iflow_mcp_yiwenlu66_piloty-0.3.0-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file iflow_mcp_yiwenlu66_piloty-0.3.0.tar.gz.

File metadata

  • Download URL: iflow_mcp_yiwenlu66_piloty-0.3.0.tar.gz
  • Upload date:
  • Size: 76.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_yiwenlu66_piloty-0.3.0.tar.gz
Algorithm Hash digest
SHA256 22aef0793f9616ebf3ae996192e49cee5b00da8acce49a8f061c5101e45132ec
MD5 d62b03e4d827cc5c1e67f7ddc6089027
BLAKE2b-256 ab8223e9cead9f1e48c2796f1938c1d163b2142077e14f4e032745b79985fcbd

See more details on using hashes here.

File details

Details for the file iflow_mcp_yiwenlu66_piloty-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_yiwenlu66_piloty-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 24.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_yiwenlu66_piloty-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6335a555bc540578966dbeffd4e25c8bd841ace4dc0bd3126e787fcb3432aaa9
MD5 b00eb1a5dec0f61ebdd5c7d8cb0ae215
BLAKE2b-256 f1eeb76f014f46d5faab8fb1ebaad63a9a95470316defec6ae75ff723ddcebba

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