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.
Files changed (3) hide show
  1. package/README.md +208 -26
  2. package/package.json +2 -1
  3. 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
- ## Installation
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
- npm install mcp-cos-upload
23
+ cp node_modules/mcp-cos-upload/.env.example .env
24
+ # Or create manually:
9
25
  ```
10
26
 
11
- ## Usage
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
- ### MCP Configuration (Cursor / Claude Desktop)
36
+ Then add MCP configuration (Cursor Settings β†’ MCP) without `env`:
14
37
 
15
- Add to your MCP configuration:
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": "uploads/",
29
- "COS_CDN_DOMAIN": "your-cdn-domain.com"
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 (e.g., `uploads/`) |
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
- ## Tools
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 if not provided) |
61
- | `region` | string | ❌ | COS region (uses env default if not provided) |
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 (overrides `COS_KEY_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`, for JPEG/WebP/PNG) |
224
+ | `quality` | number | ❌ | Compression quality 1-100 (default: `80`) |
68
225
 
69
- > Note: `url`, `filepath`, and `content` are mutually exclusive - provide only one.
226
+ > **Note:** `url`, `filepath`, and `content` are mutually exclusive - provide only one.
70
227
 
71
- **Example:**
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
- Upload this image to COS: https://example.com/image.png
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 | Lossless/lossy compression |
84
- | JPEG | Quality adjustment with mozjpeg |
85
- | WebP | Quality adjustment |
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 optimization (removes redundant code) |
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",
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
@@ -1,5 +1,8 @@
1
1
  // mcp-cos-upload - COS client configuration
2
2
  import COS from "cos-nodejs-sdk-v5";
3
+ import dotenv from "dotenv";
4
+
5
+ dotenv.config({ override: true });
3
6
 
4
7
  export function createCosClient() {
5
8
  const secretId = process.env.COS_SECRET_ID;