使用说明
文件服务器MCP
一种模型上下文协议(MCP)服务器,通过可配置的访问从特定文件夹中公开文档。
特性
- 可配置文件夹:显示特定文件夹,如文档、报告、桌面等。
- 文件类型筛选:出于安全考虑,只允许特定的文件扩展名
- 大小限制:可配置的最大文件大小限制
- 可用工具:
list_files:列出配置文件夹中具有可选模式匹配的文件read_file:读取特定文件的内容search_files:搜索包含特定文本的文件
- 资源:通过MCP资源URI访问文件,如
file://documents/filename.txt
配置
服务器可以通过环境变量或 config.json 文件:
默认文件夹
documents:C:\用户\账单\文档reports:C:\支持desktop:C:\用户\账单\桌面backup_scripts:C:\支持
环境变量
FILE_SERVER_CONFIG:具有自定义配置的JSON字符串DOCUMENTS_FOLDER:覆盖文档文件夹路径REPORTS_FOLDER:覆盖报告文件夹路径DESKTOP_FOLDER:覆盖桌面文件夹路径
配置文件
编辑 config.json 自定义:
{
"folders": {
"documents": "C:\\Users\\bill\\Documents",
"reports": "C:\\Support",
"desktop": "C:\\Users\\bill\\Desktop",
"backup_scripts": "C:\\support"
},
"allowedExtensions": [".txt", ".md", ".pdf", ".docx", ".xlsx", ".csv", ".json", ".xml", ".log", ".ps1"],
"maxFileSize": 10485760
}
安装
先决条件
- 安装Node.js(https://nodejs.org/)
- 安装 npm 依赖项 :
npm install
构建
npm run build
MCP配置
添加到MCP设置文件(C:\Users\bill\AppData\Roaming\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json):
{
"mcpServers": {
"file-server": {
"command": "node",
"args": ["C:/Users/bill/Desktop/file-server/build/index.js"],
"env": {
"FILE_SERVER_CONFIG": "{\"folders\":{\"documents\":\"C:\\\\Users\\\\bill\\\\Documents\",\"reports\":\"C:\\\\Support\",\"desktop\":\"C:\\\\Users\\\\bill\\\\Desktop\",\"backup_scripts\":\"C:\\\\support\"}}"
}
}
}
}
使用示例
安装后,您可以通过MCP工具使用文件服务器:
列出文件
Use the list_files tool with folder="documents" to see all files in the Documents folder
读取文件
Use the read_file tool with folder="reports" and filename="backup-report.csv" to read a specific file
搜索文件
Use the search_files tool with folder="backup_scripts" and searchText="SQLite" to find scripts containing "SQLite"
访问资源
Access file://documents/ to get a list of files in Documents
Access file://reports/backup-report.csv to read a specific file
安全功能
- 仅可访问已配置的文件夹
- 通过允许的扩展名限制文件类型
- 文件大小限制,防止大文件访问
- 路径遍历保护
- 只读访问(无文件修改)
文件夹结构
file-server/
├── package.json # Node.js package configuration
├── tsconfig.json # TypeScript configuration
├── config.json # Server configuration
├── README.md # This file
├── src/
│ └── index.ts # Main server implementation
└── build/ # Compiled JavaScript (after npm run build)
└── index.js # Executable MCP server
发展
# Watch mode for development
npm run dev
# Build for production
npm run build
# Test the server
npm start
