File Server MCP

File Server MCP

A hybrid REST + MCP file server for managing files with large file streaming support, enabling AI agents and web frontends to perform file operations via MCP tools and REST APIs.

Category
访问服务器

README

File Server MCP

A hybrid REST + MCP file server built with Python, FastMCP, and UV. Provides both REST API endpoints (for web frontends) and MCP tools (for AI agents) to manage files with support for large file streaming.

Features

  • Hybrid Interface: Both REST API and MCP tools for maximum flexibility
  • Large File Support: Streaming downloads with no size limits
  • Type Safety: Full Pydantic validation across all interfaces
  • Security: Path traversal prevention and configurable size limits
  • Async I/O: Efficient file operations with aiofiles
  • Easy Configuration: Environment-based settings

Architecture

MCP Tools (for AI Agents)

  • list_files_tool: List all files with metadata
  • get_file_info_tool: Get detailed file information
  • get_file_download_link_tool: Get REST API download URL for large files
  • create_file_tool: Create new files (text or base64 binary, 100MB limit)
  • delete_file_tool: Delete files
  • replace_file_tool: Replace file content (text or base64 binary, 100MB limit)

REST API Endpoints

  • GET /api/files: List all files
  • GET /api/files/{filename}: Get file metadata
  • GET /api/files/{filename}/download: Download file (streaming, no size limit)
  • DELETE /api/files/{filename}: Delete file

Utility Endpoints

  • GET /: API information
  • GET /health: Health check
  • GET /docs: OpenAPI documentation

Installation

Prerequisites

  • Python 3.11 or higher
  • UV package manager

Install UV

# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

Setup Project

# Clone or navigate to the project directory
cd file-server-mcp

# Install dependencies
uv sync

# Optional: Install development dependencies
uv sync --extra dev

Configuration

Create a .env file in the project root (see .env.example):

FILE_SERVER_FILE_STORAGE_DIR=./file_storage
FILE_SERVER_MAX_UPLOAD_SIZE=104857600  # 100MB
FILE_SERVER_CHUNK_SIZE=1048576         # 1MB

Environment Variables

  • FILE_SERVER_FILE_STORAGE_DIR: Directory for file storage (default: ./file_storage)
  • FILE_SERVER_MAX_UPLOAD_SIZE: Maximum file size for uploads via MCP tools in bytes (default: 100MB)
  • FILE_SERVER_CHUNK_SIZE: Chunk size for streaming downloads in bytes (default: 1MB)

Usage

Start the Server

# Run with UV
uv run python -m file_server_mcp

# Or with uvicorn directly
uv run uvicorn file_server_mcp.server:app --host 0.0.0.0 --port 8000 --reload

The server will start on http://localhost:8000.

REST API Examples

# List all files
curl http://localhost:8000/api/files

# Get file info
curl http://localhost:8000/api/files/example.txt

# Download file
curl http://localhost:8000/api/files/example.txt/download -o downloaded.txt

# Delete file
curl -X DELETE http://localhost:8000/api/files/example.txt

# Health check
curl http://localhost:8000/health

# View OpenAPI docs
# Open http://localhost:8000/docs in your browser

MCP Integration

Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "file-server": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/file-server-mcp",
        "run",
        "python",
        "-m",
        "file_server_mcp"
      ],
      "env": {
        "FILE_SERVER_FILE_STORAGE_DIR": "/path/to/storage"
      }
    }
  }
}

MCP Inspector

# Install MCP Inspector
npm install -g @modelcontextprotocol/inspector

# Run the server with inspector
mcp-inspector uv --directory /path/to/file-server-mcp run python -m file_server_mcp

Using MCP Tools

Once configured with Claude Desktop, you can ask Claude to:

"List all files in the file server"
"Get information about report.pdf"
"Create a new file called notes.txt with content 'Hello World'"
"Get a download link for large-video.mp4"
"Delete old-file.txt"
"Replace the content of config.json"

Development

Run Tests

# Run all tests
uv run pytest

# Run with coverage
uv run pytest --cov=file_server_mcp --cov-report=html

# Run specific test file
uv run pytest tests/test_storage.py

# Run with verbose output
uv run pytest -v

Project Structure

file-server-mcp/
├── .python-version          # Python version
├── pyproject.toml           # UV configuration and dependencies
├── uv.lock                  # Auto-generated lockfile
├── .env.example             # Environment variable template
├── README.md                # This file
├── src/
│   └── file_server_mcp/
│       ├── __init__.py      # Package initialization
│       ├── __main__.py      # Entry point
│       ├── config.py        # Environment configuration
│       ├── models.py        # Pydantic schemas
│       ├── storage.py       # File operations
│       ├── rest_routes.py   # FastAPI REST endpoints
│       ├── mcp_tools.py     # MCP tool definitions
│       └── server.py        # Main hybrid server
└── tests/
    ├── __init__.py
    ├── conftest.py          # Pytest fixtures
    ├── test_storage.py      # Storage layer tests
    ├── test_rest_routes.py  # REST API tests
    └── test_mcp_tools.py    # MCP tools tests

Large File Handling

Strategy

  • REST Downloads: Use streaming with aiofiles and StreamingResponse (no size limit)
  • MCP Tools:
    • Direct content transfer limited to 100MB (configurable)
    • For larger files, use get_file_download_link_tool to get REST URL
    • AI agents can fetch large files via the REST endpoint

Example: Handling Large PDFs

# For small files (< 100MB), use MCP tool directly
create_file_tool(filename="small.pdf", content=base64_content, encoding="base64")

# For large files, use download link
link = get_file_download_link_tool(filename="large.pdf")
# Returns: {"filename": "large.pdf", "download_url": "/api/files/large.pdf/download"}
# Fetch via REST API using the download_url

Security

Path Traversal Prevention

All filenames are sanitized to prevent directory traversal attacks:

# Input: "../../etc/passwd"
# Sanitized to: "passwd"
# Saved in: <storage_dir>/passwd

Authentication

This is a prototype server without authentication. For production use:

  • Add authentication middleware (e.g., API keys, OAuth)
  • Implement authorization for file operations
  • Use HTTPS for transport security
  • Consider rate limiting

Troubleshooting

Server won't start

# Check Python version
python --version  # Should be 3.11+

# Reinstall dependencies
uv sync --reinstall

# Check storage directory permissions
ls -la ./file_storage

MCP tools not appearing in Claude Desktop

  1. Check claude_desktop_config.json is valid JSON
  2. Verify the command path is absolute
  3. Check Claude Desktop logs (Help → View Logs)
  4. Restart Claude Desktop after config changes

Tests failing

# Clear pytest cache
rm -rf .pytest_cache

# Run tests with verbose output
uv run pytest -vv

# Run a single test
uv run pytest tests/test_storage.py::test_sanitize_filename -v

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选