基于 Node.js 的服务器,实现用于文件系统操作的模型上下文协议 (MCP)。
注意: 服务器只允许在通过 args
指定的目录内进行操作。
file://system
: 文件系统操作接口read_file
path
(字符串)read_multiple_files
paths
(字符串数组)write_file
path
(字符串): 文件路径content
(字符串): 文件内容edit_file
path
(字符串): 要编辑的文件edits
(数组): 编辑操作列表
oldText
(字符串): 要搜索的文本(可以是子字符串)newText
(字符串): 用来替换的文本dryRun
(布尔值): 预览更改而不应用 (默认: false)create_directory
path
(字符串)list_directory
path
(字符串)move_file
source
(字符串)destination
(字符串)search_files
path
(字符串):起始目录pattern
(字符串):搜索模式excludePatterns
(字符串数组):排除任何模式。支持glob模式。get_file_info
path
(字符串)list_allowed_directories
将以下内容添加到您的 claude_desktop_config.json
文件中:
注意:您可以通过将沙盒目录挂载到 /projects
来提供给服务器。添加 ro
标志将使服务器无法写入该目录。
注意:默认情况下,所有目录都必须挂载到 /projects
。
{
"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/allowed/dir,dst=/projects/other/allowed/dir,ro",
"--mount", "type=bind,src=/path/to/file.txt,dst=/projects/path/to/file.txt",
"mcp/filesystem",
"/projects"
]
}
}
}

{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/username/Desktop",
"/path/to/other/allowed/dir"
]
}
}
}

快速安装,点击下方安装按钮...
对于手动安装,请将以下 JSON 代码块添加到 VS Code 的用户设置 (JSON) 文件中。您可以按 Ctrl + Shift + P
并输入 Preferences: Open Settings (JSON)
来完成此操作。
或者,您可以将其添加到工作区中的 .vscode/mcp.json
文件中。这将允许您与他人共享配置。
请注意,
.vscode/mcp.json
文件中不需要mcp
键。
您可以通过将沙箱目录挂载到 /projects
来提供给服务器。添加 ro
标志将使服务器无法写入该目录。
注意:默认情况下,所有目录都必须挂载到 /projects
。
{
"mcp": {
"servers": {
"filesystem": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--mount", "type=bind,src=${workspaceFolder},dst=/projects/workspace",
"mcp/filesystem",
"/projects"
]
}
}
}
}

{
"mcp": {
"servers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"${workspaceFolder}"
]
}
}
}
}

Docker 构建:
docker build -t mcp/filesystem -f src/filesystem/Dockerfile .
此 MCP 服务器使用 MIT 许可证授权。这意味着您可以自由地使用、修改和分发该软件,但须遵守 MIT 许可证的条款和条件。更多详情,请参阅项目仓库中的 LICENSE 文件。