一个基于 TypeScript 的 Model Context Protocol (MCP) 文件管理服务器,提供文件系统操作能力。
| 工具名 | 描述 |
|---|
read_file | 读取文件内容(支持文本和二进制) |
write_file | 写入/创建文件,自动创建父目录 |
list_directory | 列出目录内容(包含大小、时间等信息) |
create_directory | 创建目录(支持递归创建) |
delete_file | 删除文件 |
delete_directory | 删除目录(支持递归删除) |
move_file | 移动/重命名文件或目录 |
copy_file | 复制文件或目录 |
get_file_info | 获取文件元信息(大小、时间、权限等) |
| 工具名 | 描述 |
|---|
batch_delete | 批量删除文件/目录(支持 dryRun 试运行) |
batch_copy | 批量复制文件/目录到指定目录 |
batch_move | 批量移动文件/目录到指定目录 |
batch_read | 批量读取多个文件内容 |
batch_rename | 批量重命名(支持正则表达式) |
batch_get_info | 批量获取文件/目录元信息 |
| 模式 | 匹配 |
|---|
*.txt | 当前目录下所有 txt 文件 |
src/**/*.js | src 目录下所有 js 文件(递归) |
**/*.md | 所有目录下的 md 文件 |
test?.log | test1.log, testA.log 等 |
| 资源名 | 描述 |
|---|
current-directory | 当前工作目录信息 |
directory-structure | 工作目录顶层结构 |
- 路径遍历保护:所有路径操作限制在工作目录内
- 文件大小限制:读取文件上限 10MB,防止内存溢出
- 文本/二进制识别:自动识别文件类型并适当处理
npm install
npm run build
npm start
在 Claude Desktop 或其他 MCP 客户端的配置文件中添加:
{
"mcpServers": {
"filemanagermcp": {
"command": "node",
"args": ["/绝对路径/filemanagermcp/build/index.js"]
}
}
}
filemanagermcp/
├── package.json
├── tsconfig.json
├── .gitignore
├── src/
│ └── index.ts # 核心源码
├── build/ # 编译输出
└── node_modules/
- TypeScript 5.8 (ES2022, ES Module)
- @modelcontextprotocol/sdk
- Zod(参数验证)