
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 分