
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 分