Skip to main content
Glama

MCP File Context Server

by bsmi021

文件上下文服务器

模型上下文协议 (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 的流程。

跨平台路径兼容性

**注意:**截至 2025 年 4 月,文件上下文服务器中的所有文件和目录路径处理均已更新,以提高跨平台兼容性(Windows、macOS、Linux):

  • 所有 glob 模式在内部都使用 POSIX 样式的路径(正斜杠),确保无论操作系统如何都能实现一致的文件匹配。
  • 所有文件系统操作(读取、写入、统计等)都使用规范化的绝对路径以确保可靠性。
  • 如果您正在开发或扩展服务器,请使用path.posix.join进行 glob 模式,并使用path.normalize进行文件系统访问。
  • 此更改可防止不同操作系统上出现路径分隔符和文件匹配问题。

最终用户不需要进行任何更改,但开发人员在为项目做贡献时应遵循这些约定。

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

local-only server

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

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

  1. 特征
    1. 安装
      1. 通过 Smithery 安装
      2. 手动安装
    2. 用法
      1. 启动服务器
      2. 可用工具
    3. 错误处理
      1. 配置
        1. 发展
          1. 执照
            1. 贡献
              1. 跨平台路径兼容性

                Related MCP Servers

                • A
                  security
                  A
                  license
                  A
                  quality
                  A Model Context Protocol server that provides tools for code modification and generation via Large Language Models, allowing users to create, modify, rewrite, and delete files using structured XML instructions.
                  Last updated -
                  12
                  Python
                  MIT License
                  • Linux
                  • Apple
                • -
                  security
                  F
                  license
                  -
                  quality
                  A Model Context Protocol server that enables LLMs to extract and use content from unstructured documents across a wide variety of file formats.
                  Last updated -
                  2
                  Python
                  • Apple
                • -
                  security
                  F
                  license
                  -
                  quality
                  A Model Context Protocol server that connects LLMs to the Compiler Explorer API, enabling them to compile code, explore compiler features, and analyze optimizations across different compilers and languages.
                  Last updated -
                  Python
                • A
                  security
                  A
                  license
                  A
                  quality
                  A Model Context Protocol server that helps large language models process code repositories by providing file tree generation, code merging, and code analysis capabilities.
                  Last updated -
                  3
                  14
                  JavaScript
                  MIT License

                View all related MCP servers

                MCP directory API

                We provide all the information about MCP servers via our MCP API.

                curl -X GET 'https://glama.ai/api/mcp/v1/servers/bsmi021/mcp-file-context-server'

                If you have feedback or need assistance with the MCP directory API, please join our Discord server