mcp-ssh-tool
mcp-ssh-tool
面向运维人员、开发人员和 AI 客户端的生产级 MCP SSH 自动化工具。mcp-ssh-tool 可开启持久化 SSH 会话,并提供安全、结构化的工具,用于命令执行、文件操作、传输、隧道、软件包/服务管理、指标监控、资源访问及引导式提示。
v2 版本默认安全:开启严格的主机密钥验证,禁用 root 登录,原始 sudo 受策略限制,除非策略允许,否则拒绝破坏性命令和文件系统变更;远程 HTTP 仅在回环地址上启动,除非配置了 bearer 令牌和允许的来源。
为什么选择此服务器
信任: 中心化策略引擎、结构化审计事件、脱敏日志、严格的主机密钥以及机器可读的错误信息。
MCP 质量: 本地客户端使用 stdio,远程客户端使用可流式传输的 HTTP,仅在显式兼容性标志下支持旧版 SSE。
AI 友好工具: 稳定的输出模式、
structuredContent、针对只读/破坏性/幂等行为的注解、资源以及精选提示词。运维: 会话 TTL/驱逐、命令超时、传输校验和验证、真实的 SSH 转发、Prometheus 指标以及 OpenTelemetry 钩子。
可移植性: 优先使用 SFTP,针对基本文件操作提供 POSIX/BusyBox 感知 shell 后备方案,并明确支持边界。
快速开始
无需安装直接运行:
npx -y mcp-ssh-tool --version或全局安装:
npm install -g mcp-ssh-tool将 stdio MCP 服务器添加到您的客户端:
{
"servers": {
"ssh-mcp": {
"type": "stdio",
"command": "mcp-ssh-tool",
"args": []
}
}
}在您的 MCP 客户端中使用它:
Open a safe SSH session to prod-1 as deploy, inspect host capabilities, then show disk usage.要求
Node.js
22.22.2+或24.14.1+(仅限 LTS 版本)对目标主机的 SSH 访问权限
包含已填充的
known_hosts文件以进行严格的主机验证,或显式的每会话主机密钥策略
传输方式
模式 | 命令 | 使用场景 |
stdio |
| 本地桌面客户端,如 ChatGPT、Claude Desktop、VS Code、Cursor 或 Codex。 |
Streamable HTTP |
| 远程 MCP 客户端、反向代理或 Inspector 会话。 |
legacy SSE |
| 仅用于临时 v1 兼容性。建议优先使用 Streamable HTTP。 |
除非同时配置了 --bearer-token-file 和允许的来源,否则拒绝非回环地址的 HTTP 启动。
安全默认设置
领域 | v2 默认值 |
主机密钥 |
|
Root SSH 登录 | 拒绝 |
原始 | 拒绝,除非 |
破坏性命令 | 拒绝,除非 |
破坏性文件系统操作 | 仅在策略前缀下允许,其他位置拒绝 |
HTTP 绑定 |
|
旧版 SSE | 禁用 |
文件读取 | 受 |
每会话的 policyMode: "explain" 会返回计划/判定而不执行。当 AI 客户端需要总结风险时,请在变更前使用此模式。
策略示例
设置 SSH_MCP_POLICY_FILE=/etc/mcp-ssh-tool/policy.json:
{
"mode": "enforce",
"allowRootLogin": false,
"allowRawSudo": false,
"allowDestructiveCommands": false,
"allowDestructiveFs": false,
"allowedHosts": ["^prod-[0-9]+\\.example\\.com$"],
"commandAllow": ["^(uname|df|uptime|systemctl status)\\b"],
"commandDeny": ["rm\\s+-rf\\s+/", "shutdown", "reboot"],
"pathAllowPrefixes": ["/tmp", "/var/tmp", "/home/deploy"],
"pathDenyPrefixes": ["/etc/shadow", "/etc/sudoers", "/boot", "/dev", "/proc"]
}简单的部署可以使用环境变量覆盖,例如 SSH_MCP_ALLOW_RAW_SUDO=true、SSH_MCP_ALLOWED_HOSTS=prod-1.example.com 或 SSH_MCP_PATH_ALLOW_PREFIXES=/tmp,/home/deploy。
核心工具
ssh_open_session,ssh_close_session,ssh_list_sessions,ssh_ping,ssh_list_configured_hosts,ssh_resolve_hostproc_exec,proc_sudo,proc_exec_streamfs_read,fs_write,fs_list,fs_stat,fs_mkdirp,fs_rmrf,fs_renamefile_upload,file_downloadensure_package,ensure_service,ensure_lines_in_file,patch_applyos_detect,get_metricstunnel_local_forward,tunnel_remote_forward,tunnel_list,tunnel_close
所有工具均返回文本及稳定的 structuredContent。工具元数据包含标题、输出模式以及披露只读、破坏性、幂等和外部副作用行为的注解。
资源与提示词
资源:
mcp-ssh-tool://sessions/activemcp-ssh-tool://metrics/jsonmcp-ssh-tool://metrics/prometheusmcp-ssh-tool://ssh-config/hostsmcp-ssh-tool://policy/effectivemcp-ssh-tool://audit/recentmcp-ssh-tool://capabilities/support-matrix
提示词:
safe-connectinspect-host-capabilitiesplan-mutationmanaged-config-change
支持矩阵
目标 | 状态 |
Linux | 完全支持。 |
macOS/BSD | 支持会话、进程、文件系统和传输;软件包/服务助手仅在已测试的环境中支持。 |
BusyBox/dropbear | 会话、进程和基本文件系统后备方案处于实验阶段。 |
Windows SSH 目标 | 会话、进程、文件系统和传输处于实验阶段;不支持 |
客户端示例
ChatGPT 或 Claude Desktop:
{
"mcpServers": {
"ssh-mcp": {
"command": "npx",
"args": ["-y", "mcp-ssh-tool"]
}
}
}VS Code 或 Cursor:
{
"servers": {
"ssh-mcp": {
"type": "stdio",
"command": "mcp-ssh-tool"
}
}
}通过 HTTP 使用 MCP Inspector:
printf '%s' 'super-secret-token' > .mcp-token
mcp-ssh-tool --transport=http --host 127.0.0.1 --port 3000 --bearer-token-file .mcp-token配置
高价值环境变量:
变量 | 默认值 | 用途 |
| 未设置 | 规范的 JSON 策略源。 |
|
|
|
|
| 用于严格验证的 known-hosts 文件。 |
|
|
|
|
| 默认命令超时时间。 |
|
| 可流式传输 HTTP 的绑定主机。 |
|
| 可流式传输 HTTP 的端口。 |
| 未设置 | 非回环地址 HTTP 必需。 |
| 回环来源 | 以逗号分隔的允许来源。 |
已弃用的别名 STRICT_HOST_KEY_CHECKING 和 SSH_MCP_STRICT_HOST_KEY 在 v2 兼容周期内仍被接受。建议优先使用 SSH_MCP_HOST_KEY_POLICY。
开发
使用 .nvmrc / .node-version 中的精确本地运行时,然后运行:
npm ci
npm run check实时 SSH 套件为可选:
RUN_SSH_INTEGRATION=1 npm run test:integration
RUN_SSH_E2E=1 npm run test:e2e本地质量门禁是分层的:
pre-commit:格式化暂存文件并仅对暂存的 TypeScript 进行 lint 检查pre-push:运行npm run check:pushtask hooks:在安装pre-commit时运行跟踪的 npm 钩子及.pre-commit-config.yaml钩子手动/完全对齐:
task ci或npm run check
CI/CD 所有权
个人仓库 https://github.com/oaslananka/mcp-ssh-tool 是规范的源仓库。自动 CI/CD、供应链安全检查、受信任的 npm 发布以及 MCP Registry 发布仅从 https://github.com/oaslananka-lab/mcp-ssh-tool 运行。组织仓库从规范源拉取;个人仓库的推送和发布工作流已禁用。
npm 包的 repository.url 特意指向组织仓库,以便 npm 来源验证可以确认发布的工件来自构建它的同一个 GitHub Actions 仓库。
参见 docs/ci-cd-topology.md 获取组织同步、发布流程和手动后备指南。
文档
许可证
MIT 许可证。参见 LICENSE。
Available Tools
33 toolsconnector_statusConnector StatusARead-onlyIdempotent
Use this when ChatGPT or Claude needs to understand the remote connector profile, authentication mode, and credential broker readiness without exposing secrets.
Inputs: no named parameters. Returns: Remote connector readiness without secrets
ensure_lines_in_fileEnsure Lines In FileADestructiveIdempotent
Ensures specific lines are present or absent in a file
Inputs: sessionId (required), path (required), lines (required), state, +1 more. Returns: Line management result
ensure_packageEnsure Package StateCDestructiveIdempotent
Ensures a package is installed or removed
Inputs: sessionId (required), name (required), state. Returns: Package state result
ensure_serviceEnsure Service StateBDestructiveIdempotent
Ensures a service is in the desired state
Inputs: sessionId (required), name (required), state (required). Returns: Service state result
file_downloadDownload FileARead-only
Downloads a remote file to the local machine over SFTP
Inputs: sessionId (required), remotePath (required), localPath (required). Returns: Download result with integrity details
file_uploadUpload FileBDestructive
Uploads a local file to the remote host over SFTP
Inputs: sessionId (required), localPath (required), remotePath (required). Returns: Upload result with integrity details
fs_listList Remote DirectoryCRead-onlyIdempotent
Lists directory contents
Inputs: sessionId (required), path (required), page, limit. Returns: Remote directory entries
fs_mkdirpCreate Remote DirectoriesAIdempotent
Creates directories recursively
Inputs: sessionId (required), path (required). Returns: Directory creation result
fs_readRead Remote FileBRead-onlyIdempotent
Reads a file from the remote system
Inputs: sessionId (required), path (required), encoding, maxBytes. Returns: Remote file content wrapped as structured content
fs_renameRename Remote PathBDestructive
Renames or moves a file/directory
Inputs: sessionId (required), from (required), to (required). Returns: Rename result
fs_rmrfRemove Remote Path RecursivelyADestructive
Removes files or directories recursively
Inputs: sessionId (required), path (required). Returns: Recursive remove result
fs_statStat Remote PathARead-onlyIdempotent
Gets file or directory statistics
Inputs: sessionId (required), path (required). Returns: Remote path stat result
fs_writeWrite Remote FileBDestructive
Writes data to a file on the remote system
Inputs: sessionId (required), path (required), data (required), mode. Returns: File write result
get_metricsGet Runtime MetricsARead-onlyIdempotent
Returns server metrics including session counts, command statistics, and uptime
Inputs: format. Returns: Runtime metrics
os_detectDetect Remote OSARead-onlyIdempotent
Detects operating system and environment information
Inputs: sessionId (required). Returns: Remote operating system information
patch_applyApply PatchBDestructive
Applies a patch to a file
Inputs: sessionId (required), path (required), diff (required). Returns: Patch application result
proc_execExecute Remote CommandA
Executes a non-interactive command on the remote system after policy and safety checks
Inputs: sessionId (required), command (required), cwd, env, +1 more. Returns: Remote command result
proc_exec_streamExecute Streaming CommandA
Executes a command and returns streaming output chunks
Inputs: sessionId (required), command (required), cwd, env, +1 more. Returns: Streaming command result with output chunks
proc_sudoExecute Sudo CommandADestructive
Executes a command with sudo privileges only when allowRawSudo policy permits it
Inputs: sessionId (required), command (required), cwd, timeoutMs. Returns: Remote sudo command result
ssh_close_sessionClose SSH SessionBIdempotent
Closes an SSH session
Inputs: sessionId (required). Returns: Boolean close result wrapped as structured content
ssh_host_inspectInspect SSH HostARead-only
Use this when ChatGPT or Claude needs read-only host inspection through the server-side credential broker. The user supplies only a configured host alias and selected checks; no secret material or login details are accepted.
Inputs: hostAlias (required), checks. Returns: Read-only host inspection result
ssh_hosts_listList Safe SSH Host AliasesARead-onlyIdempotent
Use this when ChatGPT or Claude needs a safe list of SSH host aliases that may be inspected through the remote connector. Sensitive login material is omitted.
Inputs: no named parameters. Returns: Redacted SSH host aliases allowed by policy
ssh_list_configured_hostsList Configured HostsARead-onlyIdempotent
Lists all hosts configured in ~/.ssh/config
Inputs: no named parameters. Returns: Configured SSH host aliases
ssh_list_sessionsList SSH SessionsARead-onlyIdempotent
Lists all active SSH sessions with their details
Inputs: no named parameters. Returns: Active SSH sessions
ssh_mutation_planPlan SSH MutationARead-onlyIdempotent
Use this when ChatGPT or Claude needs a non-executing plan for a remote SSH change. It never runs commands, writes files, uploads data, starts tunnels, or escalates privileges.
Inputs: hostAlias (required), goal (required), category. Returns: Non-executing remote mutation plan
ssh_open_sessionOpen SSH SessionB
Opens a new SSH session with authentication
Inputs: host (required), username (required), port, auth, +12 more. Returns: Session creation result or explain-mode connection plan
ssh_pingPing SSH SessionARead-onlyIdempotent
Checks if an SSH session is still alive and responsive
Inputs: sessionId (required). Returns: Session health check result
ssh_policy_explainExplain SSH PolicyARead-onlyIdempotent
Use this when ChatGPT or Claude needs to explain whether a requested SSH inspection or mutation would be allowed. This is explain-only and does not execute commands or open tunnels.
Inputs: hostAlias, action, command, path. Returns: Explain-only policy decision
ssh_resolve_hostResolve SSH HostARead-onlyIdempotent
Resolves a host alias from ~/.ssh/config to connection parameters
Inputs: hostAlias (required). Returns: Resolved SSH connection parameters
tunnel_closeClose SSH TunnelBIdempotent
Closes an active tunnel
Inputs: tunnelId (required). Returns: Tunnel close result
tunnel_listList SSH TunnelsARead-onlyIdempotent
Lists active tunnels, optionally filtered by session
Inputs: sessionId. Returns: Active tunnels
tunnel_local_forwardCreate Local SSH TunnelC
Creates a local SSH port forward
Inputs: sessionId (required), localPort (required), remoteHost (required), remotePort (required). Returns: Local tunnel information
tunnel_remote_forwardCreate Remote SSH TunnelC
Creates a remote SSH port forward
Inputs: sessionId (required), remotePort (required), localHost (required), localPort (required). Returns: Remote tunnel information
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 33 tools
Each tool targets a distinct operation or resource type (file, command, session, tunnel, package, service, inspection). There is no significant overlap; even similar tools like proc_exec and proc_exec_stream are differentiated by execution mode.
Tools are grouped by domain (fs_, proc_, tunnel_, ssh_, ensure_) with consistent patterns within groups. However, the overall naming convention mixes prefixes (fs_list vs file_download) and some tools use long phrasal names (ensure_lines_in_file).
At 33 tools, the server is heavily featured. While most tools serve a clear purpose, the count is above the typical sweet spot and includes several niche utilities (get_metrics, os_detect, ssh_mutation_plan) that could be consolidated.
The tool surface covers the full lifecycle of SSH interactions: session management, file operations, command execution, package/service management, tunneling, and safety/planning. No obvious gaps exist for a generic SSH administration server.
Maintenance
Related MCP Connectors
Connect ChatGPT and Claude to your Mac, Windows or Linux with secure MCP remote access.
Termalin's hosted MCP server. Claude, ChatGPT or any MCP client runs commands, moves files over SFTP, queries databases and reads server metrics and monitoring alerts on your servers, keylessly through Termalin Connectors: no SSH key is handed over and no inbound port is opened. Per-host command policy and an audit log. Needs a termal.in Pro or Team account (new accounts start with a 14-day Pro trial).
Remote MCP server exposing your Node Command fleet (files, shell, processes, browser) to AI hosts.
Remote MCP server for supportsheep: run AI interviews and manage support content for your blog.