Coding File Context MCP server

Provides advanced file system access and code analysis capabilities, enabling efficient reading, searching, and analysis of large codebases for automated quality assessment and intelligent navigation.
Back to servers
Provider
Brian W. Smith
Release date
Jan 04, 2025
Language
TypeScript
Stats
18 stars

The File Context Server is a powerful Model Context Protocol (MCP) server that provides file system access capabilities to Large Language Models (LLMs). It enables models to read, search, and analyze code files with advanced features like real-time file watching and intelligent caching.

Features Overview

  • File Operations: Read files, list directories, watch for changes
  • Code Analysis: Calculate complexity, extract dependencies, analyze code quality
  • Smart Caching: LRU strategy with automatic invalidation
  • Advanced Search: Pattern matching with context-aware results

Installation

Via Smithery

Install the File Context Server automatically using Smithery:

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

Manual Installation

Install using npm:

npm install @modelcontextprotocol/file-context-server

Getting Started

Starting the Server

Launch the server with:

npx file-context-server

Available Tools

Listing Files

Use the list_context_files tool to get file information:

{
  "path": "./src",
  "recursive": true,
  "includeHidden": false
}

Reading Files

Read file or directory contents with the read_context tool:

{
  "path": "./src/index.ts",
  "encoding": "utf8",
  "maxSize": 1000000,
  "recursive": true,
  "fileTypes": ["ts", "js"]
}

Searching Content

Search for patterns in files using search_context:

{
  "pattern": "function.*",
  "path": "./src",
  "options": {
    "recursive": true,
    "contextLines": 2,
    "fileTypes": ["ts"]
  }
}

Analyzing Code

Get code quality metrics with analyze_code:

{
  "path": "./src",
  "recursive": true,
  "metrics": ["complexity", "dependencies", "quality"]
}

Checking Cache Statistics

Monitor cache performance using cache_stats:

{
  "detailed": true
}

Error Handling

The server provides specific error codes for different situations:

  • FILE_NOT_FOUND: File or directory doesn't 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 Options

Customize server behavior with these environment variables:

  • 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

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later