远程命令 MCP 服务器
一个模型上下文协议 (MCP) 服务器,支持跨不同操作系统执行远程命令。该服务器提供统一的接口来执行 Shell 命令,自动处理 Windows 和类 Unix 系统之间的平台特定差异。
特征
Related MCP server: Shell MCP Server
安装
克隆存储库:
git clone https://github.com/deepsuthar496/Remote-Command-MCP
cd remote-command-server
安装依赖项:
构建服务器:
在您的设置文件中配置 MCP 服务器:
对于 VSCode Cline 扩展( 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命令。其中包括:
工具:execute_remote_command
参数:
示例
系统信息:
<use_mcp_tool>
<server_name>remote-command</server_name>
<tool_name>execute_remote_command</tool_name>
<arguments>
{
"command": "systeminfo" // Windows
// or "uname -a" // Linux
}
</arguments>
</use_mcp_tool>
包管理:
<use_mcp_tool>
<server_name>remote-command</server_name>
<tool_name>execute_remote_command</tool_name>
<arguments>
{
"command": "npm list -g --depth=0" // List global NPM packages
}
</arguments>
</use_mcp_tool>
网络运营:
<use_mcp_tool>
<server_name>remote-command</server_name>
<tool_name>execute_remote_command</tool_name>
<arguments>
{
"command": "netstat -an" // Show all network connections
}
</arguments>
</use_mcp_tool>
Git操作:
<use_mcp_tool>
<server_name>remote-command</server_name>
<tool_name>execute_remote_command</tool_name>
<arguments>
{
"command": "git status",
"cwd": "/path/to/repo"
}
</arguments>
</use_mcp_tool>
文件操作:
<use_mcp_tool>
<server_name>remote-command</server_name>
<tool_name>execute_remote_command</tool_name>
<arguments>
{
"command": "ls -la", // List files with details
"cwd": "/path/to/directory"
}
</arguments>
</use_mcp_tool>
流程管理:
<use_mcp_tool>
<server_name>remote-command</server_name>
<tool_name>execute_remote_command</tool_name>
<arguments>
{
"command": "ps aux" // List all running processes (Unix)
// or "tasklist" // Windows equivalent
}
</arguments>
</use_mcp_tool>
服务控制:
<use_mcp_tool>
<server_name>remote-command</server_name>
<tool_name>execute_remote_command</tool_name>
<arguments>
{
"command": "systemctl status nginx" // Check service status (Linux)
// or "sc query nginx" // Windows equivalent
}
</arguments>
</use_mcp_tool>
安全注意事项
由于此服务器可以执行任何系统命令,请考虑以下安全措施:
访问控制:仅限受信任的用户访问 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
建筑
这将编译 TypeScript 代码并在build目录中创建可执行文件。
贡献
分叉存储库
创建你的功能分支( git checkout -b feature/amazing-feature )
提交您的更改( git commit -m 'Add some amazing feature' )
推送到分支( git push origin feature/amazing-feature )
打开拉取请求
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅 LICENSE 文件。