跳到内容

RustFS MCP

RustFS MCP 服务器是一个高性能的 模型上下文协议 (MCP) 服务器,可为 AI/LLM 工具提供对 S3 兼容对象存储操作的无缝访问。它采用 Rust 构建,注重性能和安全性,使 Claude Desktop 等 AI 助手能够通过标准化协议与云存储进行交互。

什么是 MCP?

模型上下文协议 (Model Context Protocol) 是一项开放标准,使 AI 应用程序能够与外部系统建立安全、受控的连接。该服务器充当 AI 工具和 S3 兼容存储服务之间的桥梁,提供对文件操作的结构化访问,同时维护安全性和可观察性。

✨ 特性

支持的 S3 操作

  • 列出存储桶 (List Buckets):列出所有可访问的 S3 存储桶。
  • 列出对象 (List Objects):浏览存储桶内容,支持可选的前缀过滤。
  • 上传文件 (Upload Files):上传本地文件,支持自动 MIME 类型检测和缓存控制。
  • 获取对象 (Get Objects):从 S3 存储检索对象,支持读取或下载模式。

🔧 安装

先决条件

  • Rust 1.75+ (用于从源码构建)
  • 已配置的 AWS 凭证 (通过环境变量、AWS CLI 或 IAM 角色)
  • 可访问 S3 兼容的存储服务

从源码构建

bash
# Clone the repository
git clone https://github.com/rustfs/rustfs.git
cd rustfs

# Build the MCP server
cargo build --release -p rustfs-mcp

# Binary will be available at
./target/release/rustfs-mcp

⚙️ 配置

环境变量

bash
# AWS credentials (required)
export AWS_ACCESS_KEY_ID=your_access_key
export AWS_SECRET_ACCESS_KEY=your_secret_key
export AWS_REGION=us-east-1  # optional, defaults to us-east-1

# Optional: Custom S3 endpoint (for MinIO, etc.)
export AWS_ENDPOINT_URL=https://:9000

# Log level (optional)
export RUST_LOG=info

命令行选项

bash
rustfs-mcp --help

服务器支持各种命令行选项来定制行为

  • --access-key-id:用于 S3 身份验证的 AWS 访问密钥 ID
  • --secret-access-key:用于 S3 身份验证的 AWS 秘密密钥
  • --region:用于 S3 操作的 AWS 区域 (默认: us-east-1)
  • --endpoint-url:自定义 S3 端点 URL (适用于 MinIO, LocalStack 等)
  • --log-level:日志级别配置 (默认: rustfs_mcp_server=info)

🚀 使用

启动服务器

bash
# Start the MCP server
rustfs-mcp

# Or with custom options
rustfs-mcp --log-level debug --region us-west-2

与聊天客户端集成

选项 1:使用命令行参数

json
{
  "mcpServers": {
    "rustfs-mcp": {
      "command": "/path/to/rustfs-mcp",
      "args": [
        "--access-key-id", "your_access_key",
        "--secret-access-key", "your_secret_key",
        "--region", "us-west-2",
        "--log-level", "info"
      ]
    }
  }
}

选项 2:使用环境变量

json
{
  "mcpServers": {
    "rustfs-mcp": {
      "command": "/path/to/rustfs-mcp",
      "env": {
        "AWS_ACCESS_KEY_ID": "your_access_key",
        "AWS_SECRET_ACCESS_KEY": "your_secret_key",
        "AWS_REGION": "us-east-1"
      }
    }
  }
}

使用 Docker

RustFS MCP 官方提供了一个 Dockerfile,可用于构建 RustFS MCP 的容器镜像。

bash
# Clone RustFS repository code
git clone git@github.com:rustfs/rustfs.git

# Build Docker image
docker build -f crates/mcp/Dockerfile -t rustfs/rustfs-mcp .

成功构建后,您可以在 AI IDE 的 MCP 配置中进行配置。

在 AI IDE 中配置 MCP

目前,Cursor、Windsurf、Trae 等主流 AI IDE 都支持 MCP。例如,在 Trae 中,将以下内容添加到 MCP 配置中 (MCP --> 添加)

json
{
  "mcpServers": {
    "rustfs-mcp": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-e",
        "AWS_ACCESS_KEY_ID",
        "-e",
        "AWS_SECRET_ACCESS_KEY",
        "-e",
        "AWS_REGION",
        "-e",
        "AWS_ENDPOINT_URL",
        "rustfs/rustfs-mcp"
      ],
      "env": {
        "AWS_ACCESS_KEY_ID": "rustfs_access_key",
        "AWS_SECRET_ACCESS_KEY": "rustfs_secret_key",
        "AWS_REGION": "cn-east-1",
        "AWS_ENDPOINT_URL": "rustfs_instance_url"
      }
    }
  }
}

AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEY 是 RustFS 访问密钥。您可以参考访问密钥管理章节进行创建。

如果添加成功,您可以在 MCP 配置页面上查看可用的工具

add rustfs mcp in trae mcp configuration successfully

在 Trae 中,您可以通过输入相应的提示来使用相应的工具。例如,在 Trae 的聊天对话框中,输入

Please help me list the buckets in the current rustfs instance, thank you!

将返回以下响应

list rustfs bucket with rustfs mcp

Trae 使用 Builder with MCP 模式,调用 list_buckets 工具来列出配置的 RustFS 实例中的所有存储桶。调用其他工具也类似。

🛠️ 可用工具

MCP 服务器公开了以下供 AI 助手使用的工具

list_buckets

列出使用配置凭证可访问的所有 S3 存储桶。

参数:无

list_objects

列出 S3 存储桶中的对象,支持可选的前缀过滤。

参数:

  • bucket_name (string):S3 存储桶的名称
  • prefix (string, optional):用于过滤对象的名称

upload_file

将本地文件上传到 S3,支持自动 MIME 类型检测。

参数:

  • local_file_path (string):本地文件路径
  • bucket_name (string):目标 S3 存储桶
  • object_key (string):S3 对象键 (目标路径)
  • content_type (string, optional):内容类型 (如果未提供,则自动检测)
  • storage_class (string, optional):S3 存储类别
  • cache_control (string, optional):缓存控制头

get_object

从 S3 检索对象,支持两种操作模式:直接读取内容或下载到文件。

参数:

  • bucket_name (string):源 S3 存储桶
  • object_key (string):S3 对象键
  • version_id (string, optional):版本化对象的版本 ID
  • mode (string, optional):操作模式 - "read" (默认) 直接返回内容,"download" 保存到本地文件
  • local_path (string, optional):本地文件路径 (当模式为 "download" 时必需)
  • max_content_size (number, optional):读取模式下的最大内容大小 (字节,默认: 1MB)

create_bucket

创建新的 RustFS 存储桶。

参数:

  • bucket_name (string):要创建的存储桶的名称。

delete_bucket

删除指定的 RustFS 存储桶。

参数:

  • bucket_name (string):要删除的存储桶的名称。

架构

MCP 服务器采用模块化架构构建

rustfs-mcp/
├── src/
│   ├── main.rs          # Entry point, CLI parsing and server initialization
│   ├── server.rs        # MCP server implementation and tool handlers
│   ├── s3_client.rs     # S3 client wrapper with async operations
│   ├── config.rs        # Configuration management and CLI options
│   └── lib.rs           # Library exports and public API
└── Cargo.toml           # Dependencies, metadata and binary configuration

根据 Apache 许可证 2.0 发布。