Skip to main content

MCP server for persistent SSH sessions via local tmux

Project description

mcp-ssh-tmux

PyPI version Downloads License: MIT GitHub stars

A high-performance, persistent Model Context Protocol (MCP) server that manages SSH sessions via a local tmux instance.

Why this exists?

Traditional SSH automation runs individual commands without state tracking between executions. Other implementations rely on complex regex patterns to detect command completion. By using tmux as a persistent terminal multiplexer, this project eliminates that complexity entirely. The AI agent simply "looks" at the screen like a human would - the server provides visual snapshots, and the agent interprets prompts, errors, and output naturally.

Key Features

  • Persistence: SSH connections stay alive in tmux even if the MCP server or your AI client restarts.
  • Observability: You can manually run tmux attach -t mcp-ssh to see exactly what the agent is doing in real-time.
  • Reliability: Uses ssh -G for robust config resolution (handles aliases, identity files, etc.).
  • Safety: Built-in command validation to prevent common dangerous operations.
  • File Transfer: Native tools for reading and writing remote files using cat and tee over the existing PTY.

Installation

Requirements

  • tmux must be installed on your system
    • Ubuntu/Debian: apt install tmux
    • macOS: brew install tmux
    • Arch: pacman -S tmux

Via uv (Recommended)

uv tool install mcp-ssh-tmux

Via pip

pip install mcp-ssh-tmux

Configuration

Add this to your mcp.json (e.g., in Claude Desktop, Cursor, or 1mcp):

{
  "mcpServers": {
    "ssh-tmux": {
      "command": "uv",
      "args": [
        "run",
        "mcp-ssh-tmux"
      ]
    }
  }
}

Note: If you installed via uv tool install, you can just use mcp-ssh-tmux as the command.

Tools

  • open_session(host, username, port): Opens a new SSH connection in a unique tmux window.
  • send_command(session_id, command, lines, timeout): Sends a command and polls for a prompt/output. timeout (default 2.0s) controls how long to wait — increase for slower commands like package installs.
  • send_keys(session_id, keys): Sends raw keystrokes without Enter. Use for Ctrl+C, Ctrl+D, interactive input, etc.
  • get_snapshot(session_id, lines): Captures the current screen state.
  • read_remote_file(session_id, remote_path): Efficiently reads a remote file.
  • write_remote_file(session_id, remote_path, content, append): Writes content to a remote file.
  • list_sessions(): Lists all active SSH windows.
  • close_session(session_id): Kills the window and cleans up. WARNING: This terminates any running processes in the session. For long-running tasks, leave the session open and monitor with get_snapshot().

Important Notes

Session Management

  • Do not close sessions with active processes: Closing a session terminates all running commands (builds, downloads, etc.)
  • Monitor long-running tasks: Use get_snapshot() to check progress without closing the session
  • Sessions persist: SSH connections remain alive in tmux even if the MCP server restarts
  • Manual inspection: Run tmux attach -t mcp-ssh to see what's happening in real-time

Acknowledgments

Built with FastMCP and libtmux.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Star History

If you find this project useful, please consider giving it a star! ⭐

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

mcp_ssh_tmux-0.2.3.tar.gz (98.6 kB view details)

Uploaded Source

Built Distribution

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

mcp_ssh_tmux-0.2.3-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file mcp_ssh_tmux-0.2.3.tar.gz.

File metadata

  • Download URL: mcp_ssh_tmux-0.2.3.tar.gz
  • Upload date:
  • Size: 98.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mcp_ssh_tmux-0.2.3.tar.gz
Algorithm Hash digest
SHA256 76eeabb9c1c2a0b02b392ca9b0cd4f157b258550b64cd75561d107304cf63873
MD5 66858de9fcbf460ba0b073446ff7ddba
BLAKE2b-256 be0d5222ee16a37f2b49c3f8dd12a00575a0656febc91da7a2554185dcd09b72

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_ssh_tmux-0.2.3.tar.gz:

Publisher: release.yml on devnullvoid/mcp-ssh-tmux

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mcp_ssh_tmux-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: mcp_ssh_tmux-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mcp_ssh_tmux-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e8046b151fe407acb613aaf9a7f029d0113525fc8f29b1f0372a213fd2bcf0f1
MD5 6ac95251584b85cb39900b1ed1b7bf79
BLAKE2b-256 0f298d150de5d8b98b6ea6a9c8d9589ff9aada5a1e374eb5097d01af50fd8a7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_ssh_tmux-0.2.3-py3-none-any.whl:

Publisher: release.yml on devnullvoid/mcp-ssh-tmux

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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