mcp-cos-upload 1.0.4 → 1.1.1

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 +47 -30
  2. package/package.json +4 -2
  3. package/src/cos.js +26 -1
package/README.md CHANGED
@@ -11,17 +11,38 @@ MCP server for uploading files to Tencent Cloud COS. Supports uploading from URL
11
11
 
12
12
  ---
13
13
 
14
+ ### Publishing to npm
15
+
16
+ ```bash
17
+ # 1. Update version in package.json
18
+ npm version patch # or minor/major
19
+
20
+ # 2. Login to npm (first time only)
21
+ npm login
22
+
23
+ # 3. Publish
24
+ npm publish
25
+
26
+ # 4. Verify
27
+ npm info mcp-cos-upload
28
+ ```
29
+
30
+ After publishing, team members can use it immediately (see Quick Start below).
31
+
32
+ ---
33
+
14
34
  ## For Team Members (Users)
15
35
 
16
36
  ### Quick Start
17
37
 
18
38
  #### Method 1: Project `.env` File (Recommended)
19
39
 
20
- Create a `.env` file in your project root:
40
+ 1. Create a `.env` file in your project root:
21
41
 
22
42
  ```bash
23
- cp node_modules/mcp-cos-upload/.env.example .env
24
- # Or create manually:
43
+ # Copy the template
44
+ cp .env.example .env
45
+ # Then fill in your values
25
46
  ```
26
47
 
27
48
  ```env
@@ -33,31 +54,39 @@ COS_KEY_PREFIX=figma-assets
33
54
  COS_CDN_DOMAIN=cdn.example.com
34
55
  ```
35
56
 
36
- Then add MCP configuration (Cursor Settings → MCP) without `env`:
57
+ 2. Add MCP configuration (Cursor Settings → MCP):
37
58
 
38
59
  ```json
39
60
  {
40
61
  "mcpServers": {
41
62
  "mcp-cos-upload": {
42
- "command": "npx",
43
- "args": ["-y", "mcp-cos-upload"]
63
+ "command": "sh",
64
+ "args": ["-c", "command -v mcp-cos-upload >/dev/null 2>&1 || npm i -g mcp-cos-upload >/dev/null 2>&1; exec mcp-cos-upload"]
44
65
  }
45
66
  }
46
67
  }
47
68
  ```
48
69
 
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.
70
+ > **Why not `npx`?** npm's `npx -y` outputs package installation info to stdout, which conflicts with MCP's stdio protocol. The shell wrapper auto-installs silently and keeps stdout clean.
71
+
72
+ > **Note:** The `.env` file contains secrets — never commit it. Use `.env.example` as a reference template.
73
+
74
+ The server searches for `.env` in the following order:
75
+ 1. `$COS_ENV_PATH` (custom path via env var)
76
+ 2. Project root (`process.cwd()/.env`, set by Cursor to workspace root)
77
+ 3. `~/.mcp-cos-upload.env`
78
+ 4. `~/.config/mcp-cos-upload/.env`
50
79
 
51
80
  #### Method 2: MCP `env` Configuration
52
81
 
53
- Alternatively, pass credentials directly in MCP config:
82
+ Alternatively, pass credentials directly in MCP config (no `.env` file needed):
54
83
 
55
84
  ```json
56
85
  {
57
86
  "mcpServers": {
58
87
  "mcp-cos-upload": {
59
- "command": "npx",
60
- "args": ["-y", "mcp-cos-upload"],
88
+ "command": "sh",
89
+ "args": ["-c", "command -v mcp-cos-upload >/dev/null 2>&1 || npm i -g mcp-cos-upload >/dev/null 2>&1; exec mcp-cos-upload"],
61
90
  "env": {
62
91
  "COS_SECRET_ID": "your_secret_id",
63
92
  "COS_SECRET_KEY": "your_secret_key",
@@ -181,26 +210,6 @@ mcp-cos-upload/
181
210
  └── README.md
182
211
  ```
183
212
 
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
213
  ## Tool Reference
205
214
 
206
215
  ### cos_upload
@@ -256,6 +265,14 @@ Compression is enabled by default. Use `compress: false` to upload original file
256
265
 
257
266
  ## Troubleshooting
258
267
 
268
+ ### `Unexpected token` / JSON parse error on startup
269
+
270
+ This happens when using `npx -y mcp-cos-upload` directly — npm outputs package installation info to stdout, breaking MCP's stdio protocol. **Use the recommended shell wrapper config** in Quick Start instead.
271
+
272
+ ### Missing COS_SECRET_ID or COS_SECRET_KEY
273
+
274
+ The server cannot find your credentials. Make sure you have a `.env` file in your project root (or `~/.mcp-cos-upload.env`). Check the `.env.example` template for required variables.
275
+
259
276
  ### MCP not working after code changes
260
277
 
261
278
  Restart Cursor or toggle the MCP off/on in settings to reload the server.
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "mcp-cos-upload",
3
- "version": "1.0.4",
3
+ "version": "1.1.1",
4
4
  "description": "MCP server for uploading files to Tencent Cloud COS",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
- "bin": "./src/index.js",
7
+ "bin": {
8
+ "mcp-cos-upload": "src/index.js"
9
+ },
8
10
  "files": [
9
11
  "src/**/*"
10
12
  ],
package/src/cos.js CHANGED
@@ -1,8 +1,33 @@
1
1
  // mcp-cos-upload - COS client configuration
2
2
  import COS from "cos-nodejs-sdk-v5";
3
3
  import dotenv from "dotenv";
4
+ import { existsSync } from "fs";
5
+ import { join, dirname } from "path";
6
+ import { homedir } from "os";
7
+ import { fileURLToPath } from "url";
4
8
 
5
- dotenv.config({ override: true });
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+
11
+ const envPaths = [
12
+ process.env.COS_ENV_PATH,
13
+ join(process.cwd(), ".env"),
14
+ join(homedir(), ".mcp-cos-upload.env"),
15
+ join(homedir(), ".config", "mcp-cos-upload", ".env"),
16
+ join(__dirname, "..", ".env"),
17
+ ].filter(Boolean);
18
+
19
+ let envLoaded = false;
20
+ for (const envPath of envPaths) {
21
+ if (existsSync(envPath)) {
22
+ dotenv.config({ path: envPath, override: true });
23
+ envLoaded = true;
24
+ process.stderr.write(`[mcp-cos-upload] loaded env from ${envPath}\n`);
25
+ break;
26
+ }
27
+ }
28
+ if (!envLoaded) {
29
+ dotenv.config({ override: true });
30
+ }
6
31
 
7
32
  export function createCosClient() {
8
33
  const secretId = process.env.COS_SECRET_ID;