Filesystem MCP Server

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Included in development dependencies for code linting within the file system operations.

  • Included in development dependencies for running tests on the file system operations and analysis capabilities.

  • Used for visualizing the architecture of the MCP server in documentation.

文件系统 MCP 服务器

模型上下文协议 (MCP) 服务器实现通过标准化工具接口提供文件系统操作、分析和操控功能。

建筑学

该服务器基于 MCP SDK 构建,并分为不同的层:

成分

  • 服务器层:处理MCP协议通信和工具调度
  • 工具注册表:管理工具注册和执行
  • 操作层:实现核心功能
  • 文件系统接口:提供安全的文件系统访问

安装

  1. 克隆存储库:
git clone <repository-url> cd filesystem-server
  1. 安装依赖项:
npm install
  1. 构建服务器:
npm run build
  1. 配置 MCP 设置(cline_mcp_settings.json):
{ "mcpServers": { "filesystem": { "command": "node", "args": ["path/to/filesystem-server/build/index.js"] } } }

工具参考

目录操作

列表目录

列出带有元数据的目录内容。

interface ListDirectoryParams { path: string; // Directory path recursive?: boolean; // List recursively (default: false) } interface ListDirectoryResult { entries: { name: string; path: string; isDirectory: boolean; size: number; created: string; modified: string; accessed: string; mode: string; }[]; }

创建目录

创建新目录。

interface CreateDirectoryParams { path: string; // Directory path recursive?: boolean; // Create parent directories (default: true) }

文件操作

读取文件

读取具有编码支持的文件内容。

interface ReadFileParams { path: string; // File path encoding?: string; // File encoding (default: 'utf8') }

写入文件

将内容写入文件。

interface WriteFileParams { path: string; // File path content: string; // Content to write encoding?: string; // File encoding (default: 'utf8') }

追加文件

将内容附加到文件。

interface AppendFileParams { path: string; // File path content: string; // Content to append encoding?: string; // File encoding (default: 'utf8') }

分析操作

分析文本

分析文本文件属性。

interface AnalyzeTextParams { path: string; // File path } interface AnalyzeTextResult { lineCount: number; wordCount: number; charCount: number; encoding: string; mimeType: string; }

计算哈希

使用指定的算法计算文件哈希值。

interface CalculateHashParams { path: string; // File path algorithm?: 'md5' | 'sha1' | 'sha256' | 'sha512'; // Hash algorithm } interface CalculateHashResult { hash: string; algorithm: string; }

查找重复项

识别目录中的重复文件。

interface FindDuplicatesParams { path: string; // Directory path } interface FindDuplicatesResult { duplicates: { hash: string; size: number; files: string[]; }[]; }

压缩操作

创建_zip

创建一个 ZIP 档案。

interface CreateZipParams { files: string[]; // Files to include output: string; // Output ZIP path }

提取压缩文件

提取 ZIP 档案。

interface ExtractZipParams { path: string; // ZIP file path output: string; // Output directory }

错误处理

服务器使用标准 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/ # Core operations implementation ├── tools/ # MCP tool definitions and handlers ├── __tests__/ # Test suites ├── index.ts # Entry point ├── server.ts # MCP server setup ├── types.ts # Type definitions └── utils.ts # Utility functions

运行测试

运行测试套件:

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:文件哈希
  • 归档器:ZIP 创建
  • extract-zip:ZIP 提取
  • iconv-lite:文本编码
  • chardet:编码检测

开发依赖项:

  • typescript:类型系统
  • 开玩笑:测试
  • eslint:Lint
  • 更漂亮:格式化
  • ts-node:TypeScript 执行
  • nodemon:开发服务器

贡献

  1. 分叉存储库
  2. 创建你的功能分支
  3. 为新功能编写测试
  4. 确保所有测试通过
  5. 提交拉取请求

执照

麻省理工学院

-
security - not tested
A
license - permissive license
-
quality - not tested

通过标准化工具接口提供文件系统操作、分析和操控功能的模型上下文协议服务器。

  1. Architecture
    1. Components
  2. Installation
    1. Tool Reference
      1. Directory Operations
      2. File Operations
      3. Analysis Operations
      4. Compression Operations
    2. Error Handling
      1. Development
        1. Project Structure
        2. Running Tests
        3. Development Mode
        4. Code Quality
      2. Dependencies
        1. Contributing
          1. License
            ID: hfidyfcfcx