Skip to main content
Glama
MCP File Context Server

MCP File Context Server

by bsmi021

文件上下文服务器

铁匠徽章

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

特征

  • 文件操作

    • 读取文件和目录内容

    • 列出具有详细元数据的文件

    • 实时文件监控和缓存失效

    • 支持多种文件编码

    • 递归目录遍历

    • 文件类型过滤

  • 代码分析

    • 圈复杂度计算

    • 依赖关系提取

    • 评论分析

    • 质量指标:

      • 重复行检测

      • 长行检测(>100 个字符)

      • 复杂函数识别

      • 行数(总数、非空行、注释)

  • 智能缓存

    • LRU(最近最少使用)缓存策略

    • 文件更改时缓存自动失效

    • 具有可配置限制的大小感知缓存

    • 缓存统计和性能指标

    • 上次读取的结果缓存,以实现高效搜索

  • 高级搜索

    • 正则表达式模式匹配

    • 具有可配置周围线条的上下文感知结果

    • 文件类型过滤

    • 多模式搜索支持

    • 缓存结果搜索

    • 排除模式

Related MCP server: TokenScope

安装

通过 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进行文件系统访问。

  • 此更改可防止不同操作系统上出现路径分隔符和文件匹配问题。

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

Available Tools

6 tools
generate_outlineC

Generate a code outline for a file, showing its structure (classes, functions, imports, etc). Supports TypeScript/JavaScript and Python files.

Inputs: path (required).

get_chunk_countA

Get the total number of chunks that will be returned for a read_context request. Use this tool FIRST before reading content to determine how many chunks you need to request. The parameters should match what you'll use in read_context.

Inputs: path (required), encoding, maxSize, recursive, +1 more.

getFilesC

Retrieve multiple files by their paths, returning content and metadata for each file

Inputs: filePathList (required).

get_profile_contextC

Get repository context based on current profile settings

Inputs: refresh.

read_contextA

Read and analyze code files with advanced filtering and chunking. The server automatically ignores common artifact directories and files:

  • Version Control: .git/

  • Python: .venv/, pycache/, *.pyc, etc.

  • JavaScript/Node.js: node_modules/, bower_components/, .next/, dist/, etc.

  • IDE/Editor: .idea/, .vscode/, .env, etc.

For large files or directories, use get_chunk_count first to determine total chunks, then request specific chunks using chunkNumber parameter.

Inputs: path (required), maxSize, encoding, recursive, +2 more.

set_profileC

Set the active profile for context generation

Inputs: profile_name (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.3/5.0

    Scored across 6 tools

    Disambiguation4/5

    Most tools have distinct purposes, but 'getFiles' and 'read_context' both involve retrieving file content, which could cause confusion. 'generate_outline' and 'get_profile_context' are clearly separate, and 'set_profile' and 'get_chunk_count' are specialized utilities.

    Naming Consistency2/5

    Naming is inconsistent with mixed conventions: 'generate_outline' and 'read_context' use snake_case, while 'getFiles' uses camelCase. Verb styles vary (e.g., 'generate' vs. 'get' vs. 'read'), and 'get_chunk_count' includes an underscore while 'getFiles' does not, creating a chaotic pattern.

    Tool Count5/5

    With 6 tools, the count is well-scoped for a file context server, covering core operations like file retrieval, analysis, and profile management without being overwhelming or too sparse.

    Completeness4/5

    The toolset covers key file context operations: retrieving files, analyzing code, generating outlines, and managing profiles. A minor gap exists in update or delete operations for profiles or contexts, but agents can likely work around this for the server's purpose.

    Maintenance

    ActivityInactive
    ResponsivenessLimited data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      A Model Context Protocol server that enables token-aware directory exploration and file analysis for LLMs, helping them understand codebases through intelligent scanning and reporting.
      4
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      A Model Context Protocol server that enhances AI agents by providing deep semantic understanding of codebases, enabling more intelligent interactions through advanced code search and contextual awareness.
      90
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      A Model Context Protocol (MCP) server that enables AI applications to access and analyze local code repositories without manual uploads, providing file listing, content reading, code searching, and project structure analysis capabilities.
      7
      MIT