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

A
license - permissive license
-
quality - not tested
D
maintenance

Maintenance

–Maintainers
–Response time
–Release cycle
–Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

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/boleyn/fs-mcp-server'

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