mcp-linux-ops
# Linux 操作 MCP 服务器
这是一个 Model Context Protocol (MCP) 服务器,允许大模型在 Linux 机器上执行各种操作,包括执行命令、文件操作等。
## 功能特性
### 命令执行
- **execute_command**: 在 Linux 系统上执行 shell 命令
- 支持指定工作目录
- 可配置超时时间
- 返回标准输出、标准错误和退出码
### 文件操作
- **read_file**: 读取文件内容
- **write_file**: 写入文件内容(支持追加模式)
- **list_directory**: 列出目录内容
- **create_directory**: 创建目录(支持递归创建)
- **delete_file**: 删除文件或目录
- **file_exists**: 检查文件或目录是否存在
- **get_file_info**: 获取文件或目录的详细信息
- **copy_file**: 复制文件或目录
- **move_file**: 移动或重命名文件或目录
## 安装
1. 克隆或下载此项目
2. 安装依赖:
```bash
npm install
```
3. 构建项目:
```bash
npm run build
```
## 使用方法
### 在 Cursor 中配置
在 Cursor 的设置中添加 MCP 服务器配置。编辑你的 MCP 配置文件(通常在 `~/.cursor/mcp.json` 或类似位置):
```json
{
"mcpServers": {
"linux-ops": {
"command": "node",
"args": ["/path/to/mcp/dist/index.js"]
}
}
}
```
或者如果你使用 npm 全局安装:
```json
{
"mcpServers": {
"linux-ops": {
"command": "mcp-linux-ops"
}
}
}
```
### 开发模式
在开发时,你可以使用 `tsx` 直接运行:
```bash
npm run dev
```
## 工具说明
### execute_command
执行 shell 命令并返回结果。
**参数:**
- `command` (必需): 要执行的 shell 命令
- `workingDirectory` (可选): 执行命令的工作目录
- `timeout` (可选): 命令超时时间(秒,默认 30)
**示例:**
```json
{
"command": "ls -la",
"workingDirectory": "/home/user",
"timeout": 10
}
```
### read_file
读取文件内容。
**参数:**
- `filePath` (必需): 要读取的文件路径
- `encoding` (可选): 文件编码(默认 "utf-8")
### write_file
写入文件内容。
**参数:**
- `filePath` (必需): 要写入的文件路径
- `content` (必需): 要写入的内容
- `encoding` (可选): 文件编码(默认 "utf-8")
- `append` (可选): 是否追加模式(默认 false)
### list_directory
列出目录内容。
**参数:**
- `directoryPath` (必需): 要列出的目录路径
- `includeHidden` (可选): 是否包含隐藏文件(默认 false)
### create_directory
创建目录。
**参数:**
- `directoryPath` (必需): 要创建的目录路径
- `recursive` (可选): 是否递归创建父目录(默认 true)
### delete_file
删除文件或目录。
**参数:**
- `path` (必需): 要删除的文件或目录路径
- `recursive` (可选): 删除目录时是否递归(默认 false)
### file_exists
检查文件或目录是否存在。
**参数:**
- `path` (必需): 要检查的文件或目录路径
### get_file_info
获取文件或目录的详细信息。
**参数:**
- `filePath` (必需): 文件或目录路径
### copy_file
复制文件或目录。
**参数:**
- `source` (必需): 源文件或目录路径
- `destination` (必需): 目标路径
- `recursive` (可选): 复制目录时是否递归(默认 true)
### move_file
移动或重命名文件或目录。
**参数:**
- `source` (必需): 源文件或目录路径
- `destination` (必需): 目标路径
## 安全注意事项
⚠️ **警告**: 此服务器允许执行任意 shell 命令,具有与运行用户相同的权限。请确保:
1. 只在受信任的环境中使用
2. 不要在生产环境中以 root 权限运行
3. 考虑添加命令白名单或权限控制
4. 限制可访问的文件系统路径
## 许可证
MIT
TDQS
Scored across 10 tools
Each tool maps to a distinct action (execute, read, write, list, create, delete, check, info, copy, move), with no overlap. Even though file and directory operations are combined in some tools, descriptions clarify that they handle both, eliminating ambiguity.
Most tools follow a consistent verb_noun pattern (e.g., read_file, create_directory, copy_file). The only exception is file_exists, which uses noun_verb, creating a minor inconsistency that prevents a perfect score.
10 tools is well within the ideal range for a Linux file operations server. Each tool covers a distinct operation with no redundancy, and the count feels appropriately scoped for the purpose.
The server covers the full lifecycle for files and directories: create, read, write, delete, list, copy, move, check existence, and get info, plus arbitrary command execution. This is a complete surface for the stated domain, with no obvious dead ends or missing critical operations.