mcp-cos-upload 1.0.3 β 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +208 -26
- package/package.json +2 -1
- package/src/cos.js +3 -0
package/README.md
CHANGED
|
@@ -1,23 +1,61 @@
|
|
|
1
1
|
# mcp-cos-upload
|
|
2
2
|
|
|
3
|
-
MCP server for uploading files to Tencent Cloud COS. Supports uploading from URL (e.g., Figma export) or text content.
|
|
3
|
+
MCP server for uploading files to Tencent Cloud COS. Supports uploading from URL (e.g., Figma export), local file path, or text content.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- π **Multiple upload sources** - URL, local file, or text content
|
|
8
|
+
- ποΈ **Smart image compression** - PNG, JPEG, WebP, GIF, SVG auto-optimization
|
|
9
|
+
- π **Auto-organized storage** - Files stored by date folders with random suffix
|
|
10
|
+
- π **CDN support** - Returns CDN URL for fast access
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## For Team Members (Users)
|
|
15
|
+
|
|
16
|
+
### Quick Start
|
|
17
|
+
|
|
18
|
+
#### Method 1: Project `.env` File (Recommended)
|
|
19
|
+
|
|
20
|
+
Create a `.env` file in your project root:
|
|
6
21
|
|
|
7
22
|
```bash
|
|
8
|
-
|
|
23
|
+
cp node_modules/mcp-cos-upload/.env.example .env
|
|
24
|
+
# Or create manually:
|
|
9
25
|
```
|
|
10
26
|
|
|
11
|
-
|
|
27
|
+
```env
|
|
28
|
+
COS_SECRET_ID=your_secret_id
|
|
29
|
+
COS_SECRET_KEY=your_secret_key
|
|
30
|
+
COS_DEFAULT_BUCKET=your_bucket_name
|
|
31
|
+
COS_DEFAULT_REGION=ap-guangzhou
|
|
32
|
+
COS_KEY_PREFIX=figma-assets
|
|
33
|
+
COS_CDN_DOMAIN=cdn.example.com
|
|
34
|
+
```
|
|
12
35
|
|
|
13
|
-
|
|
36
|
+
Then add MCP configuration (Cursor Settings β MCP) without `env`:
|
|
14
37
|
|
|
15
|
-
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"mcpServers": {
|
|
41
|
+
"mcp-cos-upload": {
|
|
42
|
+
"command": "npx",
|
|
43
|
+
"args": ["-y", "mcp-cos-upload"]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
> **Note:** The `.env` file contains secrets and is already excluded from Git via `.gitignore`. Never commit it. Use `.env.example` as a reference template.
|
|
50
|
+
|
|
51
|
+
#### Method 2: MCP `env` Configuration
|
|
52
|
+
|
|
53
|
+
Alternatively, pass credentials directly in MCP config:
|
|
16
54
|
|
|
17
55
|
```json
|
|
18
56
|
{
|
|
19
57
|
"mcpServers": {
|
|
20
|
-
"cos-upload": {
|
|
58
|
+
"mcp-cos-upload": {
|
|
21
59
|
"command": "npx",
|
|
22
60
|
"args": ["-y", "mcp-cos-upload"],
|
|
23
61
|
"env": {
|
|
@@ -25,14 +63,18 @@ Add to your MCP configuration:
|
|
|
25
63
|
"COS_SECRET_KEY": "your_secret_key",
|
|
26
64
|
"COS_DEFAULT_BUCKET": "your_bucket_name",
|
|
27
65
|
"COS_DEFAULT_REGION": "ap-guangzhou",
|
|
28
|
-
"COS_KEY_PREFIX": "
|
|
29
|
-
"COS_CDN_DOMAIN": "
|
|
66
|
+
"COS_KEY_PREFIX": "figma-assets",
|
|
67
|
+
"COS_CDN_DOMAIN": "cdn.example.com"
|
|
30
68
|
}
|
|
31
69
|
}
|
|
32
70
|
}
|
|
33
71
|
}
|
|
34
72
|
```
|
|
35
73
|
|
|
74
|
+
#### Priority
|
|
75
|
+
|
|
76
|
+
If both are configured, project `.env` file takes **higher priority** over MCP `env` configuration.
|
|
77
|
+
|
|
36
78
|
### Environment Variables
|
|
37
79
|
|
|
38
80
|
| Variable | Required | Description |
|
|
@@ -40,11 +82,126 @@ Add to your MCP configuration:
|
|
|
40
82
|
| `COS_SECRET_ID` | β
| Tencent Cloud SecretId |
|
|
41
83
|
| `COS_SECRET_KEY` | β
| Tencent Cloud SecretKey |
|
|
42
84
|
| `COS_DEFAULT_BUCKET` | β
| Default COS bucket name |
|
|
43
|
-
| `COS_DEFAULT_REGION` | β
| Default COS region (e.g., `ap-guangzhou`) |
|
|
44
|
-
| `COS_KEY_PREFIX` | β | Key prefix for uploaded files (
|
|
85
|
+
| `COS_DEFAULT_REGION` | β
| Default COS region (e.g., `ap-guangzhou`, `ap-beijing`) |
|
|
86
|
+
| `COS_KEY_PREFIX` | β | Key prefix for uploaded files (default: `figma-assets`) |
|
|
45
87
|
| `COS_CDN_DOMAIN` | β | Custom CDN domain (e.g., `cdn.example.com`) |
|
|
46
88
|
|
|
47
|
-
|
|
89
|
+
### Usage Examples
|
|
90
|
+
|
|
91
|
+
Just tell AI what you want to upload:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
δΈδΌ θΏεΌ εΎηοΌ/Users/me/Downloads/screenshot.png
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
Upload this image to COS: https://example.com/image.png
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The AI will automatically:
|
|
102
|
+
1. Call the `cos_upload` tool
|
|
103
|
+
2. Compress the image (if applicable)
|
|
104
|
+
3. Upload to COS with date-organized path
|
|
105
|
+
4. Return the CDN URL
|
|
106
|
+
|
|
107
|
+
### Upload Path Structure
|
|
108
|
+
|
|
109
|
+
Files are automatically organized:
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
{COS_KEY_PREFIX}/{YYYY-MM-DD}/{filename}_{random}.{ext}
|
|
113
|
+
|
|
114
|
+
Example:
|
|
115
|
+
figma-assets/2025-12-22/screenshot_a3b8k2.png
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## For Developers
|
|
121
|
+
|
|
122
|
+
### Development Setup
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
# Clone the repository
|
|
126
|
+
git clone https://github.com/user/mcp-cos-upload.git
|
|
127
|
+
cd mcp-cos-upload
|
|
128
|
+
|
|
129
|
+
# Install dependencies
|
|
130
|
+
npm install
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Local Development
|
|
134
|
+
|
|
135
|
+
#### Method 1: Direct Node Execution
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Set environment variables
|
|
139
|
+
export COS_SECRET_ID="your_secret_id"
|
|
140
|
+
export COS_SECRET_KEY="your_secret_key"
|
|
141
|
+
export COS_DEFAULT_BUCKET="your_bucket"
|
|
142
|
+
export COS_DEFAULT_REGION="ap-guangzhou"
|
|
143
|
+
|
|
144
|
+
# Run the MCP server
|
|
145
|
+
node src/index.js
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Method 2: Configure in Cursor for Testing
|
|
149
|
+
|
|
150
|
+
Point to your local development path:
|
|
151
|
+
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"mcpServers": {
|
|
155
|
+
"mcp-cos-upload": {
|
|
156
|
+
"command": "node",
|
|
157
|
+
"args": ["/path/to/mcp-cos-upload/src/index.js"],
|
|
158
|
+
"env": {
|
|
159
|
+
"COS_SECRET_ID": "your_secret_id",
|
|
160
|
+
"COS_SECRET_KEY": "your_secret_key",
|
|
161
|
+
"COS_DEFAULT_BUCKET": "your_bucket",
|
|
162
|
+
"COS_DEFAULT_REGION": "ap-guangzhou"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
After modifying code, restart Cursor or disable/enable the MCP to reload.
|
|
170
|
+
|
|
171
|
+
### Project Structure
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
mcp-cos-upload/
|
|
175
|
+
βββ src/
|
|
176
|
+
β βββ index.js # MCP server entry, tool definitions
|
|
177
|
+
β βββ cos.js # COS client configuration
|
|
178
|
+
βββ .env.example # Environment variables template
|
|
179
|
+
βββ package.json
|
|
180
|
+
βββ CHANGELOG.md
|
|
181
|
+
βββ README.md
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Publishing to npm
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# 1. Update version in package.json
|
|
188
|
+
npm version patch # or minor/major
|
|
189
|
+
|
|
190
|
+
# 2. Login to npm (first time only)
|
|
191
|
+
npm login
|
|
192
|
+
|
|
193
|
+
# 3. Publish
|
|
194
|
+
npm publish
|
|
195
|
+
|
|
196
|
+
# 4. Verify
|
|
197
|
+
npm info mcp-cos-upload
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
After publishing, team members can use it immediately with `npx -y mcp-cos-upload`.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Tool Reference
|
|
48
205
|
|
|
49
206
|
### cos_upload
|
|
50
207
|
|
|
@@ -57,37 +214,62 @@ Upload a file to Tencent Cloud COS.
|
|
|
57
214
|
| `url` | string | β | URL to download and upload |
|
|
58
215
|
| `filepath` | string | β | Local file path to upload |
|
|
59
216
|
| `content` | string | β | Text content to upload |
|
|
60
|
-
| `bucket` | string | β | COS bucket name (uses env default
|
|
61
|
-
| `region` | string | β | COS region (uses env default
|
|
217
|
+
| `bucket` | string | β | COS bucket name (uses env default) |
|
|
218
|
+
| `region` | string | β | COS region (uses env default) |
|
|
62
219
|
| `key` | string | β | Object key (auto-generated if not provided) |
|
|
63
|
-
| `folder` | string | β | Folder prefix (
|
|
220
|
+
| `folder` | string | β | Folder prefix (default: `figma-assets`, use server config) |
|
|
64
221
|
| `filename` | string | β | Custom filename |
|
|
65
222
|
| `ext` | string | β | File extension (e.g., `png`, `jpg`, `svg`) |
|
|
66
223
|
| `compress` | boolean | β | Enable image compression (default: `true`) |
|
|
67
|
-
| `quality` | number | β | Compression quality 1-100 (default: `80
|
|
224
|
+
| `quality` | number | β | Compression quality 1-100 (default: `80`) |
|
|
68
225
|
|
|
69
|
-
> Note
|
|
226
|
+
> **Note:** `url`, `filepath`, and `content` are mutually exclusive - provide only one.
|
|
70
227
|
|
|
71
|
-
**
|
|
228
|
+
**Response:**
|
|
72
229
|
|
|
230
|
+
```json
|
|
231
|
+
{
|
|
232
|
+
"bucket": "your-bucket",
|
|
233
|
+
"region": "ap-guangzhou",
|
|
234
|
+
"key": "figma-assets/2025-12-22/image_a3b8k2.png",
|
|
235
|
+
"cdnUrl": "https://cdn.example.com/figma-assets/2025-12-22/image_a3b8k2.png"
|
|
236
|
+
}
|
|
73
237
|
```
|
|
74
|
-
|
|
75
|
-
|
|
238
|
+
|
|
239
|
+
---
|
|
76
240
|
|
|
77
241
|
## Image Compression
|
|
78
242
|
|
|
79
243
|
Supports automatic compression for uploaded images:
|
|
80
244
|
|
|
81
|
-
| Format | Compression |
|
|
82
|
-
|
|
83
|
-
| PNG |
|
|
84
|
-
| JPEG |
|
|
85
|
-
| WebP |
|
|
245
|
+
| Format | Compression Method |
|
|
246
|
+
|--------|-------------------|
|
|
247
|
+
| PNG | Palette mode + color quantization (TinyPNG-like) |
|
|
248
|
+
| JPEG | mozjpeg encoder with trellis quantization |
|
|
249
|
+
| WebP | Smart subsampling |
|
|
86
250
|
| GIF | Optimization |
|
|
87
|
-
| SVG | SVGO
|
|
251
|
+
| SVG | SVGO (removes redundant code) |
|
|
88
252
|
|
|
89
253
|
Compression is enabled by default. Use `compress: false` to upload original files.
|
|
90
254
|
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Troubleshooting
|
|
258
|
+
|
|
259
|
+
### MCP not working after code changes
|
|
260
|
+
|
|
261
|
+
Restart Cursor or toggle the MCP off/on in settings to reload the server.
|
|
262
|
+
|
|
263
|
+
### Permission denied
|
|
264
|
+
|
|
265
|
+
Ensure your `COS_SECRET_ID` and `COS_SECRET_KEY` have write access to the bucket.
|
|
266
|
+
|
|
267
|
+
### Upload failed with network error
|
|
268
|
+
|
|
269
|
+
Check if your network can access Tencent Cloud COS endpoints.
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
91
273
|
## License
|
|
92
274
|
|
|
93
275
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-cos-upload",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "MCP server for uploading files to Tencent Cloud COS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
23
23
|
"cos-nodejs-sdk-v5": "^2.15.4",
|
|
24
|
+
"dotenv": "^17.3.1",
|
|
24
25
|
"sharp": "^0.34.5",
|
|
25
26
|
"svgo": "^4.0.0",
|
|
26
27
|
"zod": "^3.24.0"
|
package/src/cos.js
CHANGED