远程命令MCP服务器
一种模型上下文协议(MCP)服务器,支持跨不同操作系统执行远程命令。该服务器提供了一个统一的界面来执行shell命令,自动处理Windows和类Unix系统之间特定于平台的差异。
特性
- 跨平台命令执行
- Windows和Unix之间的自动命令规范化
- 内置错误处理和输出流
- 工作目录规范支持
- 平台特定外壳选择
安装
- 克隆存储库:
git clone https://github.com/deepsuthar496/Remote-Command-MCP
cd remote-command-server- 安装依赖项:
npm install- 构建服务器:
npm run build- 在设置文件中配置MCP服务器:
适用于克劳德桌面(claude_desktop_config.json):
{
"mcpServers": {
"remote-command": {
"command": "node",
"args": ["path/to/remote-command-server/build/index.js"],
"disabled": false,
"autoApprove": []
}
}
}用于VSCode临床扩展(cline_mcp_settings.json):
{
"mcpServers": {
"remote-command": {
"command": "node",
"args": ["path/to/remote-command-server/build/index.js"],
"disabled": false,
"autoApprove": []
}
}
}用法
服务器提供了一个名为 execute_remote_command 可以在主机上执行任何有效的shell命令。这包括:
- 系统命令
- 包管理器命令(apt、yum、chocolatey等)
- 开发工具(git、npm、python等)
- 文件 操作
- 网络命令
- 服务管理
- 以及系统上可用的任何其他CLI命令
工具:execute_remote_command
参数:
command(必填):可以在主机操作系统上执行的任何有效shell命令cwd(可选):命令执行的工作目录
例子
- 系统信息:
remote-command
execute_remote_command
{
"command": "systeminfo" // Windows
// or "uname -a" // Linux
}
- 包管理:
remote-command
execute_remote_command
{
"command": "npm list -g --depth=0" // List global NPM packages
}
- 网络操作:
remote-command
execute_remote_command
{
"command": "netstat -an" // Show all network connections
}
- Git操作:
remote-command
execute_remote_command
{
"command": "git status",
"cwd": "/path/to/repo"
}
- 文件操作:
remote-command
execute_remote_command
{
"command": "ls -la", // List files with details
"cwd": "/path/to/directory"
}
- 流程管理:
remote-command
execute_remote_command
{
"command": "ps aux" // List all running processes (Unix)
// or "tasklist" // Windows equivalent
}
- 服务控制:
remote-command
execute_remote_command
{
"command": "systemctl status nginx" // Check service status (Linux)
// or "sc query nginx" // Windows equivalent
}
安全考虑
由于此服务器可以执行任何系统命令,请考虑以下安全措施:
- 访问控制:仅允许受信任的用户访问MCP服务器
- 命令验证:在应用程序逻辑中执行命令之前验证命令
- 工作目录:使用
cwd用于将命令执行限制在特定目录的参数 - 环境:请谨慎使用修改系统设置或敏感文件的命令
- 权限:以适当的用户权限运行MCP服务器
跨平台指挥处理
服务器会自动处理平台特定的差异:
- 命令翻译:
- ls ⟷ dir (根据平台自动转换) - 为每个平台设置适当的管道操作员格式
- 外壳选择:
- Windows:用途 cmd.exe - Unix/Linux:使用 /bin/sh
错误处理
服务器提供详细的错误消息,并在响应中包含stdout和stderr。如果命令失败,您将收到一条错误消息,其中包含错误的详细信息。
错误响应示例:
{
"content": [
{
"type": "text",
"text": "Command execution error: Command failed with exit code 1"
}
],
"isError": true
}发展
项目结构
remote-command-server/
├── src/
│ └── index.ts # Main server implementation
├── package.json
├── tsconfig.json
└── README.md建筑
npm run build这将编译TypeScript代码并在 build 目录。
贡献
- 分叉存储库
- 创建功能分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add some amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。
