r2-upload-mcp-server

leonho/r2-upload-mcp-server

3.3

If you are the rightful owner of r2-upload-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A Model Context Protocol (MCP) server designed for uploading files to Cloudflare R2 storage.

Tools
1
Resources
0
Prompts
0

R2 Upload MCP Server

A Model Context Protocol (MCP) server for uploading files to Cloudflare R2 storage.

Features

  • Upload files to R2 bucket with automatic MIME type detection
  • Support for custom object keys and content types
  • Returns public URLs for uploaded files
  • Environment variable configuration

Installation

cd apps/r2-upload
pnpm install
pnpm build

Configuration

The server automatically configures itself from environment variables. Set the following required environment variables:

Required Environment Variables

  • R2_ACCOUNT_ID: Your Cloudflare account ID
  • R2_ACCESS_KEY_ID: R2 API access key ID
  • R2_SECRET_ACCESS_KEY: R2 API secret access key
  • R2_BUCKET_NAME: Name of your R2 bucket

Optional Environment Variables

  • R2_ENDPOINT: Custom endpoint URL (defaults to https://{accountId}.r2.cloudflarestorage.com)
  • R2_CUSTOM_DOMAIN: Custom domain for public file URLs (defaults to R2 dev domain)

Getting R2 Credentials

  1. Log in to Cloudflare Dashboard
  2. Go to R2 Object Storage
  3. Create an R2 bucket if you haven't already
  4. Go to "Manage R2 API tokens"
  5. Create a new API token with read/write permissions for your bucket
  6. Note down the Access Key ID and Secret Access Key

Tools

upload_file

Upload a file to the configured R2 bucket.

Parameters:

  • filePath (required): Local file path to upload
  • key (optional): Object key/name in the bucket (defaults to filename)
  • contentType (optional): MIME type of the file (auto-detected if not provided)

Usage Example

Once environment variables are configured, you can upload files directly:

{
  "filePath": "/path/to/your/file.jpg",
  "key": "uploads/my-image.jpg"
}

Supported File Types

The server automatically detects MIME types for common file extensions:

  • Images: .jpg, .jpeg, .png, .gif, .webp
  • Documents: .pdf, .txt, .json, .html, .css
  • Scripts: .js
  • Videos: .mp4, .mov, .avi
  • Audio: .mp3, .wav

For other file types, it defaults to application/octet-stream or you can specify a custom contentType.

MCP Configuration

Add this to your mcp.json configuration file:

{
  "mcpServers": {
    "r2-upload": {
      "command": "node",
      "args": ["./apps/r2-upload/dist/index.js"],
      "env": {
        "R2_ACCOUNT_ID": "your-cloudflare-account-id",
        "R2_ACCESS_KEY_ID": "your-r2-access-key-id", 
        "R2_SECRET_ACCESS_KEY": "your-r2-secret-access-key",
        "R2_BUCKET_NAME": "your-bucket-name",
        "R2_ENDPOINT": "https://your-account-id.r2.cloudflarestorage.com",
        "R2_CUSTOM_DOMAIN": "files.yourdomain.com"
      }
    }
  }
}

Environment Variables

Configure the server by setting these environment variables in your MCP configuration. If all required environment variables are set, the server will be ready to upload files immediately.

Custom Domain Setup

If you have a custom domain configured for your R2 bucket (e.g., files.yourdomain.com), set the R2_CUSTOM_DOMAIN environment variable. The server will return public URLs using your custom domain instead of the default R2 development domain.

Running the Server

# Build first
pnpm build

# Run standalone
pnpm start

The server runs as a stdio MCP server and communicates via stdin/stdout.