Get the FREE Ultimate OpenClaw Setup Guide →

mcp-file-context

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.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio bsmi021-mcp-file-context-server npx file-context-server \
  --env CACHE_TTL="Cache time-to-live in milliseconds (default: 1 hour)" \
  --env MAX_FILE_SIZE="Maximum file size in bytes for reading" \
  --env MAX_CACHE_SIZE="Maximum number of cached entries (default: 1000)"

How to use

File Context Server provides LLM-accessible file system context with capabilities to read, list, search, and analyze code files. It exposes tools such as list_context_files to enumerate directory contents with metadata, read_context to fetch file contents with encoding options, search_context to perform pattern searches with contextual lines, analyze_code to compute quality metrics like complexity and dependencies, and cache_stats to inspect caching performance. Start it via npx file-context-server and invoke the available tools through the MCP interface to retrieve structured results that LLMs can reason over. The server includes built-in real-time caching and supports file-type filtering, regex searches, and configurable context lines to tailor returned snippets for your prompts.

How to install

Prerequisites:

  • Node.js (recommended LTS) and npm installed on your system
  • Familiarity with MCP tooling and the command interface

Installation steps:

  1. Install the package from npm:
npm install @modelcontextprotocol/file-context-server
  1. (Optional) Install via Smithery for Claude Desktop integration:
npx -y @smithery/cli install @bsmi021/mcp-file-context-server --client claude
  1. Verify installation by starting the server (example):
npx file-context-server
  1. If you are integrating with an app using MCP, reference the mcp_config accordingly and manage environment variables as needed.

Additional notes

Tips and notes:

  • Environment variables:
    • MAX_CACHE_SIZE: cap on cached entries (default 1000)
    • CACHE_TTL: time-to-live for cache entries in milliseconds (default 3600000)
    • MAX_FILE_SIZE: maximum file size in bytes allowed for reading
  • Cross-platform path handling has been updated to improve compatibility; end users do not need to take action, but developers should follow POSIX-style globs and normalized paths when extending functionality.
  • Tools return structured JSON objects for easy parsing by LLMs. Use cache_stats to monitor performance and adjust cache-related env vars as needed.
  • If you encounter FILE_NOT_FOUND or PERMISSION_DENIED, verify the path and file permissions. Ensure the server has access to the requested directories.
  • This server is designed to work with multiple file types and supports recursive traversal, context-aware results, and exclusion patterns via the search and read APIs.

Related MCP Servers

Sponsor this space

Reach thousands of developers