R2 Upload MCP Server
About
It is a Model Context Protocol (MCP) server for uploading files to Cloudflare R2 storage with automatic MIME type detection and environment variable configuration. It is intended for developers who want to integrate file uploads into MCP‑compatible AI tools.
Details
- Author
- leonho
- GitHub stars
- 1
- Downloads
- 411
- Categories
- Other
Jump to
- Upload files to R2 bucket with automatic MIME detection
- Support custom object keys and content types
- Returns public URLs for uploaded files
- Environment variable configuration
- Optional custom domain for public URLs
Install via pnpm install and pnpm build. Set the required environment variables (R2_ACCOUNT_ID, R2_ACCESS_KEY_ID, R2_SECRET_ACCESS_KEY, R2_BUCKET_NAME) in your MCP configuration file. The server exposes the upload_file tool, which accepts a filePath (required) and optional key and contentType parameters.
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
```bash
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.



