Uses Express.js to implement a REST API server with endpoints for file operations and LLM queries.
Implemented as a Node.js application for server-side functionality.
Integrates with Ollama as a local LLM provider for context-aware querying. Allows users to send prompts to Ollama models with context from local files.
Includes a Postman collection for testing all API endpoints of the MCP server.
Incorporates OpenAPI/Swagger for API documentation with request/response schemas and endpoint documentation.
Built using TypeScript to provide type safety and modern development practices.
File Context MCP (Model Context Processor)
Overview
File Context MCP is a TypeScript-based application that provides an API for querying Large Language Models (LLMs) with context from local files. It supports multiple LLM providers (Ollama and Together.ai) and can process various file types to generate context-aware responses.
Core Features
1. File System Navigation
Dynamic file and directory traversal
Support for multiple file types (
.txt
,.md
,.ts
,.json
, etc.)Safe path handling with sanitization
2. Context Processing
Intelligent context formatting for LLM queries
Context truncation to handle large files
File content aggregation for directory queries
3. Multi-Model Support
Ollama (local) integration
Together.ai (cloud) integration
Extensible model interface design
Architecture
Core Components
Server (server.ts)
Express.js REST API implementation
File upload/delete handling with multer
Request validation and routing
OpenAPI/Swagger integration
FileSystemTools (core/fileSystem.ts)
File and directory operations
Content reading and parsing
Directory traversal
Secure file deletion
Error handling for file operations
ModelInterface (core/modelInterface.ts)
Multiple LLM provider support (Ollama, Together.ai)
Response formatting and error handling
Configurable model parameters
Unified query interface
Utility Modules
fileUtils
: File type detection, path sanitization, size formattingpromptUtils
: Context formatting, intelligent truncationvalidators
: Path, query, and model validationlogger
: Structured logging with levels
Configuration (config/config.ts)
Environment variable management
API keys and endpoints
Model configuration
Server settings
API Specification (resources/file-context-api.yml)
OpenAPI 3.0 documentation
Request/response schemas
Endpoint documentation
Error response definitions
API Endpoints
1. List Files
2. Upload File
3. Delete File
4. Query with Context
Setup and Configuration
Environment Variables
Installation
Installing via Smithery
To install File Context MCP for Claude Desktop automatically via Smithery:
Running the Application
How It Works
File Processing Flow
Request received → Path validation → File reading → Content extraction
Directory handling includes recursive file reading
Content filtering based on file type
File uploads are validated for type and size
Secure file deletion with path validation
Context Processing
File contents are aggregated
Context is formatted with clear boundaries
Large contexts are intelligently truncated
Prompt formatting adds structure for LLM understanding
Model Integration
Unified interface for different LLM providers
Error handling and response normalization
Configurable model parameters
Security Features
Path Sanitization
Prevention of directory traversal attacks
Path validation and normalization
Safe file type checking
File Upload Security
File type validation
File size limits (5MB max)
Secure file storage
Safe file deletion
Input Validation
Query content validation
Model type verification
Path structure verification
File content validation
Supported File Types
The application supports the following text-based file types:
Documentation:
.txt
,.md
Code files:
.js
,.ts
,.jsx
,.tsx
,.py
,.java
,.cpp
,.c
,.h
Configuration:
.json
,.yaml
,.yml
,.env
Web files:
.html
,.css
Data files:
.csv
,.xml
,.log
File type validation is enforced during:
File uploads
Context processing
File reading operations
Maximum file size: 5MB per file
Error Handling
The application implements comprehensive error handling:
File system errors
API response errors
Invalid input errors
Model-specific errors
File upload/deletion errors
Development
Project Structure
Adding New Features
New File Types
Add extensions to
fileUtils.isTextFile()
Implement specific handlers if needed
New Model Providers
Extend
ModelInterface
classAdd provider to
validators.isValidModel()
Implement provider-specific error handling
Testing
Postman Collection
The project includes a Postman collection (postman/File-Context-MCP.postman_collection.json
) for testing all API endpoints. To use it:
Import the Collection
Open Postman
Click "Import" button
Select or drag the
File-Context-MCP.postman_collection.json
file
Available Requests
File-Context-MCP ├── List files │ └── GET http://localhost:3001/api/files?path=./storage ├── Query │ └── POST http://localhost:3001/api/query (single file analysis) ├── Analyze multiple files │ └── POST http://localhost:3001/api/query (directory analysis) └── File Upload └── POST http://localhost:3001/api/files/uploadTesting File Operations
List Files: View contents of the storage directory
Upload File: Use form-data with key "file" and select a text file
Query File: Analyze single file contents with LLM
Analyze Directory: Process multiple files with LLM
Example Queries
// Single file analysis { "path": "./storage/code-samples/example.ts", "query": "Explain what this TypeScript code does", "model": "ollama" } // Directory analysis { "path": "./storage", "query": "What types of files are in this directory and summarize their contents?", "model": "ollama" }File Upload Guide
Use the "File Upload" request
Select "form-data" in the Body tab
Add key "file" with type "File"
Choose a supported text file (see Supported File Types)
Maximum file size: 5MB
Manual Testing
Use the provided test files in
/storage
Test different file types and queries
Verify model responses and error handling
Test file size limits and type restrictions
Environment Setup
Make sure to:
Have the server running (
npm run dev
)Configure environment variables
Have Ollama running locally (for Ollama model)
Set Together.ai API key (for Together model)
Future Considerations
How to handle large files efficiently
Expanding supported file types
Optimizing context processing
Adding streaming support for responses
Implementing rate limiting and caching
This project demonstrates modern TypeScript/Node.js practices with a focus on modularity, type safety, and error handling while providing a flexible interface for LLM interactions with file-based context.
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
This server provides an API to query Large Language Models using context from local files, supporting various models and file types for context-aware responses.
- Overview
- Core Features
- Architecture
- API Endpoints
- Setup and Configuration
- How It Works
- Security Features
- Supported File Types
- Error Handling
- Development
- Testing
- Future Considerations
Related Resources
Related MCP Servers
- -securityAlicense-qualityA Model Context Protocol server that provides access to BigQuery. This server enables LLMs to inspect database schemas and execute queries.Last updated -120MIT License
- -securityFlicense-qualityA TypeScript-based server that provides a memory system for Large Language Models (LLMs), allowing users to interact with multiple LLM providers while maintaining conversation history and offering tools for managing providers and model configurations.Last updated -27
- -securityAlicense-qualityA server that enables Large Language Models to discover and interact with REST APIs defined by OpenAPI specifications through the Model Context Protocol.Last updated -519154MIT License
MCP TapData Serverofficial
-securityFlicense-qualityA Model Context Protocol server that enables Large Language Models to access and interact with database connections, including viewing schemas and performing CRUD operations on connected databases.Last updated -