#
tokens: 741/50000 4/4 files
lines: on (toggle) GitHub
raw markdown copy reset
# Directory Structure

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

# Files

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

```
1 | # Qiniu Cloud Storage Configuration
2 | QINIU_ACCESS_KEY=your_access_key_here
3 | QINIU_SECRET_KEY=your_secret_key_here
4 | QINIU_BUCKET_NAME=your_bucket_name
5 | QINIU_DOMAIN=https://your.domain
6 | QINIU_UPLOAD_EXPIRES=3600
7 | 
```

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

```
 1 | # Python
 2 | __pycache__/
 3 | *.py[cod]
 4 | *$py.class
 5 | *.so
 6 | .Python
 7 | build/
 8 | develop-eggs/
 9 | dist/
10 | downloads/
11 | eggs/
12 | .eggs/
13 | lib/
14 | lib64/
15 | parts/
16 | sdist/
17 | var/
18 | wheels/
19 | *.egg-info/
20 | .installed.cfg
21 | *.egg
22 | MANIFEST
23 | 
24 | # Virtual Environment
25 | venv/
26 | ENV/
27 | 
28 | # Sensitive files
29 | config.py
30 | cline_config.json
31 | .env
32 | 
33 | # IDE
34 | .vscode/
35 | .idea/
36 | *.swp
37 | *.swo
38 | 
39 | # Logs
40 | *.log
41 | 
```

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

```
1 | fastmcp
2 | qiniu
3 | 
```

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

```python
 1 | from mcp.server.fastmcp import FastMCP
 2 | from qiniu import Auth, put_file
 3 | import config
 4 | import os
 5 | import uuid
 6 | 
 7 | # Initialize Qiniu Auth
 8 | q = Auth(config.QINIU_ACCESS_KEY, config.QINIU_SECRET_KEY)
 9 | 
10 | # Create MCP server
11 | mcp = FastMCP("qiniu-uploader")
12 | 
13 | @mcp.tool()
14 | def upload_file(file_path: str) -> str:
15 |     """Uploads a file to Qiniu and returns its public URL"""
16 |     if not os.path.exists(file_path):
17 |         raise ValueError(f"File not found: {file_path}")
18 | 
19 |     # Generate unique key
20 |     key = f"mcp-uploads/{uuid.uuid4()}{os.path.splitext(file_path)[1]}"
21 |     
22 |     # Generate upload token
23 |     token = q.upload_token(config.QINIU_BUCKET_NAME, key, config.QINIU_UPLOAD_EXPIRES)
24 | 
25 |     # Upload file
26 |     ret, info = put_file(token, key, file_path)
27 | 
28 |     if info.status_code == 200:
29 |         return f"{config.QINIU_DOMAIN}/{key}"
30 |     else:
31 |         raise Exception(f"Upload failed: {info}")
32 | 
33 | if __name__ == "__main__":
34 |     mcp.run()
35 | 
```