Skip to main content

A simple MCP server for downloading files from URLs

Project description

File Downloader MCP Server

一个简单而强大的文件下载MCP(Model Context Protocol)服务器,支持从URL下载文件到指定目录并自定义文件名。

功能特性

  • 🌐 支持HTTP/HTTPS URL下载
  • 📁 自定义保存目录
  • 📝 自定义文件名
  • 🔄 自动创建目录
  • 📊 显示下载进度和文件信息
  • 🛡️ 错误处理和重试机制
  • 📋 自动文件类型检测
  • 🔒 文件名冲突处理

安装

使用uv(推荐)

# 克隆或创建项目
cd file-downloader-mcp

# 安装依赖
uv sync

# 运行服务器
uv run file-downloader-mcp

开发模式

# 开发模式运行(支持热重载)
uv run python -m file_downloader_mcp.server

# 或者直接运行
uv run src/file_downloader_mcp/server.py

MCP客户端配置

Claude Desktop配置

在Claude Desktop的配置文件中添加:

{
  "mcpServers": {
    "file-downloader": {
      "command": "uv",
      "args": ["run", "file-downloader-mcp"],
      "cwd": "/path/to/file-downloader-mcp"
    }
  }
}

Cursor IDE配置

.cursor/mcp.json中添加:

{
  "mcpServers": {
    "file-downloader": {
      "command": "uv",
      "args": ["run", "file-downloader-mcp"],
      "cwd": "/path/to/file-downloader-mcp"
    }
  }
}

使用方法

工具:download_file

下载文件的主要工具,支持以下参数:

参数

  • url (必需): 要下载的文件URL
  • save_path (可选): 保存目录路径,默认为./downloads
  • filename (可选): 自定义文件名,默认从URL提取

使用示例

  1. 基本下载
{
  "url": "https://example.com/image.jpg"
}
  1. 指定保存目录
{
  "url": "https://example.com/document.pdf",
  "save_path": "/Users/username/Downloads"
}
  1. 自定义文件名
{
  "url": "https://example.com/file.zip",
  "save_path": "./my_files",
  "filename": "custom_name.zip"
}
  1. 完整参数示例
{
  "url": "https://github.com/user/repo/archive/main.zip",
  "save_path": "./projects",
  "filename": "repo_backup.zip"
}

特性说明

自动文件类型检测

服务器会根据HTTP响应的Content-Type自动为文件添加合适的扩展名:

  • image/jpeg.jpg
  • image/png.png
  • application/pdf.pdf
  • application/zip.zip
  • 等等...

文件名冲突处理

如果目标文件已存在,会自动添加数字后缀:

  • file.txtfile_1.txt
  • image.jpgimage_1.jpg

错误处理

  • 网络错误自动重试
  • 无效URL检测
  • 权限错误提示
  • HTTP状态码错误处理

开发

项目结构

file-downloader-mcp/
├── pyproject.toml          # 项目配置
├── README.md              # 说明文档
├── src/
│   └── file_downloader_mcp/
│       ├── __init__.py    # 包初始化
│       └── server.py      # 主服务器代码
└── tests/                 # 测试文件(可选)

运行测试

uv run pytest

代码格式化

uv run ruff format .
uv run ruff check .

许可证

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

file_downloader_mcp-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

file_downloader_mcp-0.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file file_downloader_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: file_downloader_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.4

File hashes

Hashes for file_downloader_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4b23b84d6545d2a2646691d18ac6c27666ff40ef3ea197736b99362c1a71c884
MD5 70ca75f7d94444d92c405c0a2e1bc9eb
BLAKE2b-256 cf96ec005700c0ff5ab5c77ce13a58ff4f2df3134c28859d9c66d0ae7acf9e41

See more details on using hashes here.

File details

Details for the file file_downloader_mcp-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for file_downloader_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92e37e927f9ce5655c9be4028215ad5437ee80cb34d52b25d3ece5485e085ed4
MD5 7e86529993880e2ddea7e2cf50eb4bec
BLAKE2b-256 cb715a4d6cb032c1a4d49d9b653cfb995fb61c17801fcff354ce87272d996029

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page