Skip to main content

MCP S3 File Uploader - A Model Context Protocol server for S3 uploads

Project description

MCP S3 File Uploader (mcp-s3)

A Model Context Protocol (MCP) server that provides secure file upload functionality to Amazon S3 with progress tracking and presigned URL generation.

๐Ÿš€ Features

  • Secure S3 Upload: Upload files to AWS S3 with automatic UUID-based naming
  • Progress Tracking: Real-time upload progress for large files (>100MB uses multipart upload)
  • Presigned URLs: Generate time-limited access URLs for uploaded files
  • Path Security: Prevents directory traversal attacks with safe path joining
  • Environment Configuration: Supports both CLI arguments and .env file configuration
  • FastMCP Integration: Built with FastMCP framework for optimal MCP compatibility
  • Modern Python Support: Full support for uv and uvx package managers
  • Multiple Execution Methods: Run with traditional Python, uv, uvx, or direct script execution

๐Ÿ“‹ Prerequisites

  • Python 3.10+
  • AWS account with S3 access
  • Valid AWS credentials (Access Key ID and Secret Access Key)
  • An S3 bucket for file storage

โšก Quick Start

1. Choose Your Installation Method

Method 1: Using uv (Recommended)

# Install dependencies and run
uv run python mcp_s3.py --root ~/mcp-uploads

# Or install the package and use the script
uv pip install -e .
uv run mcp-s3 --root ~/mcp-uploads

Method 2: Using uvx (Isolated Environment)

# Run directly from current directory
uvx --from . mcp-s3 --root ~/mcp-uploads

# Or if published to PyPI
uvx mcp-s3 --root ~/mcp-uploads

Method 3: Traditional Python

# With conda environment
conda activate your-env
python mcp_s3.py --root ~/mcp-uploads

# With pip/venv
pip install -r requirements.txt
python mcp_s3.py --root ~/mcp-uploads

Method 4: Direct Script Execution

# Make executable and run
chmod +x mcp_s3.py
./mcp_s3.py --root ~/mcp-uploads

2. Configure AWS Credentials

Create a .env file in the project root:

# AWS Credentials
AWS_ACCESS_KEY_ID=your_access_key_here
AWS_SECRET_ACCESS_KEY=your_secret_key_here
AWS_DEFAULT_REGION=us-east-1

# S3 Configuration
S3_BUCKET_NAME=your_bucket_name_here

3. Test Your Setup

# Test AWS connection
python test_aws_connection.py

# Or with uv
uv run python test_aws_connection.py

4. Run the MCP Server

# Basic usage (recommended)
uv run python mcp_s3.py --root ~/mcp-uploads

# With custom bucket
uv run python mcp_s3.py --root ~/mcp-uploads --bucket my-custom-bucket

# Using uvx for isolation
uvx --from . mcp-s3 --root ~/mcp-uploads

# Traditional Python
python mcp_s3.py --root ~/mcp-uploads

๐Ÿ”ง MCP Integration

Cursor IDE Setup

Using uv (Recommended)

Add this configuration to your ~/.cursor/mcp.json:

{
  "mcpServers": {
    "mcp-s3": {
      "command": "uv",
      "args": ["run", "python", "/path/to/mcp_s3.py", "--root", "/path/to/uploads"],
      "env": {
        "AWS_ACCESS_KEY_ID": "your_access_key",
        "AWS_SECRET_ACCESS_KEY": "your_secret_key",
        "AWS_DEFAULT_REGION": "us-east-1",
        "S3_BUCKET_NAME": "your_bucket_name"
      }
    }
  }
}

Using uvx (Isolated Environment)

{
  "mcpServers": {
    "mcp-s3": {
      "command": "uvx",
      "args": ["--from", "/path/to/project", "python", "mcp_s3.py", "--root", "/path/to/uploads"],
      "env": {
        "AWS_ACCESS_KEY_ID": "your_access_key",
        "AWS_SECRET_ACCESS_KEY": "your_secret_key",
        "S3_BUCKET_NAME": "your_bucket_name"
      }
    }
  }
}

Traditional Python

{
  "mcpServers": {
    "mcp-s3": {
      "transport": "stdio",
      "command": "/path/to/python",
      "args": [
        "/path/to/mcp_s3.py",
        "--root",
        "/path/to/upload/directory"
      ],
      "env": {
        "AWS_ACCESS_KEY_ID": "your_access_key",
        "AWS_SECRET_ACCESS_KEY": "your_secret_key",
        "AWS_DEFAULT_REGION": "us-east-1",
        "S3_BUCKET_NAME": "your_bucket_name"
      }
    }
  }
}

Claude Desktop Setup

Add to your Claude Desktop MCP configuration:

{
  "mcpServers": {
    "s3-uploader": {
      "command": "python",
      "args": [
        "/path/to/mcp_s3.py",
        "--bucket", "your-bucket-name",
        "--root", "/path/to/uploads"
      ]
    }
  }
}

๐Ÿ› ๏ธ Available Tools

upload_file

Upload a local file to S3 and return a presigned URL.

Parameters:

  • local_path (string, required): Path to the file relative to the configured root directory
  • expires_in (integer, optional): URL expiration time in seconds (default: 86400 = 24 hours)

Returns:

  • url: Presigned URL for accessing the uploaded file
  • size: File size in bytes
  • mime_type: Detected MIME type of the file
  • s3_key: Generated S3 object key (UUID + file extension)

Example Usage in MCP Client:

@mcp-s3 upload the document.pdf file with 2-hour expiration

๐Ÿ“ File Structure

mcp-s3/
โ”œโ”€โ”€ mcp_s3.py                   # Main MCP server
โ”œโ”€โ”€ pyproject.toml              # Modern Python project configuration
โ”œโ”€โ”€ requirements.txt            # Python dependencies (legacy)
โ”œโ”€โ”€ __main__.py                 # Module entry point
โ”œโ”€โ”€ test_aws_connection.py      # AWS credentials tester
โ”œโ”€โ”€ test_mcp_server.py          # MCP server functionality test
โ”œโ”€โ”€ test_with_progress.py       # Progress tracking test
โ”œโ”€โ”€ test_execution_methods.py   # Test all execution methods
โ”œโ”€โ”€ generate_mcp_config.py      # Generate Cursor MCP config
โ”œโ”€โ”€ setup_s3_bucket.py          # S3 bucket setup script
โ”œโ”€โ”€ .env                        # AWS credentials (create from env_example.txt)
โ”œโ”€โ”€ env_example.txt             # Environment variables template
โ”œโ”€โ”€ USAGE.md                    # Detailed usage guide
โ”œโ”€โ”€ AWS_SETUP_GUIDE.md          # AWS setup instructions
โ””โ”€โ”€ README.md                   # This file

๐Ÿ”’ Security Features

  • Path Traversal Protection: Prevents access to files outside the configured root directory
  • Presigned URLs: Time-limited access to uploaded files without exposing AWS credentials
  • Environment Variables: Sensitive credentials stored in .env file (not committed to git)
  • UUID File Naming: Prevents filename collisions and adds obscurity

๐Ÿ“Š Progress Tracking

  • Small Files (<100MB): Progress reported at key milestones (0%, 25%, 90%, 100%)
  • Large Files (โ‰ฅ100MB): Multipart upload with detailed progress per chunk
  • Real-time Updates: MCP clients receive progress notifications during upload

๐Ÿงช Testing

Test AWS Connection

# Traditional Python
python test_aws_connection.py

# With uv
uv run python test_aws_connection.py

Test MCP Server

# Traditional Python
python test_mcp_server.py

# With uv
uv run python test_mcp_server.py

Test with Progress Tracking

# Traditional Python
python test_with_progress.py

# With uv
uv run python test_with_progress.py

Test All Execution Methods

# Verify all installation methods work
python test_execution_methods.py

๐Ÿšจ Troubleshooting

Common Issues

  1. Missing Dependencies

    # With uv
    uv sync  # Install all dependencies
    
    # Traditional pip
    pip install -r requirements.txt
    
  2. "Missing required environment variables"

    • Ensure your .env file exists and contains all required AWS credentials
    • Check your .env file format matches the example
  3. AWS Credentials Not Found

    • Check your .env file
    • Verify AWS CLI configuration: aws configure list
    • Ensure environment variables are properly loaded
  4. "File not found"

    • Check that the file exists in the configured root directory
    • Verify the file path is relative to the root directory
  5. "Access denied to bucket"

    • Verify your AWS credentials have S3 permissions
    • Ensure the bucket name is correct and exists
    • Check S3 bucket policies and IAM permissions
  6. "Path escapes allowed root"

    • File path must be within the configured root directory
    • Use relative paths only (no ../ traversal)
  7. Permission Denied

    • Ensure the upload directory exists and is writable
    • Check file system permissions
  8. Port Already in Use

    • The server uses stdio transport, no port conflicts should occur
    • If using a different transport, check for port conflicts

๐Ÿ“ Configuration Options

CLI Arguments

  • --bucket: S3 bucket name (overrides environment variable)
  • --root: Root directory for file uploads (required)

Environment Variables

  • AWS_ACCESS_KEY_ID: AWS access key
  • AWS_SECRET_ACCESS_KEY: AWS secret access key
  • AWS_DEFAULT_REGION: AWS region (default: us-east-1)
  • S3_BUCKET_NAME: Target S3 bucket name

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test with python test_mcp_server.py
  5. Submit a pull request

๐Ÿ“„ License

This project is open source. Please ensure you comply with AWS terms of service when using S3.

๐Ÿ“š Additional Resources


Built with โค๏ธ using FastMCP for seamless LLM integration

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

mcp_s3-1.0.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

mcp_s3-1.0.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file mcp_s3-1.0.0.tar.gz.

File metadata

  • Download URL: mcp_s3-1.0.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for mcp_s3-1.0.0.tar.gz
Algorithm Hash digest
SHA256 dcdab044e09214506d53dcfeaf64b8974bd0b5ecb69d840b234868ed499a5269
MD5 9773316f72d9090e0c0e2f72cc8d6b83
BLAKE2b-256 8cb842d6006beda9fb96568808dbe3f9b40fd39cfc4e9db599413035472b767b

See more details on using hashes here.

File details

Details for the file mcp_s3-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_s3-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for mcp_s3-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53c6f2ead0be9492feb1e26f910f50218385ef7113824141c54da79dba6f4720
MD5 d7c4c33c57dad84e7621e69ad50a4ef4
BLAKE2b-256 9af39f6ea7258136d9492e9d514b76be1bed2987eb006b9f088e48b525433b00

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