mcp-local-reader

mcp-local-reader

Transform any local file into AI-optimized markdown format for seamless integration with Claude Desktop, Claude Code, and other MCP clients.

Category
访问服务器

README

MCP-LOCAL-Reader

License: MIT Python 3.11+ FastMCP

中文版 | 日本語 | Français | Deutsch

AI-Ready Document Converter - Transform any local file into AI-optimized markdown format for seamless integration with Claude Desktop, Claude Code, and other MCP clients.

Intelligent Document Processing - High-performance local file content extraction with advanced parsing for PDF, Office documents, images, and more. Automatically converts complex documents into clean, structured markdown that AI models can easily understand and process.

Features

📄 AI-Optimized File Processing

  • PDF Documents: Advanced parsing with PyMuPDF4LLM → Clean markdown output
  • Office Suite: Word, Excel, PowerPoint → Structured tables and text
  • OpenDocument: ODT, ODS, ODP → Standardized markdown format
  • Text & Data: Markdown, JSON, CSV, EPUB → Enhanced AI readability
  • Images: OCR text recognition → Searchable markdown content
  • Archives: Smart extraction → Organized document collections

🚀 Intelligent Performance

  • Smart Caching: Remembers processed files for instant re-access
  • Lazy Loading: Only loads needed components - 80% faster startup
  • Concurrent Processing: Handles multiple files simultaneously
  • Resource Optimization: Prevents system overload with smart limits

🔒 Security & Control

  • Directory Permissions: Restrict access to specific directories
  • Path Validation: Secure file access with absolute path requirements
  • File Size Limits: Prevent DoS with configurable size restrictions
  • Local-First: No data leaves your machine - complete privacy

Quick Start

Prerequisites

Installation

Option 1: One-Command Setup (Recommended)

# Clone and auto-configure
git clone https://github.com/freefish1218/mcp-local-reader.git
cd mcp-local-reader
chmod +x install.sh && ./install.sh

The installer will guide you through three installation modes:

  1. Minimal: PDF and basic text files only (smallest footprint)
  2. Standard: Office documents support, no OCR (recommended)
  3. Complete: All features including OCR and archive processing

Option 2: Manual Installation

# Install uv package manager
curl -LsSf https://astral.sh/uv/install.sh | sh

# Setup project
git clone https://github.com/freefish1218/mcp-local-reader.git
cd mcp-local-reader
uv sync

# Configure environment
cp env.example .env
# Edit .env with your settings

# Start server
./start_mcp.sh

Configuration for Claude Desktop

Automatic Configuration

chmod +x configure_claude.sh && ./configure_claude.sh

Manual Configuration

Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or equivalent:

{
  "mcpServers": {
    "local-reader": {
      "command": "/absolute/path/to/mcp-local-reader/start_mcp.sh",
      "args": [],
      "env": {
        "LOCAL_FILE_ALLOWED_DIRECTORIES": "/Users/username/Documents,/Users/username/Downloads"
      }
    }
  }
}

Configuration for Claude Code

Add to .claude/claude_config.json:

{
  "mcpServers": {
    "local-reader": {
      "command": "/absolute/path/to/mcp-local-reader/start_mcp.sh",
      "args": [],
      "env": {
        "LOCAL_FILE_ALLOWED_DIRECTORIES": "/Users/username/Documents,/Users/username/Downloads"
      }
    }
  }
}

Usage

After setup, use these features directly in conversations:

📄 Read & Convert to AI-Ready Markdown

Transform any file into AI-optimized markdown format:

Read the content from /Users/username/Documents/report.pdf
→ Converts to clean markdown with tables, headings, and structure

Parse /Users/username/data.xlsx and show me the data structure  
→ Extracts spreadsheet data as markdown tables

Extract text from /Users/username/presentation.pptx
→ Organizes slides into structured markdown sections

🔄 Save as Markdown Files

Convert and save documents as AI-ready markdown files:

Convert /Users/username/contract.pdf to markdown format
→ Creates contract.pdf.md with structured content

Save /Users/username/analysis.xlsx as markdown in /Users/username/output/
→ Saves formatted tables and data as markdown

Configuration

Essential Settings (.env)

# File access control (REQUIRED)
LOCAL_FILE_ALLOWED_DIRECTORIES=/Users/username/Documents,/Users/username/Downloads

# Performance optimization
TOTAL_CACHE_SIZE_MB=500          # Unified cache limit
CACHE_EXPIRE_DAYS=30             # Cache retention
FILE_READER_MAX_FILE_SIZE_MB=20  # File size limit

# Logging
LOG_LEVEL=INFO

Optional OCR Settings

For image text recognition:

# Vision model for OCR
LLM_VISION_BASE_URL=https://api.openai.com/v1
LLM_VISION_API_KEY=sk-your-api-key-here
LLM_VISION_MODEL=gpt-4o  # or qwen-vl-plus

Environment Variables

Variable Required Default Description
LOCAL_FILE_ALLOWED_DIRECTORIES current_dir Comma-separated allowed directories
TOTAL_CACHE_SIZE_MB 500 Unified cache size limit
FILE_READER_MAX_FILE_SIZE_MB 20 Maximum file size
LOG_LEVEL INFO Logging level
LLM_VISION_API_KEY - OCR vision model API key

MCP Tools

read_local_file

Extract content from local files and return as AI-optimized markdown.

Parameter Type Description
file_path string Absolute path to the file
max_size number File size limit in MB (optional)

convert_local_file

Convert files to AI-ready markdown and save to filesystem.

Parameter Type Description
file_path string Absolute path to input file
output_path string Output path (optional, defaults to input+.md)
max_size number File size limit in MB (optional)
overwrite boolean Overwrite existing files (default: false)

Supported File Types

Document Formats

  • PDF: .pdf
  • Microsoft Office: .doc, .docx, .ppt, .pptx, .xls, .xlsx
  • OpenDocument: .odt, .ods, .odp
  • Text: .txt, .md, .rtf, .csv, .json, .xml

Image Formats (with OCR)

  • Common: .png, .jpg, .jpeg, .gif, .bmp, .tiff
  • Advanced: .webp, .svg

Archive Formats

  • Compressed: .zip, .tar, .tar.gz, .7z
  • Office: .docx, .xlsx, .pptx (internally zip-based)

Special Formats

  • E-books: .epub
  • Data: .csv, .tsv, .json

Architecture

Core Components

  • FileReader (src/file_reader/core.py): Main orchestrator for file content extraction
  • MCP Server (src/mcp_server.py): FastMCP-based server providing MCP tools
  • Parser System (src/file_reader/parsers/): Specialized parsers for different file types
  • Cache Manager (src/file_reader/cache_manager.py): Unified caching system
  • Storage Layer (src/file_reader/storage/): Secure local file access

Performance Optimizations

  1. Unified Caching: Single cache instance instead of multiple (reduced from ~6GB to 500MB default)
  2. Lazy Loading: Parsers loaded on-demand, not at startup
  3. Dependency Optimization: Optional dependencies for advanced features
  4. Resource Limits: Configurable memory and file size limits

Development

Setup Development Environment

git clone https://github.com/freefish1218/mcp-local-reader.git
cd mcp-local-reader
uv sync
source .venv/bin/activate  # On Unix/macOS

Running Tests

# Run all tests
uv run python tests/run_tests.py

# Specific test categories
uv run python tests/run_tests.py --models     # Data models
uv run python tests/run_tests.py --parsers    # File parsers
uv run python tests/run_tests.py --core       # Core functionality
uv run python tests/run_tests.py --server     # MCP server

# With coverage
uv run python tests/run_tests.py -c

# Alternative pytest usage
PYTHONPATH=src uv run pytest tests/ -v

Adding New Parsers

  1. Create parser in src/file_reader/parsers/
  2. Inherit from BaseParser
  3. Register in parser_loader.py
  4. Add tests in tests/test_parsers.py

See CONTRIBUTING.md for detailed development guidelines.

Performance Characteristics

  • Smart Caching: Instantly access previously processed files without re-conversion
  • Efficient Memory Use: Optimized from 6GB+ to 500MB default cache size
  • Lightning Startup: 80% faster startup with on-demand component loading
  • Parallel Processing: Handle multiple document conversions simultaneously

System Requirements

  • Python: 3.11+
  • OS: macOS, Linux, Windows
  • Memory: 2GB+ recommended for large files
  • Optional: LibreOffice (legacy Office files), Pandoc (special conversions)

FAQ

Q: Files not reading correctly?
A: Ensure LOCAL_FILE_ALLOWED_DIRECTORIES includes your file's directory.

Q: OCR not working for images?
A: Configure LLM_VISION_API_KEY with a valid vision model API key (OpenAI GPT-4o or compatible).

Q: Want to improve processing speed?
A: The smart cache automatically remembers processed files. Clear cache directory if you want fresh processing of all files.

Q: Legacy Office files (.doc/.ppt) failing?
A: Install LibreOffice: brew install --cask libreoffice (macOS) or equivalent for your OS.

Q: What file formats are supported?
A: PDF, Word, Excel, PowerPoint, OpenDocument, images (with OCR), archives, text files, and more.

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines on how to contribute to this project.

License

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

Links

Acknowledgments

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选