Skip to main content
Glama
alayonyo

File Context MCP Server

by alayonyo

File Context MCP Server

A Model Context Protocol (MCP) server that provides AI assistants with the ability to read local folder files and use them for context to query and ask questions about file data.

Features

This MCP server provides four powerful tools for file system interaction:

๐Ÿ”ง Available Tools

  1. read_file - Read the contents of any file from the local filesystem

    • Input: path (string) - The path to the file to read

    • Returns: File content as text

  2. list_directory - List all files and directories in a given directory

    • Input: path (string) - The path to the directory to list

    • Returns: Formatted list with file/directory indicators and sizes

  3. search_files - Search for files by name pattern in a directory tree

    • Input: rootPath (string), pattern (string) - Root directory and search pattern

    • Returns: List of matching file paths

  4. analyze_folder - Get comprehensive analysis of folder structure

    • Input: path (string) - The path to the folder to analyze

    • Returns: Detailed analysis including file types, sizes, and directory structure

Quick Start

1. Install Dependencies

npm install

2. Configure Claude API Key

Set your Anthropic/Claude API key as an environment variable. Create a .env.local file in the project root:

echo "ANTHROPIC_API_KEY=sk-ant-api03-your-actual-api-key-here" > .env.local

Note: This project works exclusively with Anthropic's Claude API. You'll need an API key from Anthropic. OpenAI keys are not supported.

Alternatively, you can set the environment variable directly:

export ANTHROPIC_API_KEY="your-claude-api-key-here"

โš ๏ธ Security Note: The .env.local file is automatically ignored by git to keep your API key secure. If no API key is found, the application will automatically run in mock mode for development.

3. Build the Project

npm run build

4. Run Tests

npm test # Run all tests npm run test:coverage # Run tests with coverage report npm run test:watch # Run tests in watch mode

5. Test the Server

npm run start:http

Then open http://localhost:3000 in your browser for a full interactive interface!

Command Line Interface

npm start

Interface Options

This project includes multiple ways to interact with your files:

๐ŸŽจ Interactive Web UI (New!)

npm run start:http

Open http://localhost:3000 in your browser for a modern, interactive interface featuring:

  • ๐Ÿ—‚๏ธ File Operations Panel: Direct access to read, list, search, and analyze tools

  • ๐Ÿ’ฌ AI Chat Assistant: Natural language file queries with intelligent command detection

  • ๐Ÿ“Š Real-time Results: Live display of file operations and responses

  • ๐Ÿ“ฑ Responsive Design: Works on desktop, tablet, and mobile devices

  • โŒจ๏ธ Keyboard Shortcuts: Ctrl/Cmd+K to focus chat, Enter to send messages

๐Ÿ’ฌ Chat Interface Options

๐ŸŒ Terminal Chat Interface (requires network & API key)

npm run chat # Interactive chat with Claude npm run chat -- --help # Show usage options

๐ŸŽญ Mock Mode (no network required)

Perfect for corporate environments or testing:

npm run chat:mock # Use built-in mock responses npm run chat -- --mock # Alternative syntax npm run chat -- -m # Short form

Mock mode features:

  • โœ… Full file system access (read, list, search)

  • โœ… Realistic AI-like responses

  • โœ… No network calls or API keys needed

  • โœ… Perfect for demos and corporate networks

  • โœ… Automatic fallback when API fails

๐Ÿฆ™ Local AI (Ollama integration)

npm run local-chat # Use local Ollama models

Testing

This project includes comprehensive test coverage using Jest and TypeScript:

๐Ÿงช Test Categories

  • Unit Tests: Core file operations (read, list, search, analyze)

  • Integration Tests: MCP server functionality and tool interactions

  • Mock Tests: Chat interface with simulated Claude responses

  • Error Handling: Edge cases, permissions, and network failures

  • Performance Tests: Large directories and concurrent operations

๐Ÿ“Š Test Coverage

Current coverage: >90% of core functionality

๐Ÿš€ Running Tests

npm test # Run all tests npm run test:coverage # Detailed coverage report npm run test:watch # Interactive development mode

โœ… Test Features

  • Isolated test environments with temporary directories

  • Mocked external dependencies (API calls, file system)

  • Cross-platform compatibility testing

  • Security validation (path traversal, permissions)

  • Performance benchmarks

Usage with MCP Clients

Claude Desktop Configuration

Add to your Claude Desktop configuration file (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{ "mcpServers": { "file-context": { "command": "node", "args": ["/absolute/path/to/your/project/build/index.js"] } } }

VS Code Configuration

The project includes a .vscode/mcp.json file for VS Code MCP integration:

{ "servers": { "file-context-server": { "type": "stdio", "command": "node", "args": ["/Users/yonatan.ayalon/projects/new_app_1/my-mcp/build/index.js"] } } }

Example Use Cases

๐ŸŽจ Web UI Examples

The interactive web interface supports both direct tool usage and natural language:

Direct Operations:

  • Use the file operation panels to read, list, search, and analyze files

  • Real-time results display with syntax highlighting

  • Chat assistant for natural language queries

Natural Language Chat:

  • "What files are in the current directory?"

  • "Read the package.json file"

  • "Search for all .ts files in the src folder"

  • "Analyze this project structure"

  • "Show me the contents of README.md"

๐Ÿ“– Reading Project Files

"Can you read the package.json file and tell me about the project dependencies?"

๐Ÿ” Analyzing Codebases

"Analyze the src directory and give me an overview of the project structure"

๐Ÿ”Ž Finding Specific Files

"Search for all TypeScript files that contain 'interface' in the filename"

๐Ÿ“Š Project Analysis

"Analyze this entire project folder and tell me what kind of application this is"

Security Features

  • Path Resolution: All file paths are resolved to prevent directory traversal attacks

  • Access Checks: Files and directories are checked for read permissions before access

  • Limited Recursion: Directory analysis limits depth to prevent infinite loops

  • Hidden File Filtering: Skips hidden directories and node_modules in recursive operations

Development

Project Structure

โ”œโ”€โ”€ src/ โ”‚ โ””โ”€โ”€ index.ts # Main MCP server implementation โ”œโ”€โ”€ build/ # Compiled JavaScript output โ”œโ”€โ”€ .vscode/ โ”‚ โ””โ”€โ”€ mcp.json # VS Code MCP configuration โ”œโ”€โ”€ package.json # Project configuration โ”œโ”€โ”€ tsconfig.json # TypeScript configuration โ””โ”€โ”€ README.md # This file

Available Scripts

  • npm run build - Compile TypeScript to JavaScript

  • npm run dev - Watch mode compilation

  • npm start - Run the compiled server

Testing the Server

You can test the server using the MCP Inspector:

npx @modelcontextprotocol/inspector node build/index.js

Technical Details

  • Protocol: Model Context Protocol (MCP)

  • Transport: STDIO (Standard Input/Output)

  • Language: TypeScript/Node.js

  • SDK: @modelcontextprotocol/sdk

Requirements

  • Node.js 16+

  • TypeScript 5+

  • Model Context Protocol compatible client (Claude Desktop, VS Code, etc.)

License

MIT


Need Help? Check out the Model Context Protocol documentation for more information about MCP and how to integrate it with different clients.

-
security - not tested
F
license - not found
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/alayonyo/mcp-resume'

If you have feedback or need assistance with the MCP directory API, please join our Discord server