
Remote Ssh Mcp
io.github.the-nine-nation由 GitHub 帳號 the-nine-nation 發布v0.2.0更新於 Oct 24, 2026
Persistent stateful remote SSH sessions for AI agents via MCP + OpenSSH.
概覽
讓助理開啟持續存在的遠端 SSH 工作階段並執行指令,同時保留工作目錄與環境狀態。
- 可以做什麼
- 把系統 OpenSSH 用戶端包裝成 MCP 工具:ssh_hosts 列出允許的 Host 別名,ssh_open 啟動長期存活的遠端 Bash 工作階段,ssh_run 在其中執行指令,ssh_peek 輪詢長時間工作的輸出,ssh_interrupt 送出 Ctrl-C,ssh_list 檢視工作階段,ssh_close 關閉工作階段。同一個工作階段內的工作目錄、匯出的變數與 shell 副作用會跨呼叫保留。輸出會區分 stdout 與 stderr,做頭尾截斷並移除 ANSI 雜訊。
- 適用情境
- 適合部署、建置、除錯、查看日誌等多步驟遠端作業,避免每條指令都重新連線而浪費 token 並遺失 shell 狀態。也適合已透過本機 SSH 設定存取主機、希望每個工作階段只握手一次的助理。
- 執行需求
- 以 stdio 方式在本機執行,需要 Node.js 20 或更新版本,以及位於 PATH 中的系統 OpenSSH 用戶端。遠端主機只需一般 shell 帳號,並具備 bash、base64、stty、mkdir、cat、rm,同時在 SSH 設定中有已信任主機金鑰的 Host 別名。選用設定來自設定檔或環境變數,例如 SSH_MCP_CONFIG 與 SSH_MCP_ALLOWED_HOSTS。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Remote Ssh Mcp,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
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 "…".
來源:README.md,提交 e952a55
工具
0版本歷史
1- v0.2.0最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分