
Remote Ssh Mcp
io.github.the-nine-nationPublished by GitHub account the-nine-nationv0.2.0Updated Oct 24, 2026
Persistent stateful remote SSH sessions for AI agents via MCP + OpenSSH.
Overview
Lets an assistant open persistent remote SSH shell sessions and run commands that keep working directory and environment state.
- What you can do
- Wraps the system OpenSSH client in MCP tools: ssh_hosts lists allowed Host aliases, ssh_open starts a long-lived remote Bash session, ssh_run executes commands in it, ssh_peek polls output of long-running jobs, ssh_interrupt sends Ctrl-C, ssh_list shows sessions, and ssh_close tears them down. State such as cwd, exported variables, and shell side effects persist across calls within one session. Output is split into stdout and stderr, truncated head-and-tail, and stripped of ANSI noise.
- When to use it
- Useful for multi-step remote work such as deploys, builds, debugging, and log inspection where reconnecting for every command wastes tokens and loses shell state. It fits agents that already reach hosts through a local SSH config and want one handshake per session instead of one per command.
- Requirements
- Runs locally over stdio; needs Node.js 20 or newer and a system OpenSSH client on PATH. Remote hosts need only a normal shell account with bash, base64, stty, mkdir, cat, and rm, plus a Host alias in the SSH config with the host key already trusted. Optional settings come from a config file or environment variables such as SSH_MCP_CONFIG and SSH_MCP_ALLOWED_HOSTS.
Installation
In SourceWeft
- Open Remote Ssh Mcp in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
Remote SSH MCP
Persistent, stateful remote Bash sessions for AI agents
via the Model Context Protocol
Why · Features · How it works · Tools · Quick start · Config · Security · 简体中文
[MIT License] [Node.js 20+] [TypeScript] [MCP stdio] [OpenSSH] [Version 0.2.2] [GitHub release] [npm version] [GitHub stars]
[Remote SSH MCP — AI agent terminal connected to remote servers over SSH]
Why Remote SSH MCP?
Most agents reach remote machines like this:
Every call pays the same tax:
Remote SSH MCP turns a long-lived remote Bash into first-class MCP tools. One session ID keeps working directory, environment variables, and shell side effects. Open a new session when you need a clean environment.
Why pick this over one-shot ssh in bash?
Concrete gains for agent workflows (multi-step remote work: deploy, debug, build, inspect logs):
Portability in one line: put the MCP on your dev box / AI host; every server already in your SSH config is reachable — zero package install on the remote fleet.
Token sketch (illustrative multi-step remote debug):
It does not reimplement SSH. Your system OpenSSH client stays in charge — so ~/.ssh/config, known hosts, the SSH agent, ProxyJump routes, and hardware keys keep working exactly as they already do.
Features
🧠 Persistent remote sessions
- One stable session ID maps to one long-lived remote Bash
cwdand environment survive acrossssh_runcalls- Open a fresh session whenever you need a clean slate
- Multiple sessions can target the same or different hosts (up to
maxSessions)
🔧 Native OpenSSH integration
- Spawns the real
sshbinary — no custom crypto stack - Honors
~/.ssh/config,Include, agent sockets, and ProxyJump - Forces
BatchMode=yesandStrictHostKeyChecking=yes - Never accepts passwords, private-key text, or arbitrary SSH option args from the model
📡 Long-running command friendly
ssh_runwaits up towait_sec(default 10s), then returnsstatus: "running"while the remote command continues- Poll with
ssh_peek(wait_sec=...)long-poll instead of busy-looping - Optional hard
timeout_secsends Ctrl-C; no automatic kill by default - Ideal for
docker pull, builds, downloads, and deploys that must not block the tool call forever
🛡️ Safety & control plane
- Exact Host-alias allowlist from
ssh_config+ optional config / env overrides - Patterns with
*,?, or!are ignored - Fail-closed interrupt: if shell recovery cannot be confirmed after Ctrl-C, the session is closed
- Built-in denylist for a few obviously destructive patterns (not a full policy engine)
- Idle reaping, session caps, and a JSONL audit log (
0600) with hashed commands
📦 Clean tool results for models
- Separate
stdout/stderrstreams - Head-and-tail byte truncation with valid UTF-8 boundaries
- ANSI / PTY noise stripped before the model sees output (colors, CSI, bracketed-paste markers, control-only blank lines)
- Quiet open-frame:
TERM=dumb,NO_COLOR, bracketed-paste off — less junk at the source - Slim JSON payloads: omit empty
stderr,falsetruncation flags, and request-echo fields so dualcontent+structuredContentstays cheap ssh_hostsreturns only safe metadata:alias,hostname,user,port,proxy_jump- Never leaks
IdentityFile, certificates, agent sockets, orProxyCommand
🔌 MCP-native
- stdio transport for Claude Desktop, Cursor, and other MCP hosts
- Compatible with both legacy and current MCP handshakes
- Parent / stdio exit closes every tracked SSH connection
How it works
Typical agent flow
MCP tools
Tool parameters (essentials)
Quick start
Requirements
⚠️ First-time host-key confirmation and authentication must be completed in a normal terminal. The MCP server never shows password or trust prompts.
Install
Run the server:
Or install from npm (once published):
Or, after a local package install from this repo, use the remote-ssh-mcp executable.
MCP host configuration
Most stdio hosts accept a shape like this (outer key may differ by product):
Cursor · Claude Desktop · Claude Code · other MCP-capable hosts: point command / args at the built dist/index.js and set SSH_MCP_ALLOWED_HOSTS (or rely on auto-discovery from ~/.ssh/config).
SSH_MCP_ALLOWED_HOSTS adds aliases to the allowlist. By default the server also discovers exact Host entries from ~/.ssh/config and its Include files. Tool inputs accept only safe aliases — not user@host, ports, or extra SSH options.
After editing ~/.ssh/config, call ssh_hosts(reload=true) instead of restarting the server.
Credential boundary
Authentication stays inside the local OpenSSH client:
- Tools never accept passwords or private-key material
ssh_hostsnever returns key paths, certs, agent sockets, orProxyCommand- Agents should call
ssh_openwith a Host alias and must not read~/.sshprivate keys from disk
Configuration
Optional config file (default path):
Environment variables
Environment variables override the file. The audit log is created with mode 0600 and records session, host, result, duration, command length, command name, and SHA-256 — not full argument strings (reduces secret leakage).
Execution semantics
Detailed rules the agent (and you) should know:
Example: start docker pull with wait_sec: 10 and no timeout_sec. A running result means the original pull is still active — do not start another. Call ssh_peek with a positive wait_sec until idle, interrupt it, or open another session for parallel work.
Development
The test suite covers MCP stdio discovery and calls, persistent cwd / environment state, stream separation, framing across arbitrary chunk boundaries, timeout fail-closed behavior, shell death, allowlist discovery, output truncation, and the safety denylist.
Design notes and wire protocol: 远程SSH-MCP设计.md.
Security
Please do not report security vulnerabilities through public GitHub issues. Until a private advisory workflow is configured, contact the maintainer via the email on their GitHub profile.
Remote commands can have irreversible side effects even when the MCP transport is healthy. Use least-privilege accounts, keep the allowlist narrow, and review host permissions carefully.
Project status
Changelog
Unreleased — Connection and progress feedback
- Custom
sshConfigPath/SSH_MCP_SSH_CONFIGnow controls the actual connection through OpenSSH-F, as well as host discovery. The default~/.ssh/configkeeps native OpenSSH behavior; a custom file follows-Fsemantics (system-wide config is skipped). - Host discovery also accepts
Host=prod,HostName = example.com, andInclude=...syntax. ssh_openfailures include areasonand actionablehintfor host trust, authentication, DNS, network, timeout, and local setup issues, alongside the original error.- Short progress output is delivered immediately unless its suffix could be a partial protocol marker.
- Completed
ssh_peekresponses includecommand_statusandduration_ms, keeping shell state (idle) separate from the command outcome. A peek already waiting when a session dies retains available output and timeout/interruption details. Later calls to the removed session still returnsession_gone.
0.2.2 — quieter remote output, fewer tokens
PTY-backed interactive bash often injects escape sequences that look like “binary” when JSON-escaped (\u001b[?2004h, color CSI, cursor codes). That noise burned context on every ssh_peek / ssh_run.
Upgrade: npm i -g @zyluo/[email protected] (or bump the package in your MCP config), then restart the MCP process so the new server binary is loaded.
0.2.1
- Fix READY-marker parsing when the open frame is PTY-echoed
0.2.0
- Initial public release on npm / GitHub
Star History
If this project saves you tokens and flaky reconnects, a ⭐ on GitHub helps others find it.
[Star history]
Built for agents that need a real remote shell — not another one-shot ssh host "…".
Source: README.md at commit e952a55
Tools
0Version history
1- v0.2.0LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts