文件系统 MCP 服务器是一个安全的模型上下文协议(MCP)服务器,它能够提供受控访问指定目录的文件系统操作,保障文件操作的安全性与可控性。
本服务器可通过环境变量控制目录访问,且所有文件操作都受限于允许的目录内。以下是快速使用的步骤:
使用以下命令安装项目:
go get github.com/gomcpgo/filesys
使用环境变量设置允许目录:
export MCP_ALLOWED_DIRS="/path1,/path2,/path with spaces/dir3"
read_file
:读取单个文件内容read_multiple_files
:同时读取多个文件write_file
:创建或覆盖文件create_directory
:创建新目录list_directory
:列出目录内容list_allowed_directories
:显示可访问的目录move_file
:移动或重命名文件和目录get_file_info
:获取文件元数据search_files
:递归搜索带有模式匹配的文件将以下内容添加到 claude_desktop_config.json
:
{
"mcpServers": {
"filesystem": {
"command": "/path/to/filesys",
"env": {
"MCP_ALLOWED_DIRS": "/path1,/path2,/path with spaces/dir3"
}
}
}
}
{
"name": "read_file",
"arguments": {
"path": "/allowed/path/file.txt"
}
}
{
"name": "list_directory",
"arguments": {
"path": "/allowed/path"
}
}
go build -o bin/filesys cmd/main.go
本项目采用 MIT License 许可协议。
欢迎提交拉取请求。请确保: