关于 Remote Command MCP Server
Remote Command MCP Server 让 MCP 客户端在 Windows 和类 Unix 主机上运行 Shell 命令,并处理平台差异。它支持指定工作目录、流式输出和错误详情。
主要功能
- 01跨平台执行 Shell 命令
- 02规范化 Windows 与 Unix 命令差异
- 03设置命令工作目录
- 04流式传递输出并报告错误
- 05选择平台对应的 Shell
适用场景
- 01运行系统或开发命令
- 02管理文件并检查代码仓库
- 03查看进程、网络连接或服务
MCP 相关
该 MCP 服务提供 execute_remote_command 工具,可接收命令和可选的工作目录。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
远程命令 MCP 服务
一个模型上下文协议(MCP)服务,可在不同操作系统上执行远程命令。该服务提供统一的接口来执行 shell 命令,并自动处理 Windows 和类 Unix 系统之间的平台差异。
功能
- 跨平台执行命令
- 自动转换 Windows 和 Unix 命令
- 内置错误处理和输出流式传输
- 支持指定工作目录
- 根据平台选择 shell
安装
- 克隆仓库:
git clone https://github.com/deepsuthar496/Remote-Command-MCP
cd remote-command-server
- 安装依赖项:
npm install
- 构建服务:
npm run build
- 在设置文件中配置 MCP 服务:
对于 Claude Desktop(claude_desktop_config.json):
{
"mcpServers": {
"remote-command": {
"command": "node",
"args": ["path/to/remote-command-server/build/index.js"],
"disabled": false,
"autoApprove": []
}
}
}
对于 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 命令,包括:
- 系统命令
- 包管理器命令(apt、yum、chocolatey 等)
- 开发工具(git、npm、python 等)
- 文件操作
- 网络命令
- 服务管理
- 以及系统上可用的其他任何 CLI 命令
工具:execute_remote_command
参数:
command(必填):可在主机操作系统上执行的任何有效 shell 命令cwd(可选):执行命令时使用的工作目录
示例
- 系统信息:
<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(根据平台自动转换)- 为各个平台正确设置管道运算符格式
-
Shell 选择:
- Windows:使用
cmd.exe - Unix/Linux:使用
/bin/sh
- Windows:使用
错误处理
该服务会提供详细的错误消息,并在响应中包含 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 目录中创建可执行文件。
贡献
- Fork 仓库
- 创建功能分支(
git checkout -b feature/amazing-feature) - 提交更改(
git commit -m 'Add some amazing feature') - 将分支推送到远程仓库(
git push origin feature/amazing-feature) - 创建 Pull Request
许可证
本项目基于 MIT 许可证授权,详情请参阅 LICENSE 文件。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。