此 MCP 服务器通过模型上下文协议(MCP)提供对本地文件系统的安全访问。
read_file
path(必需):要读取的文件路径read_multiple_files
paths(必需):要读取的文件路径列表write_file
path(必需):写入文件的位置,content(必需):写入文件的内容copy_file
source(必需):文件或目录的源路径,destination(必需):目标路径move_file
source(必需):文件或目录的源路径,destination(必需):目标路径delete_file
path(必需):要删除的文件或目录路径,recursive(可选):是否递归删除目录(默认:false)modify_file
path(必需):要修改的文件路径,find(必需):要搜索的文本,replace(必需):替换的文本,all_occurrences(可选):替换所有出现的情况(默认:true),regex(可选):将查找模式视为正则表达式(默认:false)list_directory
path(必需):要列出的目录路径create_directory
path(必需):要创建的目录路径tree
path(必需):要遍历的目录路径,depth(可选):最大遍历深度(默认:3),follow_symlinks(可选):是否跟随符号链接(默认:false)search_files
path(必需):搜索的起始路径,pattern(必需):与文件名匹配的搜索模式search_within_files
path(必需):搜索的起始目录,substring(必需):在文件内容中搜索的文本,depth(可选):最大目录深度,max_results(可选):返回的最大结果数(默认:1_000)get_file_info
path(必需):文件或目录的路径list_allowed_directories
go install github.com/mark3labs/mcp-filesystem-server@latest
使用允许的目录启动 MCP 服务器:
mcp-filesystem-server /path/to/allowed/directory [/another/allowed/directory ...]
package main
import (
"log"
"os"
"github.com/mark3labs/mcp-filesystem-server/filesystemserver"
)
func main() {
// 使用允许的目录创建新的文件系统服务器
allowedDirs := []string{"/path/to/allowed/directory", "/another/allowed/directory"}
fs, err := filesystemserver.NewFilesystemServer(allowedDirs)
if err != nil {
log.Fatalf("创建服务器失败:%v", err)
}
// 提供请求服务
if err := fs.Serve(); err != nil {
log.Fatalf("服务器错误:%v", err)
}
}
要将此服务器集成到支持 MCP 的应用程序中:
{
"mcpServers": {
"filesystem": {
"command": "mcp-filesystem-server",
"args": ["/path/to/allowed/directory", "/another/allowed/directory"]
}
}
}
您可以使用 Docker 运行文件系统 MCP 服务器:
docker run -i --rm ghcr.io/mark3labs/mcp-filesystem-server:latest /path/to/allowed/directory
要将 Docker 镜像集成到支持 MCP 的应用程序中:
{
"mcpServers": {
"filesystem": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/mark3labs/mcp-filesystem-server:latest",
"/path/to/allowed/directory"
]
}
}
}
如果您需要容器内的更改反映在主机文件系统上,可以挂载一个卷。这允许容器访问和修改主机系统上的文件。以下是一个示例:
{
"mcpServers": {
"filesystem": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--volume=/allowed/directory/in/host:/allowed/directory/in/container",
"ghcr.io/mark3labs/mcp-filesystem-server:latest",
"/allowed/directory/in/container"
]
}
}
}
详情见 LICENSE 文件。