
MCP SSH Gateway
io.github.d00mus由 GitHub 账号 d00mus 发布v7.0.0更新于 Nov 10, 2026
SSH terminals for AI agents: stateful shells, exit codes the moment a command ends, router CLIs.
概览
让 AI 助手通过 SSH 操作远程主机:有状态的 shell、命令结束即返回退出码,输出可分页读取。
- 可以做什么
- 列出已配置的 SSH 服务器及其打开的会话
- 在新会话或已有会话中执行命令,返回状态、退出码和输出
- 继续读取输出、查看末尾内容或回滚浏览会话缓冲区
- 通过 stdin 回答交互提示,或用 Ctrl+C、Ctrl+D 终止命令
- 通过 SFTP 或经由 shell 列出、读取、写入和编辑远程文件
- 在启用添加服务器选项时向配置中追加服务器
- 适用场景
- 适合让助手通过 SSH 检查或操作你掌控的 Linux 主机,例如查看磁盘占用、运行构建、读取日志、编辑远程文件,并且需要可靠的命令结束判断和退出码,而不是靠输出静默来猜测。
- 运行要求
- 以 stdio 方式在本地运行,需要 Python 3.11+(或 uv)以及对你所控制主机的 SSH 访问权限。服务器来自 JSON 配置文件或内联 JSON 字符串,也可用导入选项读取现有 SSH 配置。密码或密钥口令登录可在配置中引用环境变量(如 ROUTER_PASSWORD);可选设置包括 SSH_SERVERS_CONFIG、SSH_READ_ONLY、SSH_COMMAND_BLACKLIST 和 SSH_MCP_CACHE_DIR。
安装
在 SourceWeft 中
- 打开 控制台中的 MCP SSH Gateway,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
MCP SSH Gateway
SSH terminals for AI agents that know when a command is done.
Six tools, real shells that keep their state, the exit code the moment a command ends, and answers a small model can act on. One direct dependency (paramiko), no daemon, nothing in the cloud.
[CI] [Python 3.11+] [PyPI] [License: MIT]
English · Русский
Why this one
- It knows when a command is done. The shell itself reports the end and the exit code, so
echo hireturns in milliseconds, a failing command saysexit_code: 2, and a three-minute build answersrunningafter 10 seconds and is collected withread. No sleeps, no guessing from silence. - Terminals with state. A session is one real shell:
cd, variables and virtualenvs stay between calls.runwithout asession_idopens a new shell, so nothing is shared by accident. - Made for small models. Six tools, about 1.6k tokens of descriptions in total. Every stop says what to do next (
hint), pagers are off, a progress bar is one line, a wrong argument gets an answer that names the right call, and long output comes in pages (has_more,tail,offset). - Questions do not hang.
Continue? [y/N], a password prompt or an unclosed quote returnswaiting_input. The agent answers withsignalor presses Ctrl+C, and the shell keeps its state. - Routers too. A Keenetic router CLI (
show interface,--More--handled) or its Linux shell, through the same tools. - Tested against real
sshd. Containers with bash, BusyBox ash, zsh, dash, fish and tcsh logins and a host without SFTP run in CI on every push.
Quick start
You need uv (or Python 3.11+ and pip) and SSH access to a host you control.
Already have ~/.ssh/config? Add this to your MCP client, and every host in that file becomes a server (key or agent login):
This is the format of Cursor (~/.cursor/mcp.json) and Claude Desktop (claude_desktop_config.json); other clients are below. Restart the client and ask: "List my SSH servers and show the disk usage on web."
Want a password login, a router or a read-only host? Write a servers.json:
and point the gateway at it with "args": ["mcp-ssh-gateway", "--servers-config", "/absolute/path/to/servers.json"]. Use an absolute path (clients do not start in your folder; on Windows escape backslashes in JSON) and give the gateway the variables it refers to in the client's "env" block. servers.json.example also shows a read-only production host. Without uv: pip install mcp-ssh-gateway and "command": "mcp-ssh-gateway".
Other clients
Claude Code
VS Code (.vscode/mcp.json: the top key is servers)
Codex (~/.codex/config.toml, or codex mcp add ssh -- uvx mcp-ssh-gateway --import-ssh-config)
The gateway is also listed in the official MCP Registry as io.github.d00mus/mcp-ssh-gateway, for the clients and directories that read it.
What the agent sees
Answers as a client receives them, captured from the test suite's Debian container (the host address and the disk figures are replaced with example values):
A mistake gets an answer that names the right call. This is what a model that invents a cwd argument for run reads back:
Tools
Sessions are named server/N. A shell has state (folder, variables), so there is no default one: run without session_id always opens a new shell and returns its id, and that id continues the same shell. Close the shells you are done with.
What it works with
The gateway itself runs wherever Python 3.11+ runs (Linux, macOS, Windows).
Security
The agent has the reach of the SSH account you give it. What follows narrows the damage from mistakes; it does not replace a restricted account.
- Guardrails are mistake guards.
read_onlyandcommand_blacklist(literal words, case-insensitive) look at the command text. Shell tricks,base64orpython -cget around them. For a real boundary use a restricted SSH account: a read-only shell,ForceCommand, separate credentials per trust level. - Local files are off.
local_path(upload, download) works only after you start the gateway with--project-root <folder>, and then only inside that folder. - Host keys: a new host is trusted on first contact and its key is kept in
known_hostsin the cache directory; a changed key is refused.verify_host: falseturns the check off. - Secrets: put
${NAME}references inservers.jsoninstead of the values. Logs mask password-like values (--log-output offwrites no logs). - No listening port: the gateway talks MCP over stdio only.
server_adddoes not exist unless you start it with--allow-add-server, and it only appends.
The full policy and how to report a problem: SECURITY.md.
Configuration
servers.json fields: host, user, port (22), key_path (~ and ${NAME} work), password and key_passphrase (only ${NAME} references are replaced, the rest is used as written), verify_host (true), description, extra_path (added to PATH), read_only, command_blacklist, max_sessions (8), shell (a POSIX shell to exec after login, for fish or tcsh accounts). The file is re-read while the gateway runs; unchanged servers keep their sessions.
Command line (none is required except a source of servers):
Logs: one JSON-lines file per session and one per command under the cache directory; old files are pruned by age and size.
How it works
The gateway opens an interactive shell with a PTY and switches it to a quiet, machine-readable mode with one setup line: no echo, and a prompt that prints a marker containing the exit code. When the marker appears the command is over and the agent has its exit code. This also covers syntax errors, background jobs and Ctrl+C. An unclosed quote or heredoc is recognised by a second marker.
Routers whose login is a vendor CLI (Keenetic NDM) have no such shell. There the gateway learns the prompt from the login banner, removes the echo of the typed command, presses space at --More-- and treats a stable prompt as the end of the command. run(shell=false) uses the CLI, run(shell=true) enters the Linux shell behind it; a session keeps one mode.
Output goes into one line-based buffer per session with a single unread position. run and read advance it; tail jumps to the end; offset only looks. Lines longer than 1024 characters are split so that pages stay predictable.
Limits
- A shell runs one command at a time. For two things at once open two shells (or let your client call
runin parallel). - A shell started inside a session (
sudo -s,su,bash) hides where commands end, so the gateway tells the agent to leave it. Usesudo <command>for root. - No jump hosts yet (#2), no other router CLIs yet (#1).
- The gateway has no approvals, policy engine or audit trail. If you need those, see below.
Other SSH servers for MCP
They make different trade-offs (as of September 2026; read their READMEs before choosing):
- tufantunc/ssh-mcp: security first. Command classification, role and host policy, human approval, audit log,
ProxyJump, SSH CA and streaming SFTP; 14 tools. Choose it for production fleets that need approvals and an audit trail. - classfang/ssh-mcp-server: 4 tools on Node (
npx) with a command whitelist, SOCKS and HTTP proxies, a bastion mode and MFA. Choose it for the smallest Node setup that needs proxies or MFA. - bvisible/mcp-ssh-manager: 37 tools, a DevOps toolbox with backups, databases and monitoring. Choose it if you want those workflows ready-made.
This gateway chooses the other end: few tools, stateful shells, and an answer for every situation an agent gets stuck in.
Docker
The cache volume keeps known_hosts and the logs between runs.
Development
Integration tests start real sshd containers and drive the gateway through the same JSON-RPC entry point a client uses. They skip themselves when Docker is missing (MCP_SSH_IT=0 skips on purpose). See CONTRIBUTING.md and the changelog. MIT-licensed.
来源:README.md,提交 35b3f5c
工具
0版本历史
2- v7.0.0最新Sep 29, 2026
- v6.0.1Sep 28, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分