Cover image
Try Now
2025-01-30

Mirror ofhttps://github.com/bsmi021/mcp-file-context-server

3 years

Works with Finder

0

Github Watches

1

Github Forks

0

Github Stars

File Context Server

A Model Context Protocol (MCP) server that provides file system context to Large Language Models (LLMs). This server enables LLMs to read, search, and analyze code files with advanced caching and real-time file watching capabilities.

Features

  • File Operations

    • Read file and directory contents
    • List files with detailed metadata
    • Real-time file watching and cache invalidation
    • Support for multiple file encodings
    • Recursive directory traversal
    • File type filtering
  • Code Analysis

    • Cyclomatic complexity calculation
    • Dependency extraction
    • Comment analysis
    • Quality metrics:
      • Duplicate lines detection
      • Long lines detection (>100 characters)
      • Complex function identification
      • Line counts (total, non-empty, comments)
  • Smart Caching

    • LRU (Least Recently Used) caching strategy
    • Automatic cache invalidation on file changes
    • Size-aware caching with configurable limits
    • Cache statistics and performance metrics
    • Last read result caching for efficient searches
  • Advanced Search

    • Regex pattern matching
    • Context-aware results with configurable surrounding lines
    • File type filtering
    • Multi-pattern search support
    • Cached result searching
    • Exclusion patterns

Installation

npm install @modelcontextprotocol/file-context-server

Usage

Starting the Server

npx file-context-server

Available Tools

  1. list_context_files

    • Lists files in a directory with detailed metadata
    {
      "path": "./src",
      "recursive": true,
      "includeHidden": false
    }
    
  2. read_context

    • Reads file or directory contents with metadata
    {
      "path": "./src/index.ts",
      "encoding": "utf8",
      "maxSize": 1000000,
      "recursive": true,
      "fileTypes": ["ts", "js"]
    }
    
  3. search_context

    • Searches for patterns in files with context
    {
      "pattern": "function.*",
      "path": "./src",
      "options": {
        "recursive": true,
        "contextLines": 2,
        "fileTypes": ["ts"]
      }
    }
    
  4. analyze_code

    • Analyzes code files for quality metrics
    {
      "path": "./src",
      "recursive": true,
      "metrics": ["complexity", "dependencies", "quality"]
    }
    
  5. cache_stats

    • Gets cache statistics and performance metrics
    {
      "detailed": true
    }
    

Error Handling

The server provides detailed error messages with specific error codes:

  • FILE_NOT_FOUND: File or directory does not exist
  • PERMISSION_DENIED: Access permission issues
  • INVALID_PATH: Invalid file path format
  • FILE_TOO_LARGE: File exceeds size limit
  • ENCODING_ERROR: File encoding issues
  • UNKNOWN_ERROR: Unexpected errors

Configuration

Environment variables for customization:

  • MAX_CACHE_SIZE: Maximum number of cached entries (default: 1000)
  • CACHE_TTL: Cache time-to-live in milliseconds (default: 1 hour)
  • MAX_FILE_SIZE: Maximum file size in bytes for reading

Development

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Start in development mode
npm run dev

License

MIT

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • momi
  • Provides initial medical assessments and advice.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Yasir Eryilmaz
  • AI scriptwriting assistant for short, engaging video content.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Daren White
  • A supportive coach for mastering all Spanish tenses.

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • huahuayu
  • A unified API gateway for integrating multiple etherscan-like blockchain explorer APIs with Model Context Protocol (MCP) support for AI assistants.

  • deemkeen
  • control your mbot2 with a power combo: mqtt+mcp+llm

  • zhaoyunxing92
  • 本项目是一个钉钉MCP(Message Connector Protocol)服务,提供了与钉钉企业应用交互的API接口。项目基于Go语言开发,支持员工信息查询和消息发送等功能。

  • justmywyw
  • Short and sweet example MCP server / client implementation for Tools, Resources and Prompts.

  • KasarLabs
  • Build powerful and secure AI Agents powered by Starknet.

    Reviews

    1 (1)
    Avatar
    user_ig8kCLmM
    2025-04-15

    Cloudinary MCP Server by yoavniran is an excellent tool for managing multimedia processing in the cloud. The seamless integration and user-friendly interface make it a top choice for developers. Highly recommend trying it out! Check it out here: https://mcp.so/server/cloudinary-mcp-server/yoavniran