Filesystem MCP Server
一个模型上下文协议服务器,通过标准化的工具接口提供文件系统操作、分析和处理能力。
README
文件系统 MCP 服务器
一个模型上下文协议 (MCP) 服务器实现,通过标准化的工具接口提供文件系统操作、分析和处理能力。
架构
该服务器构建于 MCP SDK 之上,并组织成不同的层:
graph TD
A[MCP 服务器层] --> B[工具注册表]
B --> C[操作层]
C --> D[文件系统操作]
C --> E[分析操作]
C --> F[流操作]
组件
- 服务器层: 处理 MCP 协议通信和工具分发
- 工具注册表: 管理工具注册和执行
- 操作层: 实现核心功能
- 文件系统接口: 提供安全的文件系统访问
安装
- 克隆仓库:
git clone <repository-url>
cd filesystem-server
- 安装依赖:
npm install
- 构建服务器:
npm run build
- 配置 MCP 设置 (cline_mcp_settings.json):
{
"mcpServers": {
"filesystem": {
"command": "node",
"args": ["path/to/filesystem-server/build/index.js"]
}
}
}
工具参考
目录操作
list_directory
列出目录内容及其元数据。
interface ListDirectoryParams {
path: string; // 目录路径
recursive?: boolean; // 递归列出 (默认: false)
}
interface ListDirectoryResult {
entries: {
name: string;
path: string;
isDirectory: boolean;
size: number;
created: string;
modified: string;
accessed: string;
mode: string;
}[];
}
create_directory
创建一个新目录。
interface CreateDirectoryParams {
path: string; // 目录路径
recursive?: boolean; // 创建父目录 (默认: true)
}
文件操作
read_file
读取文件内容,支持编码。
interface ReadFileParams {
path: string; // 文件路径
encoding?: string; // 文件编码 (默认: 'utf8')
}
write_file
将内容写入文件。
interface WriteFileParams {
path: string; // 文件路径
content: string; // 要写入的内容
encoding?: string; // 文件编码 (默认: 'utf8')
}
append_file
将内容追加到文件。
interface AppendFileParams {
path: string; // 文件路径
content: string; // 要追加的内容
encoding?: string; // 文件编码 (默认: 'utf8')
}
分析操作
analyze_text
分析文本文件属性。
interface AnalyzeTextParams {
path: string; // 文件路径
}
interface AnalyzeTextResult {
lineCount: number;
wordCount: number;
charCount: number;
encoding: string;
mimeType: string;
}
calculate_hash
使用指定的算法计算文件哈希值。
interface CalculateHashParams {
path: string; // 文件路径
algorithm?: 'md5' | 'sha1' | 'sha256' | 'sha512'; // 哈希算法
}
interface CalculateHashResult {
hash: string;
algorithm: string;
}
find_duplicates
识别目录中的重复文件。
interface FindDuplicatesParams {
path: string; // 目录路径
}
interface FindDuplicatesResult {
duplicates: {
hash: string;
size: number;
files: string[];
}[];
}
压缩操作
create_zip
创建一个 ZIP 压缩包。
interface CreateZipParams {
files: string[]; // 要包含的文件
output: string; // 输出 ZIP 路径
}
extract_zip
解压一个 ZIP 压缩包。
interface ExtractZipParams {
path: string; // ZIP 文件路径
output: string; // 输出目录
}
错误处理
服务器使用标准的 MCP 错误代码:
enum ErrorCode {
ParseError = -32700,
InvalidRequest = -32600,
MethodNotFound = -32601,
InvalidParams = -32602,
InternalError = -32603
}
错误响应包括:
- 错误代码
- 人类可读的消息
- 可用时的附加上下文
错误示例:
{
"code": -32602,
"message": "File not found: /path/to/file.txt"
}
开发
项目结构
src/
├── operations/ # 核心操作实现
├── tools/ # MCP 工具定义和处理程序
├── __tests__/ # 测试套件
├── index.ts # 入口点
├── server.ts # MCP 服务器设置
├── types.ts # 类型定义
└── utils.ts # 实用函数
运行测试
运行测试套件:
npm test
运行并生成覆盖率报告:
npm run test:coverage
开发模式
在监听模式下运行:
npm run watch
代码质量
检查代码风格:
npm run lint
类型检查:
npm run type-check
依赖
核心依赖:
- @modelcontextprotocol/sdk: MCP 服务器实现
- file-type: 文件类型检测
- mime-types: MIME 类型查找
- crypto-js: 文件哈希
- archiver: ZIP 创建
- extract-zip: ZIP 解压
- iconv-lite: 文本编码
- chardet: 编码检测
开发依赖:
- typescript: 类型系统
- jest: 测试
- eslint: 代码风格检查
- prettier: 代码格式化
- ts-node: TypeScript 执行
- nodemon: 开发服务器
贡献
- Fork 仓库
- 创建您的特性分支
- 为新特性编写测试
- 确保所有测试通过
- 提交 Pull Request
许可证
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。