Real-time global intelligence dashboard. AI-powered news aggregation, geopolitical monitoring, and infrastructure tracking in a unified situational awareness interface
MCP server for file context and code analysis
This repository provides an MCP server that exposes file system context to connected agents. It supports file listing, reading, regex search, code analysis, cache stats, and file watching with cache invalidation.
Builders who want their agent to read, search, and analyze project files through MCP.
You can give your agent live file context instead of pasting code by hand.
What it does
File operations
Lists files, reads files and directories, watches for changes, filters by type, and handles multiple encodings.
Code analysis
Calculates complexity, extracts dependencies, analyzes comments, and flags duplicate lines, long lines, and complex functions.
Smart caching
Uses LRU caching, cache invalidation on file changes, size limits, cache stats, and last-read result caching.
Advanced search
Searches with regex, file filters, surrounding context lines, multi-pattern search, cached results, and exclusion patterns.
How to get it
- 1To install File Context Server for Claude Desktop automatically via Smithery
npx -y @smithery/cli install @bsmi021/mcp-file-context-server --client claude
- 2Run
npm install @modelcontextprotocol/file-context-server
- 3Run
npx file-context-server
README
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
Installing via Smithery
To install File Context Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @bsmi021/mcp-file-context-server --client claude
Manual Installation
npm install @modelcontextprotocol/file-context-server
Usage
Starting the Server
npx file-context-server
Available Tools
-
list_context_files
- Lists files in a directory with detailed metadata
{ "path": "./src", "recursive": true, "includeHidden": false } -
read_context
- Reads file or directory contents with metadata
{ "path": "./src/index.ts", "encoding": "utf8", "maxSize": 1000000, "recursive": true, "fileTypes": ["ts", "js"] } -
search_context
- Searches for patterns in files with context
{ "pattern": "function.*", "path": "./src", "options": { "recursive": true, "contextLines": 2, "fileTypes": ["ts"] } } -
analyze_code
- Analyzes code files for quality metrics
{ "path": "./src", "recursive": true, "metrics": ["complexity", "dependencies", "quality"] } -
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 existPERMISSION_DENIED: Access permission issuesINVALID_PATH: Invalid file path formatFILE_TOO_LARGE: File exceeds size limitENCODING_ERROR: File encoding issuesUNKNOWN_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.
Cross-Platform Path Compatibility
Note: As of April 2025, all file and directory path handling in File Context Server has been updated for improved cross-platform compatibility (Windows, macOS, Linux):
- All glob patterns use POSIX-style paths (forward slashes) internally, ensuring consistent file matching regardless of OS.
- All file system operations (reading, writing, stat, etc.) use normalized absolute paths for reliability.
- If you are developing or extending the server, use
path.posix.joinfor glob patterns andpath.normalizefor file system access. - This change prevents issues with path separators and file matching on different operating systems.
No changes are required for end users, but developers should follow these conventions when contributing to the project.
Files in the repo
- .claude
- .cursor
- .llm-context
- cache
- docs
- examples
- PRPs
- src
- .gitignore
- CLAUDE.md
- Dockerfile
- GETFILES.md
- INITIAL.md
- LICENSE
- package-lock.json
- package.json
- pnpm-lock.yaml
- README.md
- smithery.yaml
- STREAMING.md
- tsconfig.json
Discussion (0)
Ask about usage, or say what you built with itSign in to join the discussion.
No comments yet. Be the first to say what this is good for.
More connectors
High-performance code intelligence MCP server. Indexes codebases into a persistent knowledge graph — average repo in milliseconds. 158 languages, sub-ms queries, 99% fewer tokens. Single static binary, zero dependencies.

Universal provider proxy for OpenAI Codex & Claude Code — use any LLM (Claude, Gemini, Grok, DeepSeek, Ollama…) with Codex CLI, App, SDK, and Claude Code
Git-native persistent memory for AI coding agents. Implements Google OKF v0.2 with sub-300µs in-memory BM25 search, embedded MCP server, and progressive disclosure. Slashes token bloat by 80% with zero external databases or dependencies. Built in pure Go.
Local-first code intelligence graph for MCP and CLI. Builds a persistent map of your codebase so AI coding tools read only what matters, with benchmarked context reductions on reviews and large-repo workflows.
Stop your AI from making things up — it proposes, deterministic tools decide, every claim checked against ground truth with evidence. Grounded facts and context survive resets. Reverse engineering is the proving ground. MCP server + CLI.