mcp-remote-ssh
MCP server giving AI agents full SSH access -- persistent sessions, structured command output, SFTP file transfer, port forwarding, session transcript recording, and secret-safe environment variable injection with automatic output redaction.
Why this exists
Every other SSH MCP server is missing something: no password auth, no persistent sessions, no SFTP, no port forwarding, or no structured exit codes. This one has all of them -- plus the only MCP-level secret management that prevents AI agents from ever seeing your credentials.
Secret-Safe Environment Variables
The problem: When an AI agent needs to use API tokens, passwords, or keys on a remote server, the standard approach exposes secrets in the LLM's context window. The agent either reads the secret file (now it's in the conversation) or runs echo $TOKEN and sees the value in the output.
The solution: ssh_load_env_file reads secrets from a local file on your machine, injects them into the remote SSH session, and registers them for automatic output redaction. The AI agent can use the variables freely -- every tool response is scrubbed before it reaches the LLM.
# Agent calls this -- file is read from YOUR machine, not the remote host
ssh_load_env_file(session_id="abc", file_path="~/.secrets/prod.env")
→ "Loaded 3 variables from local:~/.secrets/prod.env: API_TOKEN, DB_PASS, SECRET_KEY"
# Agent tries to echo the value -- redacted automatically
ssh_execute(session_id="abc", command="echo $API_TOKEN")
→ {"stdout": "***\n", "exit_code": 0}
# Agent dumps the environment -- all secret values scrubbed
ssh_execute(session_id="abc", command="env | grep API_TOKEN")
→ {"stdout": "API_TOKEN=***\n", "exit_code": 0}
# Agent reads a file containing a secret -- also redacted
ssh_read_remote_file(session_id="abc", remote_path="/etc/app/config")
→ "db_password=***\ndb_host=localhost\n"
# Normal commands work perfectly -- no over-redaction
ssh_execute(session_id="abc", command="uname -a")
→ {"stdout": "Linux server 6.1.0 ...", "exit_code": 0}
How it works
┌─────────┐ ┌──────────────────────────────┐ ┌─────────────┐
│ LLM │ ←─JSON─ │ MCP Server (your machine) │ ──SSH─→ │ Remote Host │
│ (Agent) │ │ │ │ │
└─────────┘ │ 1. Reads ~/.secrets/prod.env│ └─────────────┘
│ 2. Parses KEY=VALUE pairs │
│ 3. Stores values in memory │
│ 4. Injects into SSH session │
│ 5. Redacts ALL tool output │
└──────────────────────────────┘
- Local file read -- the env file lives on your machine, never on the remote host
- Shell injection via builtins -- uses
read -r VAR <<< 'value' && export VAR(no process tree exposure) - Stdin-based exec injection --
ssh_executefeeds secrets via stdin to a bash wrapper, so they never appear in/proc/*/cmdline - Automatic redaction -- every tool response (
ssh_execute,ssh_shell_send,ssh_shell_read,ssh_read_remote_file) is scrubbed before reaching the LLM - Longest-first matching -- prevents partial-match corruption (e.g.,
abc123is replaced beforeabc)
Security properties
| Threat | Mitigated? | How |
|---|---|---|
| Secret in LLM context window | Yes | Output redaction replaces values with *** |
| Secret in remote process tree (shell) | Yes | Shell builtins (read/export) don't fork |
| Secret in remote process tree (exec) | Yes | Secrets fed via stdin, never in /proc/*/cmdline |
LLM tries cat on the env file |
N/A | File is local-only, doesn't exist on remote |
LLM tries echo $VAR |
Yes | Output is redacted |
| Encoded/transformed secret (base64) | No | Only literal matches are redacted |
| MITM on first SSH connection | Accepted* | TOFU by default — see note below |
| MITM via changed host key | Yes | Changed keys are rejected (BadHostKeyException) |
| Sudo password in remote process tree | Yes | Fed to sudo -S via stdin, never in /proc/*/cmdline |
Host key policy
ssh_connect verifies host keys trust-on-first-use (TOFU) by default: the first connection to a host trusts its key and persists it to ~/.ssh/known_hosts (configurable via known_hosts_path); any later connection with a different key for that host is rejected as a possible MITM.
host_key_policy |
Behavior |
|---|---|
tofu (default) |
Trust unknown keys once, persist them, reject changed keys |
strict |
Only hosts already in known_hosts may connect |
ignore |
Accept any key, no persistence (legacy lab mode) |
For reimaged/ephemeral hosts (Beaker, CI) whose keys change on every provision, pass host_key_policy='ignore' — that restores the old zero-friction behavior at the cost of accepting first-connection MITM risk. The remaining TOFU trade-off: a MITM on the very first connection to a genuinely new host is still accepted (as with plain OpenSSH TOFU).
Env file format
Standard .env format:
# Comments are ignored
API_TOKEN=your-secret-token
DB_PASSWORD="quoted values work"
SECRET_KEY='single quotes too'
export ALSO_WORKS=yes
Session transcripts
Recording is off by default. Enable it per session when you need an audit log of what the agent actually ran — useful for bug reproductions and test campaigns.
# Start recording on connect
ssh_connect(host="lab.example.com", username="root", password="...", record=True)
# Or toggle later
ssh_start_recording(session_id="a1b2c3d4")
ssh_execute(session_id="a1b2c3d4", command="uname -a")
ssh_get_transcript(session_id="a1b2c3d4")
→ {"recording": true, "total_entries": 2, "transcript": "[12:01:02] --- connect: lab.example.com ---\n[12:01:05] $ uname -a\nLinux ...\n[exit 0]"}
ssh_save_transcript(session_id="a1b2c3d4", path="/tmp/lab-session.log")
ssh_stop_recording(session_id="a1b2c3d4")
- Execute/sudo output and shell send/read I/O are secret-redacted before they are recorded
- Closing the session discards the in-memory transcript —
ssh_save_transcriptorssh_get_transcriptfirst
Installation
Requires Python 3.11+.
uvx mcp-remote-ssh # or: pip install mcp-remote-ssh
uvx mcp-remote-ssh[tasks] # with the MCP Tasks extension (optional)
Optional environment variables: MCP_REMOTE_SSH_CACHE_TTL (tool-list cache hint, default 300s) and MCP_REMOTE_SSH_MAX_RESPONSE_BYTES (response cap for unbounded-output tools, default 200000).
Modern MCP features
- Usage instructions shipped to every connecting client via the handshake
- Interactive confirmations before destructive writes (
ssh_write_remote_file,ssh_upload_file) — MRTR on 2026-07-28 clients, elicitation on legacy clients; fails closed. Opt out per call withconfirm=False. Trust boundary: confirmation is client-mediated — a client that auto-accepts elicitations bypasses the human (MRTR on modern clients is the stronger path). Treat the guard as protection against accidental overwrites, not adversarial clients - Response limiting on unbounded-output tools; structured outputs (
ExecResult,SessionSummary,ForwardInfo) on fixed-shape tools - Progress notifications from
ssh_shell_wait - Tasks extension (optional
[tasks]extra):ssh_shell_waitcan run as a background task on supporting clients
Configuration
{
"mcpServers": {
"remote-ssh": {
"command": "uvx",
"args": ["mcp-remote-ssh"]
}
}
}
Tools (24)
Connection
| Tool | Description |
|---|---|
ssh_connect |
Connect with password, key, or agent auth. Optional record=True to start a transcript immediately. Returns session_id |
ssh_list_sessions |
List active sessions |
ssh_close_session |
Close a session and release resources |
Execution
| Tool | Description |
|---|---|
ssh_execute |
Run a command, returns {stdout, stderr, exit_code} |
ssh_sudo_execute |
Run with sudo elevation |
Interactive Shell
| Tool | Description |
|---|---|
ssh_shell_open |
Open persistent shell (preserves cwd, env, processes) |
ssh_shell_send |
Send text (with optional Enter) |
ssh_shell_read |
Read current output buffer |
ssh_shell_send_control |
Send Ctrl+C, Ctrl+D, etc. |
ssh_shell_wait |
Wait for a pattern or output to stabilize |
Secrets Management
| Tool | Description |
|---|---|
ssh_load_env_file |
Load secrets from a local env file; values never returned to the LLM |
ssh_clear_secrets |
Clear redaction registry (values become visible again) |
Transcripts
| Tool | Description |
|---|---|
ssh_start_recording |
Start recording execute/sudo/shell I/O for this session |
ssh_stop_recording |
Stop recording; transcript stays available until the session is closed |
ssh_get_transcript |
Return the transcript as text or JSONL (last_n optional) |
ssh_save_transcript |
Write the transcript to a local file on the MCP host |
SFTP
| Tool | Description |
|---|---|
ssh_upload_file |
Upload local file to remote host |
ssh_download_file |
Download remote file to local machine |
ssh_read_remote_file |
Read a remote text file |
ssh_write_remote_file |
Write/append to a remote file |
ssh_list_remote_dir |
List directory with metadata |
Port Forwarding
| Tool | Description |
|---|---|
ssh_forward_port |
Create SSH tunnel (local -> remote) |
ssh_list_forwards |
List active tunnels |
ssh_close_forward |
Close a tunnel |
Quick start
ssh_connect(host="server.example.com", username="admin", password="secret", record=True)
→ {"session_id": "a1b2c3d4", "connected": true, "recording": true}
ssh_load_env_file(session_id="a1b2c3d4", file_path="~/.secrets/prod.env")
→ "Loaded 2 variables: API_TOKEN, DB_PASS"
ssh_execute(session_id="a1b2c3d4", command="curl -H \"Authorization: Bearer $API_TOKEN\" https://api.example.com")
→ {"stdout": "{\"status\": \"ok\"}", "exit_code": 0} # token used but never visible
ssh_shell_open(session_id="a1b2c3d4")
ssh_shell_send(session_id="a1b2c3d4", data="cd /opt && make -j$(nproc)")
ssh_shell_wait(session_id="a1b2c3d4", pattern="$ ", timeout=600)
ssh_upload_file(session_id="a1b2c3d4", local_path="config.yaml", remote_path="/etc/app/config.yaml")
ssh_forward_port(session_id="a1b2c3d4", remote_port=5432, local_port=15432)
Design
Built on Paramiko (SSH) + FastMCP 4 (MCP protocol).
- Speaks the 2026-07-28 MCP protocol revision (stateless requests,
server/discover) while still serving 2025-era clients via per-connection version negotiation - All 24 tools declare explicit MCP annotations (
readOnlyHint,destructiveHint,idempotentHint,openWorldHint) — enforced by test, so new tools cannot ship unannotated ssh_executeusesexec_command()for clean structured output with real exit codes- When secrets are loaded,
ssh_executefeeds exports via stdin to abashwrapper, thenexecs the actual command -- secrets never appear in the process tree ssh_sudo_executefeeds the sudo password tosudo -Son the channel's stdin -- it never appears in any command linessh_shell_*usesinvoke_shell()for persistent interactive sessions- All blocking Paramiko calls run in the thread pool via the shared
run_sync()helper to stay async - Shell keeps a 500KB rolling buffer for
shell_readpolling - Secret redaction uses longest-first string replacement across all output paths, including redaction-only values (e.g. the sudo password) that are never exported as env vars
- Session transcripts are in-memory, off by default, and discarded when the session is closed
License
MIT
Metadata
Release files for mcp-remote-ssh 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mcp_remote_ssh-0.5.0.tar.gz | 50.8 kB | With provenance | Details for mcp_remote_ssh-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mcp_remote_ssh-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for mcp_remote_ssh-0.5.0-py3-none-any.whl |
Total release size: 84.6 kB
Release files / mcp_remote_ssh-0.5.0.tar.gz
| Download URL | mcp_remote_ssh-0.5.0.tar.gz |
|---|---|
| Size | 50.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
22ea0bf39d842ae6e690c1c9d568968bf7c17471e958f78ecd82c10d864ca3de
|
|
BLAKE2b-256 checksum How to use checksums |
13181ca0e39f8f416691238b6a1870125488f95ffe7c06fd6221c100efa877c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logRelease files / mcp_remote_ssh-0.5.0-py3-none-any.whl
| Download URL | mcp_remote_ssh-0.5.0-py3-none-any.whl |
|---|---|
| Size | 33.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5aed563d84d0d43e39418f7e090ca46b4f87064c9c89a3cacb86066ac77de746
|
|
BLAKE2b-256 checksum How to use checksums |
c0b391340010b88836744d5f02b5d46ec547437a0b4b09075880e5059511ba42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logSecurity for mcp-remote-ssh 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mcp_remote_ssh-0.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.