一个安全、高性能的模型上下文协议(MCP)服务器,使像 Claude Desktop 这样的 AI 助手能够在远程服务器上执行 SSH 命令。使用 Node.js 和官方 MCP SDK 构建,以实现最大兼容性和可靠性。
🔄 版本 2.1.0 - 高效令牌文件操作:完全重写为 Node.js 并使用官方 MCP SDK —— 消除了所有之前的 Go 兼容性问题!
# 使用 NPX 直接安装(推荐)
npx @idletoaster/ssh-mcp-server@latest
# 或全局安装
npm install -g @idletoaster/ssh-mcp-server
添加到您的 Claude Desktop MCP 配置文件中:
{
"mcpServers": {
"ssh": {
"command": "npx",
"args": ["-y", "@idletoaster/ssh-mcp-server@latest"],
"env": {}
}
}
}
就这样! 现在 Claude 可以在您的远程服务器上执行 SSH 命令了。
配置完成后,Claude 可以帮助您执行如下命令:
“检查生产服务器 192.168.1.100 的磁盘使用情况”
“作为用户 admin 在 server.example.com 上重启 nginx 服务”
“使用我的 SSH 密钥显示我的 Ubuntu 服务器上的运行进程”
{
"tool": "remote-ssh",
"arguments": {
"host": "192.168.1.100",
"user": "ubuntu",
"command": "df -h",
"privateKeyPath": "/home/user/.ssh/id_rsa"
}
}
该服务器支持多种认证方法:
{
"privateKeyPath": "/path/to/your/private/key"
}
export SSH_PRIVATE_KEY="/home/user/.ssh/id_rsa"
自动搜索以下位置的密钥:
~/.ssh/id_rsa~/.ssh/id_ed25519~/.ssh/id_ecdsaid_rsa)id_ed25519)id_ecdsa)node --version)npm --version)从 nodejs.org 下载或使用 Chocolatey:
choco install nodejs
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
sudo yum install -y nodejs
brew install node
# 克隆仓库
git clone https://github.com/idletoaster/ssh-mcp-server.git
cd ssh-mcp-server
# 安装依赖
npm install
# 本地运行
npm start
# 开发模式自动重载
npm run dev
ssh-mcp-server/
├── package.json # NPM 配置及依赖
├── index.js # 主 MCP 服务器(官方 SDK)
├── lib/
│ └── ssh-client.js # SSH 连接管理
├── README.md # 文档
├── LICENSE # MIT 许可证
└── .gitignore # Node.js .gitignore
chmod 600)~/.ssh/config 中限制 SSH 密钥到特定主机# 示例 SSH 配置以限制访问
Host production-server
HostName 192.168.1.100
User deploy
IdentityFile ~/.ssh/production_key
IdentitiesOnly yes
StrictHostKeyChecking yes
# 测试 MCP 服务器
echo '{"host":"test.server.com","user":"testuser","command":"whoami"}' | npm start
# 验证 Node.js 安装
node --version # 应为 18+
npm --version # 应为 9+
# 测试 NPX 执行
npx @idletoaster/ssh-mcp-server@latest --help
从 Go 版本升级? Node.js 版本提供了:
npx @idletoaster/ssh-mcp-server@latestgit checkout -b feature/amazing-featurenpm testMIT 许可证 - 详情见 LICENSE 文件。
为 AI 开发社区使用 Node.js 和官方 MCP SDK 构建
增强功能,包含 4 个强大的工具,灵感来自 Desktop Commander,优化了令牌使用:
// 编辑特定文本块
{
"name": "ssh-edit-block",
"arguments": {
"host": "server.com",
"user": "username",
"filePath": "/path/to/file.js",
"oldText": "version: '2.0.0'",
"newText": "version: '2.1.0'"
}
}
// 仅读取特定行
{
"name": "ssh-read-lines",
"arguments": {
"host": "server.com",
"user": "username",
"filePath": "/path/to/large-file.js",
"startLine": 100,
"endLine": 150
}
}
// 高效模式搜索
{
"name": "ssh-search-code",
"arguments": {
"host": "server.com",
"user": "username",
"path": "/project",
"pattern": "function.*export",
"filePattern": "*.js"
}
}