VOOZH about

URL: https://glama.ai/mcp/servers/YawLabs/ssh-mcp?locale=zh-CN

⇱ SSH MCP 服务器 by YawLabs | Glama


@yawlabs/ssh-mcp

👁 npm version
👁 License: MIT

让 SSH 适配 AI 工具。 MCP 服务器可管理您的 SSH 环境,诊断故障,修复问题,并让您的智能体(Agent)能够远程访问任何资源。

Yaw Labs 构建和维护。

问题所在

AI CLI 工具运行在子进程中,而 SSH 经常会出问题。智能体尝试 git pull 时收到 Permission denied (publickey) 错误;尝试 SSH 连接服务器时发现代理套接字已过期;尝试部署时发现实例重建导致主机密钥变更。每次遇到这些情况,AI 都不知道哪里出了问题,从而陷入困境。

这种情况在所有需要 SSH 密钥的场景中都会发生:

  • Git — clone、pull、push、fetch、submodules、LFS

  • 包管理器 — 从私有仓库进行 npm installpip installgo getcargocomposer

  • 服务器访问 — SSH、SCP、SFTP、rsync

  • 隧道 — 数据库端口转发、SOCKS 代理

  • 部署 — Ansible、Terraform、Capistrano、部署脚本

  • 云服务 — AWS EC2、GCP、Azure、DigitalOcean 以及任何 VPS

ssh-mcp 解决了这些问题。它管理 SSH 代理、加载密钥、通过可执行的修复命令诊断故障,并提供远程操作功能——所有这些都作为您的 AI 智能体可以调用的 MCP 工具。

快速开始

npm install -g @yawlabs/ssh-mcp

添加到您的 MCP 客户端配置中:

{
 "mcpServers": {
 "ssh": {
 "command": "ssh-mcp"
 }
 }
}

工具

SSH 环境管理

用于修复本地 SSH 设置的工具,确保 git、部署、隧道等功能不再中断。

工具

描述

ssh_agent_ensure

确保 ssh-agent 正在运行。如果需要,启动一个并为会话设置环境变量。

ssh_key_list

列出 ~/.ssh/ 中的所有 SSH 密钥,包括类型、指纹和代理状态。

ssh_key_load

将密钥加载到正在运行的代理中。确保先启动代理。

ssh_config_lookup

解析主机的有效 SSH 配置(主机名、用户、端口、代理、身份文件)。

ssh_known_hosts_fix

删除过期的主机密钥并重新扫描。修复“主机密钥验证失败”错误。

ssh_git_check

测试到 GitHub、GitLab、Bitbucket 等平台的 Git-over-SSH 身份验证。

ssh_test

快速连接测试,包含耗时和可操作的错误详情。

诊断

工具

描述

ssh_diagnose

全面的 SSH 环境诊断。检查代理、密钥、配置、known_hosts 和连接性。为每个故障返回精确的修复命令。

远程操作

工具

描述

ssh_exec

在远程主机上执行命令。返回 stdout、stderr 和退出代码。

ssh_read_file

通过 SFTP 从远程主机读取文件。

ssh_write_file

通过 SFTP 将内容写入远程主机的文件。

ssh_upload

通过 SFTP 将本地文件上传到远程主机。

ssh_download

将文件从远程主机下载到本地文件系统。

ssh_ls

列出远程主机目录中的文件。

高级操作

封装了智能体使用 ssh_exec 构建的常见模式的工具——速度更快且不易出错。

工具

描述

ssh_multi_exec

在多台主机上并行运行命令。返回每台主机的结果。

ssh_find

使用结构化参数(名称、类型、大小、深度)远程搜索文件。

ssh_tail

读取文件的最后 N 行,可选择通过 grep 模式进行过滤。

ssh_service_status

检查 systemd 服务状态(活动状态、PID、运行时间、描述)。

自动诊断

当任何远程操作失败时,ssh-mcp 会自动运行诊断并将结果包含在错误响应中。您的智能体无需单独调用 ssh_diagnose——它会在错误消息中直接获知问题所在以及如何修复。

连接池

远程操作会自动重用 SSH 连接。当您的智能体对同一主机进行多次调用时,第一次调用会打开连接,后续调用将重用该连接。连接在最后一次使用后保持 60 秒,然后自动关闭。

SSH 配置支持

所有连接都遵循您的 ~/.ssh/config。主机别名、自定义端口、用户名、身份文件和 ProxyJump 设置都会自动使用。如果您在 SSH 配置中配置了 Host myserver,只需传入 host: "myserver",ssh-mcp 就会解析所有内容。

ProxyJump / 跳板机 自动支持。如果您的 SSH 配置中包含 ProxyJump bastion,ssh-mcp 会透明地通过跳板机连接。链式代理也同样适用。

主机密钥验证

所有远程操作都会根据 ~/.ssh/known_hosts 验证服务器的主机密钥:

  • 已知主机,密钥匹配 — 接受。

  • 已知主机,密钥已更改 — 拒绝(中间人攻击防护)。

  • 未知主机 — 首次连接时接受(TOFU)。使用 ssh_known_hosts_fix 固定密钥以供将来检测不匹配。

对于更严格的环境,设置 SSH_MCP_STRICT_HOST_KEY=1 以拒绝未知主机。请先使用 ssh_known_hosts_fix 显式添加它们。

诊断工具(ssh_testssh_diagnose)在其探测命令中使用 StrictHostKeyChecking=no。这些探测仅运行 echo SSH_OK,不会传递任何凭据或数据,因此这种宽松设置对于连接测试是安全的。实际操作始终通过 hostVerifier 进行。

Windows 支持

在 Windows 上,ssh-mcp 会自动检测 OpenSSH 身份验证代理服务(通过 \\.\pipe\openssh-ssh-agent 命名管道)。无需 SSH_AUTH_SOCK,只需确保 OpenSSH 代理服务正在运行即可。

身份验证

所有远程操作都接受连接参数:

参数

描述

默认值

host

SSH 主机名或 IP(必填)

port

SSH 端口

从 SSH 配置或 22 获取

username

SSH 用户名

从 SSH 配置或当前用户获取

privateKeyPath

SSH 私钥路径

自动检测

password

SSH 密码(优先使用密钥)

身份验证解析顺序: ssh-mcp 从此列表中选择第一个匹配项,不会回退到后续条目——这使得身份验证方法具有确定性和可预测性。

  1. 显式 privateKeyPath

  2. 显式 password

  3. ssh-agent(Unix 上的 SSH_AUTH_SOCK,Windows 上的 \\.\pipe\openssh-ssh-agent

  4. ~/.ssh/config 中针对该主机的身份文件

  5. 默认密钥路径 (~/.ssh/id_ed25519, id_rsa, id_ecdsa)

工作流示例

智能体无法 git pull

Agent calls ssh_git_check → "Permission denied. Your SSH key is not registered with github.com."
Agent calls ssh_key_list → finds id_ed25519 exists but is not loaded
Agent calls ssh_key_load("~/.ssh/id_ed25519") → "Key loaded"
Agent calls ssh_git_check → "Git SSH authentication to github.com succeeded as username"
Agent runs git pull → works

实例重建后主机密钥变更

Agent calls ssh_exec on server → error: "Host key verification failed"
 (auto-diagnostics included in error: "Fix with ssh_known_hosts_fix")
Agent calls ssh_known_hosts_fix("my-server") → "Host key refreshed"
Agent calls ssh_exec → works

首次连接到新服务器

Agent calls ssh_test("new-server") → "Connection refused at new-server:22"
Agent calls ssh_diagnose("new-server") → full report showing agent running, keys loaded, but host unreachable
Agent reports: "SSH server isn't running on new-server or port 22 is blocked"

编程使用

import { connect, exec, diagnose, ensureAgent, listSshKeys, checkGitSsh, ConnectionPool } from '@yawlabs/ssh-mcp';

// Fix SSH environment
const agent = ensureAgent();
console.log(agent.message);

// Check git access
const git = checkGitSsh('github.com');
console.log(git.message);

// List available keys
const keys = listSshKeys();
for (const key of keys) {
 console.log(`${key.name} (${key.type}) - ${key.loadedInAgent ? 'loaded' : 'not loaded'}`);
}

// Run a remote command (one-off)
const client = await connect({ host: 'my-server', username: 'deploy' });
const result = await exec(client, 'uptime');
console.log(result.stdout);
client.end();

// Run multiple commands with connection pooling
const pool = new ConnectionPool();
await pool.withConnection({ host: 'my-server' }, async (client) => {
 const r1 = await exec(client, 'uptime');
 console.log(r1.stdout);
});
// Connection stays open for 60s — next call reuses it
await pool.withConnection({ host: 'my-server' }, async (client) => {
 const r2 = await exec(client, 'df -h');
 console.log(r2.stdout);
});
pool.drain(); // close all connections when done

// Diagnose issues
const report = diagnose('my-server');
console.log(report.overall); // "ok" | "warning" | "error"
for (const check of report.checks) {
 console.log(`[${check.status}] ${check.name}: ${check.message}`);
}

要求

  • Node.js 18+

  • 已安装 SSH 客户端(用于诊断和环境管理)

许可证

MIT

A
license - permissive license
A
quality
A
maintenance

Maintenance

Maintainers
<1hResponse time
3dRelease cycle
18Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/YawLabs/ssh-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server