Filesystem
Node.js实现的用于文件系统操作的MCP服务
功能概述
这是一个文件系统操作的 MCP 服务,允许 Claude 安全地读取、写入和管理文件。
设置
将 Filesystem MCP 服务添加到 claude_desktop_config.json
配置中:
Docker 方式
{
"mcpServers": {
"filesystem": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--mount", "type=bind,src=/Users/username/Desktop,dst=/projects/Desktop",
"--mount", "type=bind,src=/path/to/other/dir,dst=/projects/other/dir,ro",
"mcp/filesystem",
"/projects"
]
}
}
}
注意:目录默认必须挂载到
/projects
。使用ro
标志使目录只读。
NPX 方式
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/username/Desktop",
"/path/to/other/allowed/dir"
]
}
}
}
可用工具
工具 | 描述 | 主要参数 |
---|---|---|
read_file | 读取文件内容 | path : 文件路径 |
read_multiple_files | 批量读取多个文件 | paths : 文件路径数组 |
write_file | 创建或覆盖文件 | path : 文件路径, content : 内容 |
edit_file | 选择性编辑文件内容 | path : 文件路径, edits : 编辑操作, dryRun : 预览模式 |
create_directory | 创建新目录 | path : 目录路径 |
list_directory | 列出目录内容 | path : 目录路径 |
move_file | 移动或重命名文件/目录 | source : 源路径, destination : 目标路径 |
search_files | 递归搜索文件/目录 | path : 起始目录, pattern : 搜索模式, excludePatterns : 排除模式 |
get_file_info | 获取文件/目录元数据 | path : 文件/目录路径 |
list_allowed_directories | 列出允许访问的目录 | 无参数 |
高级功能:edit_file
edit_file
工具提供高级编辑功能:
- 基于行和多行内容匹配
- 保留缩进和格式
- 多处同时编辑
- 差异预览
最佳实践:始终先使用 dryRun: true
来预览更改。
// 示例
edit_file({
path: "/projects/myfile.js",
edits: [
{ oldText: "function oldName", newText: "function newName" }
],
dryRun: true // 预览更改
})
构建
docker build -t mcp/filesystem -f src/filesystem/Dockerfile .
许可证
MIT 许可证