#
tokens: 532/50000 4/4 files
lines: off (toggle) GitHub
raw markdown copy
# Directory Structure

```
├── .DS_Store
├── .env.example
├── .gitignore
├── README.md
├── requirements.txt
└── server.py
```

# Files

--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------

```
# Qiniu Cloud Storage Configuration
QINIU_ACCESS_KEY=your_access_key_here
QINIU_SECRET_KEY=your_secret_key_here
QINIU_BUCKET_NAME=your_bucket_name
QINIU_DOMAIN=https://your.domain
QINIU_UPLOAD_EXPIRES=3600

```

--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------

```
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Virtual Environment
venv/
ENV/

# Sensitive files
config.py
cline_config.json
.env

# IDE
.vscode/
.idea/
*.swp
*.swo

# Logs
*.log

```

--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------

```
fastmcp
qiniu

```

--------------------------------------------------------------------------------
/server.py:
--------------------------------------------------------------------------------

```python
from mcp.server.fastmcp import FastMCP
from qiniu import Auth, put_file
import config
import os
import uuid

# Initialize Qiniu Auth
q = Auth(config.QINIU_ACCESS_KEY, config.QINIU_SECRET_KEY)

# Create MCP server
mcp = FastMCP("qiniu-uploader")

@mcp.tool()
def upload_file(file_path: str) -> str:
    """Uploads a file to Qiniu and returns its public URL"""
    if not os.path.exists(file_path):
        raise ValueError(f"File not found: {file_path}")

    # Generate unique key
    key = f"mcp-uploads/{uuid.uuid4()}{os.path.splitext(file_path)[1]}"
    
    # Generate upload token
    token = q.upload_token(config.QINIU_BUCKET_NAME, key, config.QINIU_UPLOAD_EXPIRES)

    # Upload file
    ret, info = put_file(token, key, file_path)

    if info.status_code == 200:
        return f"{config.QINIU_DOMAIN}/{key}"
    else:
        raise Exception(f"Upload failed: {info}")

if __name__ == "__main__":
    mcp.run()

```