Skip to main content
Glama
boleyn

FS-MCP Server

by boleyn

FS-MCP: Universal File Reader & Intelligent Search MCP Server

Python FastMCP License PRs Welcome

A powerful MCP (Model Context Protocol) server that provides intelligent file reading and semantic search capabilities

English | ไธญๆ–‡


English

๐Ÿš€ Features

  • ๐Ÿง  Intelligent Text Detection: Automatically identifies text files without relying on file extensions

  • ๐Ÿ“„ Multi-Format Support: Handles text files and document formats (Word, Excel, PDF, etc.)

  • ๐Ÿ”’ Security First: Restricted access to configured safe directories only

  • ๐Ÿ“ Range Reading: Supports reading specific line ranges for large files

  • ๐Ÿ”„ Document Conversion: Automatic conversion of documents to Markdown with caching

  • ๐Ÿ” Vector Search: Semantic search powered by AI embeddings

  • โšก High Performance: Batch processing and intelligent caching support

  • ๐ŸŒ Multi-language: Supports both English and Chinese content

๐Ÿ“‹ Table of Contents

๐Ÿš€ Quick Start

1. Clone and Install

git clone https://github.com/yourusername/fs-mcp.git
cd fs-mcp

Using uv (Recommended):

uv sync

Using pip:

pip install -r requirements.txt  # If you have a requirements.txt
# OR install directly
pip install fastmcp>=2.0.0 langchain>=0.3.0 python-dotenv>=1.1.0

2. Environment Configuration

Create a .env file in the project root:

# Security Settings
SAFE_DIRECTORY=.                    # Directory restriction (required)
MAX_FILE_SIZE_MB=100                # File size limit in MB

# Encoding Settings
DEFAULT_ENCODING=utf-8

# AI Embeddings Configuration (for vector search)
OPENAI_EMBEDDINGS_API_KEY=your-api-key
OPENAI_EMBEDDINGS_BASE_URL=http://your-embedding-service/v1
EMBEDDING_MODEL_NAME=BAAI/bge-m3    # Or your preferred model
EMBEDDING_CHUNK_SIZE=1000

3. Start the Server

python main.py

The server will start on http://localhost:3002 and automatically build the vector index.

๐Ÿ› ๏ธ Installation

System Requirements

  • Python: 3.12 or higher

  • OS: Windows, macOS, Linux

  • Memory: 4GB+ recommended for vector search

  • Storage: 1GB+ for caching and indexes

Dependencies

Core dependencies are managed in pyproject.toml:

  • fastmcp>=2.0.0 - MCP server framework

  • langchain>=0.3.0 - AI and vector search

  • python-dotenv>=1.1.0 - Environment management

  • Document processing libraries (pandas, openpyxl, python-docx, etc.)

โš™๏ธ Configuration

Environment Variables

Variable

Default

Description

SAFE_DIRECTORY

.

Root directory for file access

MAX_FILE_SIZE_MB

100

Maximum file size limit

DEFAULT_ENCODING

utf-8

Default file encoding

OPENAI_EMBEDDINGS_API_KEY

-

API key for embedding service

OPENAI_EMBEDDINGS_BASE_URL

-

Embedding service URL

EMBEDDING_MODEL_NAME

BAAI/bge-m3

AI model for embeddings

EMBEDDING_CHUNK_SIZE

1000

Text chunk size for processing

Advanced Configuration

For production deployments, consider:

  • Setting up rate limiting

  • Configuring log rotation

  • Using external vector databases

  • Setting up monitoring

๐Ÿ”ง MCP Tools

1. view_directory_tree

Purpose: Display directory structure in tree format

view_directory_tree(
    directory_path=".",     # Target directory
    max_depth=3,           # Maximum depth
    max_entries=300        # Maximum entries to show
)

2. read_file_content

Purpose: Read file content with line range support

read_file_content(
    file_path="example.py",  # File path
    start_line=1,           # Start line (optional)
    end_line=50             # End line (optional)
)

3. search_documents

Purpose: Intelligent semantic search across documents

search_documents(
    query="authentication logic",     # Search query
    search_type="semantic",          # semantic/filename/hybrid/extension
    file_extensions=".py,.js",       # File type filter (optional)
    max_results=10                   # Maximum results
)

4. rebuild_document_index

Purpose: Rebuild vector index for search

rebuild_document_index()  # No parameters needed

5. get_document_stats

Purpose: Get index statistics and system status

get_document_stats()  # Returns comprehensive stats

6. list_files

Purpose: List files in directory with pattern matching

list_files(
    directory_path="./src",  # Directory to list
    pattern="*.py",         # File pattern
    include_size=True       # Include file sizes
)

7. preview_file

Purpose: Quick preview of file content

preview_file(
    file_path="example.py",  # File to preview
    lines=20                # Number of lines
)

Capabilities

  • Semantic Understanding: Search "user authentication" finds "login verification" code

  • Synonym Recognition: Search "database" finds "ๆ•ฐๆฎๅบ“" (Chinese) content

  • Multi-language Support: Handles English, Chinese, and mixed content

  • Context Awareness: Understands code semantics and relationships

Search Types

  1. Semantic Search (semantic): AI-powered understanding

  2. Filename Search (filename): Fast filename matching

  3. Extension Search (extension): Filter by file type

  4. Hybrid Search (hybrid): Combines semantic + filename

Technical Stack

  • Embedding Model: BAAI/bge-m3 (1024-dimensional vectors)

  • Vector Database: ChromaDB

  • Text Splitting: Intelligent semantic chunking

  • Incremental Updates: Hash-based change detection

๐Ÿ“ Supported Formats

Auto-detected Text Files

  • Programming languages: .py, .js, .ts, .java, .cpp, .c, .go, .rs, etc.

  • Config files: .json, .yaml, .toml, .ini, .xml, .env

  • Documentation: .md, .txt, .rst

  • Web files: .html, .css, .scss

  • Data files: .csv, .tsv

  • Files without extensions (auto-detected)

Document Formats (Auto-converted to Markdown)

  • Microsoft Office: .docx, .xlsx, .pptx

  • OpenDocument: .odt, .ods, .odp

  • PDF: .pdf (text extraction)

  • Legacy formats: .doc, .xls (limited support)

๐Ÿ”’ Security Features

Access Control

  • Directory Restriction: Access limited to SAFE_DIRECTORY and subdirectories

  • Path Traversal Protection: Automatic prevention of ../ attacks

  • Symlink Control: Configurable symbolic link access

  • File Size Limits: Prevents reading oversized files

Validation

  • Path Sanitization: Automatic path cleaning and validation

  • Permission Checks: Verify read permissions before access

  • Error Handling: Graceful failure with informative messages

๐Ÿ”— Integration

Claude Desktop

Add to your Claude Desktop MCP configuration:

{
  "mcpServers": {
    "fs-mcp": {
      "command": "python",
      "args": ["main.py"],
      "cwd": "/path/to/fs-mcp",
      "env": {
        "SAFE_DIRECTORY": "/your/project/directory"
      }
    }
  }
}

Other MCP Clients

Connect to http://localhost:3002 using Server-Sent Events (SSE) protocol.

API Integration

The server exposes standard MCP endpoints that can be integrated with any MCP-compatible client.

๐Ÿ—๏ธ Project Structure

fs-mcp/
โ”œโ”€โ”€ main.py                    # Main MCP server
โ”œโ”€โ”€ src/                       # Core modules
โ”‚   โ”œโ”€โ”€ __init__.py           # Package initialization
โ”‚   โ”œโ”€โ”€ file_reader.py        # Core file reading logic
โ”‚   โ”œโ”€โ”€ security_validator.py # Security and validation
โ”‚   โ”œโ”€โ”€ text_detector.py      # Intelligent file detection
โ”‚   โ”œโ”€โ”€ config_manager.py     # Configuration management
โ”‚   โ”œโ”€โ”€ document_cache.py     # Document caching system
โ”‚   โ”œโ”€โ”€ file_converters.py    # Document format converters
โ”‚   โ”œโ”€โ”€ dir_tree.py          # Directory tree generation
โ”‚   โ”œโ”€โ”€ embedding_config.py   # AI embedding configuration
โ”‚   โ”œโ”€โ”€ codebase_indexer.py   # Vector indexing system
โ”‚   โ”œโ”€โ”€ codebase_search.py    # Search engine
โ”‚   โ”œโ”€โ”€ index_scheduler.py    # Index scheduling
โ”‚   โ””โ”€โ”€ progress_bar.py       # Progress display utilities
โ”œโ”€โ”€ tests/                    # Test suite
โ”œโ”€โ”€ cache/                    # Document cache (auto-created)
โ”œโ”€โ”€ logs/                     # Log files (auto-created)
โ”œโ”€โ”€ pyproject.toml           # Project configuration
โ”œโ”€โ”€ .env.example             # Environment template
โ”œโ”€โ”€ .gitignore              # Git ignore rules
โ””โ”€โ”€ README.md               # This file

๐Ÿ’ป Development

Setting Up Development Environment

# Clone repository
git clone https://github.com/yourusername/fs-mcp.git
cd fs-mcp

# Install with development dependencies
uv sync --group dev

# OR with pip
pip install -e ".[dev]"

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=src

# Run specific test
pytest tests/test_file_reader.py

Code Quality

# Format code
black src/ tests/

# Lint code
flake8 src/ tests/

# Type checking
mypy src/

Debugging

Monitor logs in real-time:

tail -f logs/mcp_server_$(date +%Y%m%d).log

๐Ÿค Contributing

We welcome contributions! Here's how to get started:

1. Fork and Clone

git clone https://github.com/yourusername/fs-mcp.git
cd fs-mcp

2. Create Feature Branch

git checkout -b feature/your-feature-name

3. Make Changes

  • Follow the existing code style

  • Add tests for new functionality

  • Update documentation as needed

4. Test Your Changes

pytest
black src/ tests/
flake8 src/ tests/

5. Submit Pull Request

  • Describe your changes clearly

  • Reference any related issues

  • Ensure all tests pass

Development Guidelines

  • Code Style: Follow PEP 8, use Black for formatting

  • Testing: Maintain test coverage above 80%

  • Documentation: Update README and docstrings

  • Commits: Use conventional commit messages

  • Security: Follow security best practices

๐Ÿ“‹ Roadmap

  • Enhanced PDF Processing: Better table and image extraction

  • More Embedding Models: Support for local models

  • Real-time Indexing: File system watchers

  • Advanced Search: Regex, proximity, faceted search

  • Performance Optimization: Async processing, caching improvements

  • Web Interface: Optional web UI for management

  • Plugin System: Custom file type handlers

  • Enterprise Features: Authentication, rate limiting, monitoring

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support


Related MCP server: MCP Filesystem Server

ไธญๆ–‡

๐Ÿš€ ๅŠŸ่ƒฝ็‰น็‚น

  • ๐Ÿง  ๆ™บ่ƒฝๆ–‡ๆœฌๆฃ€ๆต‹: ๆ— ้œ€ไพ่ต–ๆ‰ฉๅฑ•ๅ๏ผŒ่‡ชๅŠจ่ฏ†ๅˆซๆ–‡ๆœฌๆ–‡ไปถ

  • ๐Ÿ“„ ๅคšๆ ผๅผๆ”ฏๆŒ: ๆ”ฏๆŒๆ–‡ๆœฌๆ–‡ไปถๅ’Œๆ–‡ๆกฃๆ ผๅผ๏ผˆWordใ€Excelใ€PDF็ญ‰๏ผ‰

  • ๐Ÿ”’ ๅฎ‰ๅ…จ้ชŒ่ฏ: ๅชๅ…่ฎธ่ฏปๅ–้…็ฝฎ็š„ๅฎ‰ๅ…จ็›ฎๅฝ•ไธญ็š„ๆ–‡ไปถ

  • ๐Ÿ“ ๆŒ‰่กŒ่ฏปๅ–: ๆ”ฏๆŒๆŒ‡ๅฎš่กŒ่Œƒๅ›ด่ฏปๅ–๏ผŒไพฟไบŽๅค„็†ๅคงๆ–‡ไปถ

  • ๐Ÿ”„ ๆ–‡ๆกฃ่ฝฌๆข: ่‡ชๅŠจๅฐ†ๆ–‡ๆกฃๆ ผๅผ่ฝฌๆขไธบMarkdownๅนถ็ผ“ๅญ˜

  • ๐Ÿ” ๅ‘้‡ๆœ็ดข: ๅŸบไบŽAIๅตŒๅ…ฅ็š„่ฏญไน‰ๆœ็ดข

  • โšก ้ซ˜ๆ€ง่ƒฝ: ๆ”ฏๆŒๆ‰น้‡ๆ–‡ไปถๅค„็†ๅ’Œๆ™บ่ƒฝ็ผ“ๅญ˜

  • ๐ŸŒ ๅคš่ฏญ่จ€: ๆ”ฏๆŒไธญ่‹ฑๆ–‡ๅ†…ๅฎนๅค„็†

๐Ÿš€ ๅฟซ้€Ÿๅผ€ๅง‹

1. ๅ…‹้š†ๅ’Œๅฎ‰่ฃ…

git clone https://github.com/yourusername/fs-mcp.git
cd fs-mcp

# ๆŽจ่ไฝฟ็”จ uv
uv sync

# ๆˆ–ไฝฟ็”จ pip
pip install -r requirements.txt

2. ็Žฏๅขƒ้…็ฝฎ

ๅˆ›ๅปบ .env ๆ–‡ไปถ๏ผš

# ๅฎ‰ๅ…จ่ฎพ็ฝฎ
SAFE_DIRECTORY=.                    # ็›ฎๅฝ•่ฎฟ้—ฎ้™ๅˆถ๏ผˆๅฟ…้œ€๏ผ‰
MAX_FILE_SIZE_MB=100                # ๆ–‡ไปถๅคงๅฐ้™ๅˆถ๏ผˆMB๏ผ‰

# ็ผ–็ ่ฎพ็ฝฎ
DEFAULT_ENCODING=utf-8

# AIๅตŒๅ…ฅ้…็ฝฎ๏ผˆ็”จไบŽๅ‘้‡ๆœ็ดข๏ผ‰
OPENAI_EMBEDDINGS_API_KEY=your-api-key
OPENAI_EMBEDDINGS_BASE_URL=http://your-embedding-service/v1
EMBEDDING_MODEL_NAME=BAAI/bge-m3    # ๆˆ–ๆ‚จๅๅฅฝ็š„ๆจกๅž‹
EMBEDDING_CHUNK_SIZE=1000

3. ๅฏๅŠจๆœๅŠกๅ™จ

python main.py

ๆœๅŠกๅ™จๅฐ†ๅœจ http://localhost:3002 ๅฏๅŠจๅนถ่‡ชๅŠจๅปบ็ซ‹ๅ‘้‡็ดขๅผ•ใ€‚

๐Ÿ› ๏ธ MCPๅทฅๅ…ท่ฏดๆ˜Ž

่ฏฆ็ป†็š„ๅทฅๅ…ทไฝฟ็”จๆ–นๆณ•่ฏทๅ‚่€ƒ่‹ฑๆ–‡้ƒจๅˆ†็š„ MCP Tools ็ซ ่Š‚ใ€‚

๐Ÿ” ๅ‘้‡ๆœ็ดขๅŠŸ่ƒฝ

  • ๆฆ‚ๅฟตๅŒน้…๏ผšๆœ็ดข"็”จๆˆท่ฎค่ฏ"่ƒฝๆ‰พๅˆฐ"็™ปๅฝ•้ชŒ่ฏ"็›ธๅ…ณไปฃ็ 

  • ๅŒไน‰่ฏ็†่งฃ๏ผšๆœ็ดข"database"่ƒฝๆ‰พๅˆฐ"ๆ•ฐๆฎๅบ“"็›ธๅ…ณๅ†…ๅฎน

  • ๅคš่ฏญ่จ€ๆ”ฏๆŒ๏ผšๅŒๆ—ถ็†่งฃไธญ่‹ฑๆ–‡ไปฃ็ ๅ’Œๆณจ้‡Š

  • ไธŠไธ‹ๆ–‡็†่งฃ๏ผš็†่งฃไปฃ็ ็š„่ฏญไน‰ๅ’ŒไธŠไธ‹ๆ–‡ๅ…ณ็ณป

๐Ÿ“ ๆ”ฏๆŒ็š„ๆ–‡ไปถๆ ผๅผ

่ฏฆ็ป†็š„ๆ ผๅผๆ”ฏๆŒ่ฏทๅ‚่€ƒ่‹ฑๆ–‡้ƒจๅˆ†็š„ Supported Formats ็ซ ่Š‚ใ€‚

๐Ÿ”’ ๅฎ‰ๅ…จ็‰นๆ€ง

  • ่ทฏๅพ„้ชŒ่ฏ: ๅชๅ…่ฎธ่ฎฟ้—ฎ้…็ฝฎ็š„ๅฎ‰ๅ…จ็›ฎๅฝ•ๅŠๅ…ถๅญ็›ฎๅฝ•

  • ๆ–‡ไปถๅคงๅฐ้™ๅˆถ: ้˜ฒๆญข่ฏปๅ–่ฟ‡ๅคงๆ–‡ไปถ

  • ่ทฏๅพ„้ๅކ้˜ฒๆŠค: ่‡ชๅŠจ้˜ฒๆญข ../ ็ญ‰่ทฏๅพ„้ๅކๆ”ปๅ‡ป

  • ็ฌฆๅท้“พๆŽฅๆŽงๅˆถ: ๅฏ้…็ฝฎๆ˜ฏๅฆๅ…่ฎธ่ฎฟ้—ฎ็ฌฆๅท้“พๆŽฅ

๐Ÿ”— ้›†ๆˆๆ–นๅผ

Claude Desktop้›†ๆˆ

ๅœจ Claude Desktop ็š„ MCP ้…็ฝฎไธญๆทปๅŠ ๏ผš

{
  "mcpServers": {
    "fs-mcp": {
      "command": "python",
      "args": ["main.py"],
      "cwd": "/path/to/fs-mcp",
      "env": {
        "SAFE_DIRECTORY": "/your/project/directory"
      }
    }
  }
}

๐Ÿ’ป ๅผ€ๅ‘

ๅผ€ๅ‘็Žฏๅขƒ่ฎพ็ฝฎ

# ๅ…‹้š†ไป“ๅบ“
git clone https://github.com/yourusername/fs-mcp.git
cd fs-mcp

# ๅฎ‰่ฃ…ๅผ€ๅ‘ไพ่ต–
uv sync --group dev

่ฟ่กŒๆต‹่ฏ•

# ่ฟ่กŒๆ‰€ๆœ‰ๆต‹่ฏ•
pytest

# ่ฟ่กŒ่ฆ†็›–็އๆต‹่ฏ•
pytest --cov=src

๐Ÿค ่ดก็Œฎ

ๆฌข่ฟŽ่ดก็Œฎไปฃ็ ๏ผ่ฏทๅ‚่€ƒ่‹ฑๆ–‡้ƒจๅˆ†็š„ Contributing ็ซ ่Š‚ไบ†่งฃ่ฏฆ็ป†ไฟกๆฏใ€‚

๐Ÿ“„ ่ฎธๅฏ่ฏ

ๆœฌ้กน็›ฎ้‡‡็”จ MIT ่ฎธๅฏ่ฏ - ่ฏฆ่ง LICENSE ๆ–‡ไปถใ€‚


Made with โค๏ธ for the AI community

โฌ† Back to top

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    F
    maintenance
    A Model Context Protocol server that provides secure and intelligent interaction with files and filesystems, offering smart context management and token-efficient operations for working with large files and complex directory structures.
    21
    67
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    A Model Context Protocol server that enhances AI agents by providing deep semantic understanding of codebases, enabling more intelligent interactions through advanced code search and contextual awareness.
    90
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server that provides AI assistants with direct access to local document collections through full-text search, supporting multiple formats and hierarchical collections.
    MIT