mcp-file-context-server
CLAUDE.md39 starsChanged 17 months agoMITView on GitHub
This is a Model Context Protocol (MCP) server that provides file system context and analysis to LLMs. The server is built using the MCP SDK and provides tools for reading, searching, and analyzing code files. Main Server Class (src/index.ts): - FileContextServer - Main server implementation handling MCP protocol - Implements streaming, compression, and chunking for large files - Provides file watching with automatic cache invalidation - Handles cross-platform path compatibility (Windows/macOS/Linux) Services (src/services/): - CodeAnalysisService - Analyzes code complexity, dependencies,…
In this repositoryOne other file it gives its agents.
- docs/llms-full.txtllms.txt
The file
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 80
Use path.posix.join() for glob patterns
- Very specific: line 81
Use path.normalize() for file system operations
- Distinctive: line 82
All internal paths are resolved to absolute paths
- Very specific: line 103
Run tests with npm test using Jest framework.
≈ “Common” is an estimate: at least 1 in 5 of the 28,633 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Development Commands
Build and Run
npm run build- Compile TypeScript to JavaScript in/distnpm run dev- Build and run the server in development modenpm start- Start the compiled server from/distnpm test- Run Jest tests
Environment Configuration
MAX_CACHE_SIZE- Maximum 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
Architecture Overview
This is a Model Context Protocol (MCP) server that provides file system context and analysis to LLMs. The server is built using the MCP SDK and provides tools for reading, searching, and analyzing code files.
Core Components
Main Server Class (src/index.ts):
FileContextServer- Main server implementation handling MCP protocol- Implements streaming, compression, and chunking for large files
- Provides file watching with automatic cache invalidation
- Handles cross-platform path compatibility (Windows/macOS/Linux)
Services (src/services/):
CodeAnalysisService- Analyzes code complexity, dependencies, and quality metricsFileWatcherService- Real-time file system monitoring with chokidarProfileService- Context generation profiles for different use casesTemplateService- Template rendering for prompts and context
Type Definitions (src/types.ts):
- Complete type definitions for file operations, caching, and analysis
- Error handling with custom
FileOperationErrorclass - Profile and context specification interfaces
Key Features
File Operations:
- Cross-platform path handling using POSIX-style paths for globs
- Streaming support for large files with configurable chunk sizes
- Automatic encoding detection (UTF-8, UTF-16LE with BOM support)
- LRU caching with TTL for performance optimization
Code Analysis:
- Cyclomatic complexity calculation
- Dependency extraction and analysis
- Code quality metrics (duplicate lines, long lines, complex functions)
- Language-specific analysis for TypeScript, JavaScript, Python
Search and Filtering:
- Regex pattern matching with context lines
- File type filtering by extension
- Recursive directory traversal
- Automatic exclusion of common artifact directories
Profile System:
- Multiple context generation profiles (code, code-prompt, code-file)
- Configurable file selection and exclusion rules
- Template-based prompt generation
Tool Interface
The server exposes these MCP tools:
list_context_files- List files with metadataread_context- Read file contents with chunking supportsearch_context- Search for patterns in filesget_chunk_count- Calculate chunks before reading large contentset_profile- Switch context generation profilesget_profile_context- Generate structured repository contextgenerate_outline- Create code structure outlines
Path Handling
Critical for cross-platform compatibility:
- Use
path.posix.join()for glob patterns - Use
path.normalize()for file system operations - All internal paths are resolved to absolute paths
- Glob patterns use forward slashes regardless of OS
Caching Strategy
LRU Cache Implementation:
- File content caching with modification time validation
- Automatic cache invalidation on file changes
- Configurable cache size and TTL
- Cache statistics tracking for performance monitoring
Error Handling
Structured Error Management:
- Custom
FileOperationErrorclass with error codes - Specific error codes:
FILE_NOT_FOUND,PERMISSION_DENIED,INVALID_PATH,FILE_TOO_LARGE - Graceful fallback for inaccessible files
- Detailed error context for debugging
Testing
Run tests with npm test using Jest framework. The project uses TypeScript with strict type checking enabled.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

