🔗 RemoteShell MCP
A. 模型上下文协议(MCP) 使LLM能够安全地管理和执行远程SSH服务器上的命令的服务器。
✨ 特性
- 🔐 安全的凭证管理 -保存SSH服务器配置文件一次,无需重新键入凭据
- 💻 远程命令执行 -远程执行非交互式shell命令
- 📁 文件 操作 -通过SFTP上传/下载文件
- 🤖 LLM供电 -内置于 FastMCP 帕拉米科
🚀 安装
适用于Claude Code用户
claude mcp add remoteshell --scope user -- uvx remoteshell-mcp对于其他MCP客户端
将此添加到MCP客户端配置中:
{
"mcpServers": {
"remoteshell": {
"command": "uvx",
"args": ["remoteshell-mcp"]
}
}
}📖 用法
开始很容易!您可以:
- 🤖 让LLM为您配置 -只需告诉LLM您的主机、用户名、密码等,并要求它设置服务器配置
- ⚙️ 手动配置 -直接在以下位置编辑配置文件
~/.config/remoteshell/hosts.json
💾 配置和存储
RemoteShell将您的服务器配置安全地存储在:
~/.config/remoteshell/hosts.json🔧 配置管理
- LLM管理:LLM使用以下命令自动管理此文件
save_server和remove_server工具 - 手动编辑:您还可以直接编辑JSON文件以进行高级配置
📋 配置示例
{
"version": 1,
"servers": {
"production-server": {
"host": "1.2.3.4",
"user": "root",
"port": 22,
"auth_type": "password",
"password": "your_secure_password",
"last_connected": null
},
"staging-server": {
"host": "staging.example.com",
"user": "ubuntu",
"port": 22,
"auth_type": "private_key",
"private_key": "~/.ssh/id_rsa",
"last_connected": "2025-01-01T00:00:00+00:00"
}
}
}🔒 安全说明
在POSIX系统上,保护您的配置文件:
chmod 600 ~/.config/remoteshell/hosts.json🛠️ 可用工具
RemoteShell为远程服务器管理提供了以下MCP工具:
📋 list_servers()
目的:显示所有已保存的服务器配置文件及其连接状态和上次活动。
何时使用:
- 用户要求“连接到服务器”或“显示机器”
- 无特定
connection_id被提供 - 需要查看可用服务器
示例: *“显示我配置了哪些服务器”* → 返回所有已保存且处于联机状态的服务器的列表
💾 save_server(connection_id, host, user, auth_type, credential)
目的:使用身份验证凭据创建或更新服务器配置文件。
参数:
connection_id:服务器的唯一标识符(例如,“生产”、“暂存”)host:服务器主机名或IP地址user:SSH用户名auth_type:"password"或"private_key"credential:
- 对于 password:纯文本密码字符串 - 对于 private_key:文件路径(例如。, ~/.ssh/id_rsa)或PEM密钥内容
何时使用:
- 添加新的服务器配置
- 身份验证失败后更新凭据
- 更改服务器连接详细信息
🗑️ remove_server(connection_id)
目的:从存储中永久删除服务器配置文件。
何时使用:
- 用户明确请求删除或忘记服务器
- 服务器不再可访问或不需要
⚠️ 警告:此操作无法撤消
⚡ execute_command(connection_id, command)
目的:远程执行非交互式shell命令并返回结果。
退货: stdout, stderr,以及 exit_code
何时使用:
- 运行系统命令、脚本或实用程序
- 检查服务器状态、磁盘使用情况、进程列表
- 文件操作、包管理等。
何时不使用:
- 交互式程序(vim、htop、top)
- 需要手动输入的命令(
[Y/n]提示)-除非使用以下标志-y
示例: execute_command(connection_id="production", command="df -h")
📤 upload_file(connection_id, local_path, remote_path)
目的:通过SFTP将文件从本地计算机上传到远程服务器。
参数:
local_path:本地计算机上文件的路径remote_path:远程服务器上的目标路径
备注:
- 如果
remote_path是一个目录,保留原始文件名 - 如果
local_path如果省略,服务器将选择默认值并返回作为响应
📥 download_file(connection_id, remote_path, local_path)
目的:通过SFTP将文件从远程服务器下载到本地计算机。
参数:
remote_path:远程服务器上文件的路径local_path:本地计算机上的目标路径
备注:
- 如果
local_path省略,默认为:~/.config/remoteshell/downloads//
🧪 发展
地方发展设置
对于本地开发,请使用此MCP配置:
{
"mcpServers": {
"remoteshell": {
"command": "uv",
"args": ["--directory", "/absolute/path/to/remoteShell-mcp", "run", "remoteshell-mcp"]
}
}
}运行测试
uv run pytest