MCP File Context Server

local-only server

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

Integrations

  • Enables installation of the MCP server via npm, providing access to NPM package management for installing and running the file context server.

文件上下文服务器

模型上下文协议 (MCP) 服务器,为大型语言模型 (LLM) 提供文件系统上下文。该服务器支持 LLM 读取、搜索和分析代码文件,并具备高级缓存和实时文件监控功能。

特征

  • 文件操作
    • 读取文件和目录内容
    • 列出具有详细元数据的文件
    • 实时文件监控和缓存失效
    • 支持多种文件编码
    • 递归目录遍历
    • 文件类型过滤
  • 代码分析
    • 圈复杂度计算
    • 依赖关系提取
    • 评论分析
    • 质量指标:
      • 重复行检测
      • 长行检测(>100 个字符)
      • 复杂函数识别
      • 行数(总数、非空行、注释)
  • 智能缓存
    • LRU(最近最少使用)缓存策略
    • 文件更改时自动缓存失效
    • 具有可配置限制的大小感知缓存
    • 缓存统计和性能指标
    • 上次读取的结果缓存,以实现高效搜索
  • 高级搜索
    • 正则表达式模式匹配
    • 具有可配置周围线条的上下文感知结果
    • 文件类型过滤
    • 多模式搜索支持
    • 缓存结果搜索
    • 排除模式

安装

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 File Context Server:

npx -y @smithery/cli install @bsmi021/mcp-file-context-server --client claude

手动安装

npm install @modelcontextprotocol/file-context-server

用法

启动服务器

npx file-context-server

可用工具

  1. 列出上下文文件
    • 列出目录中包含详细元数据的文件
    { "path": "./src", "recursive": true, "includeHidden": false }
  2. 读取上下文
    • 读取带有元数据的文件或目录内容
    { "path": "./src/index.ts", "encoding": "utf8", "maxSize": 1000000, "recursive": true, "fileTypes": ["ts", "js"] }
  3. 搜索上下文
    • 在具有上下文的文件中搜索模式
    { "pattern": "function.*", "path": "./src", "options": { "recursive": true, "contextLines": 2, "fileTypes": ["ts"] } }
  4. 分析代码
    • 分析代码文件的质量指标
    { "path": "./src", "recursive": true, "metrics": ["complexity", "dependencies", "quality"] }
  5. 缓存统计信息
    • 获取缓存统计信息和性能指标
    { "detailed": true }

错误处理

服务器提供详细的错误消息以及具体的错误代码:

  • FILE_NOT_FOUND :文件或目录不存在
  • PERMISSION_DENIED :访问权限问题
  • INVALID_PATH :文件路径格式无效
  • FILE_TOO_LARGE :文件超出大小限制
  • ENCODING_ERROR :文件编码问题
  • UNKNOWN_ERROR :意外错误

配置

自定义的环境变量:

  • MAX_CACHE_SIZE :缓存条目的最大数量(默认值:1000)
  • CACHE_TTL :缓存生存时间(以毫秒为单位)(默认值:1 小时)
  • MAX_FILE_SIZE :读取的最大文件大小(以字节为单位)

发展

# Install dependencies npm install # Build npm run build # Run tests npm test # Start in development mode npm run dev

执照

麻省理工学院

贡献

欢迎贡献代码!请阅读我们的贡献指南,详细了解我们的行为准则以及提交 Pull Request 的流程。

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

模型上下文协议服务器使 LLM 能够通过高级缓存和实时文件监视功能读取、搜索和分析代码文件。

  1. Features
    1. Installation
      1. Installing via Smithery
      2. Manual Installation
    2. Usage
      1. Starting the Server
      2. Available Tools
    3. Error Handling
      1. Configuration
        1. Development
          1. License
            1. Contributing
              ID: x133mt0q3l