mcp-cos-upload 1.1.4 → 1.1.6

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 CHANGED
@@ -37,7 +37,13 @@ After publishing, team members can use it immediately (see Quick Start below).
37
37
 
38
38
  #### Method 1: Project `.env` File (Recommended)
39
39
 
40
- 1. Create a `.env` file in your project root:
40
+ 1. Install once:
41
+
42
+ ```bash
43
+ npm i -g mcp-cos-upload
44
+ ```
45
+
46
+ 2. Create a `.env` file in your project root:
41
47
 
42
48
  ```bash
43
49
  # Copy the template
@@ -54,25 +60,26 @@ COS_KEY_PREFIX=figma-assets
54
60
  COS_CDN_DOMAIN=cdn.example.com
55
61
  ```
56
62
 
57
- 2. Add MCP configuration (Cursor Settings → MCP):
63
+ 3. Add MCP configuration (Cursor Settings → MCP):
58
64
 
59
65
  ```json
60
66
  {
61
67
  "mcpServers": {
62
68
  "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"]
69
+ "command": "mcp-cos-upload"
65
70
  }
66
71
  }
67
72
  }
68
73
  ```
69
74
 
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.
75
+ > **Why this is recommended:** MCP startup stays short and predictable. The server only executes the installed binary and does not run npm during startup.
76
+
77
+ > **Why not `npx`?** npm's `npx -y` outputs package installation info to stdout, which conflicts with MCP's stdio protocol.
71
78
 
72
79
  > **Note:** The `.env` file contains secrets — never commit it. Use `.env.example` as a reference template.
73
80
 
74
81
  The server only reads one file:
75
- 1. `process.cwd()/.env`
82
+ 1. `<project-root>/.env`
76
83
 
77
84
  It does **not** read:
78
85
  1. MCP `env` configuration
@@ -80,6 +87,25 @@ It does **not** read:
80
87
  3. Parent directory `.env`
81
88
  4. `COS_ENV_PATH`
82
89
 
90
+ Project root is inferred from the current working directory by walking upward and finding common project markers such as `.git`, `package.json`, `pnpm-workspace.yaml`, `.cursor`, or `.mcp.json`. After the root is determined, only that single `.env` file is read.
91
+
92
+ #### Method 2: Auto-Install On First Run (Optional)
93
+
94
+ Use this only if you explicitly want convenience over startup stability:
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "mcp-cos-upload": {
100
+ "command": "sh",
101
+ "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"]
102
+ }
103
+ }
104
+ }
105
+ ```
106
+
107
+ This mode installs automatically only when the command is missing. It does **not** auto-update an already installed version.
108
+
83
109
  ### Environment Variables
84
110
 
85
111
  | Variable | Required | Description |
@@ -243,7 +269,7 @@ Compression is enabled by default. Use `compress: false` to upload original file
243
269
 
244
270
  ### `Unexpected token` / JSON parse error on startup
245
271
 
246
- 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.
272
+ 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 direct command config** in Quick Start instead.
247
273
 
248
274
  ### Missing COS_SECRET_ID or COS_SECRET_KEY
249
275
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-cos-upload",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "MCP server for uploading files to Tencent Cloud COS",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/cos.js CHANGED
@@ -1,9 +1,52 @@
1
1
  // mcp-cos-upload - COS client configuration
2
2
  import COS from "cos-nodejs-sdk-v5";
3
3
  import { readFileSync, existsSync } from "fs";
4
- import { join } from "path";
4
+ import { dirname, join, resolve } from "path";
5
5
 
6
- const PROJECT_ENV_PATH = join(process.cwd(), ".env");
6
+ const REPO_MARKERS = [".git", ".hg", ".svn"];
7
+ const PROJECT_MARKERS = [
8
+ ".mcp.json",
9
+ ".cursor",
10
+ ".claude",
11
+ "package.json",
12
+ "pnpm-workspace.yaml",
13
+ "turbo.json",
14
+ "lerna.json",
15
+ "nx.json",
16
+ "pyproject.toml",
17
+ "Cargo.toml",
18
+ "go.mod",
19
+ ];
20
+
21
+ function hasAnyMarker(dirPath, markerNames) {
22
+ return markerNames.some((markerName) => existsSync(join(dirPath, markerName)));
23
+ }
24
+
25
+ function findProjectRoot(startDir) {
26
+ let currentDir = resolve(startDir);
27
+ let repoRoot = null;
28
+ let projectRoot = null;
29
+
30
+ while (true) {
31
+ if (hasAnyMarker(currentDir, REPO_MARKERS)) {
32
+ repoRoot = currentDir;
33
+ }
34
+
35
+ if (hasAnyMarker(currentDir, PROJECT_MARKERS)) {
36
+ projectRoot = currentDir;
37
+ }
38
+
39
+ const parentDir = dirname(currentDir);
40
+ if (parentDir === currentDir) break;
41
+ currentDir = parentDir;
42
+ }
43
+
44
+ return repoRoot || projectRoot || resolve(startDir);
45
+ }
46
+
47
+ const CURRENT_WORKING_DIRECTORY = process.cwd();
48
+ const PROJECT_ROOT = findProjectRoot(CURRENT_WORKING_DIRECTORY);
49
+ const PROJECT_ENV_PATH = join(PROJECT_ROOT, ".env");
7
50
 
8
51
  function parseEnvFile(filePath) {
9
52
  const env = {};
@@ -32,8 +75,9 @@ function getMissingCredentialMessage() {
32
75
  if (!fileEnv) {
33
76
  return [
34
77
  "[mcp-cos-upload] ❌ 未找到配置文件",
35
- `只会读取项目根目录 .env: ${PROJECT_ENV_PATH}`,
36
- `当前工作目录: ${process.cwd()}`,
78
+ `项目根目录: ${PROJECT_ROOT}`,
79
+ `只会读取这个文件: ${PROJECT_ENV_PATH}`,
80
+ `当前工作目录: ${CURRENT_WORKING_DIRECTORY}`,
37
81
  "请在该文件中设置:",
38
82
  "COS_SECRET_ID=your_secret_id",
39
83
  "COS_SECRET_KEY=your_secret_key",
@@ -44,8 +88,9 @@ function getMissingCredentialMessage() {
44
88
 
45
89
  return [
46
90
  "[mcp-cos-upload] ❌ .env 缺少 COS_SECRET_ID 或 COS_SECRET_KEY",
91
+ `项目根目录: ${PROJECT_ROOT}`,
47
92
  `只读取此文件: ${PROJECT_ENV_PATH}`,
48
- `当前工作目录: ${process.cwd()}`,
93
+ `当前工作目录: ${CURRENT_WORKING_DIRECTORY}`,
49
94
  "请补全以下字段:",
50
95
  "COS_SECRET_ID=your_secret_id",
51
96
  "COS_SECRET_KEY=your_secret_key",
package/src/index.js CHANGED
@@ -56,7 +56,7 @@ const cosUploadInputSchema = {
56
56
 
57
57
  async function main() {
58
58
  const server = new Server(
59
- { name: "mcp-cos-upload", version: "1.1.2" },
59
+ { name: "mcp-cos-upload", version: "1.1.5" },
60
60
  { capabilities: { tools: {} } }
61
61
  );
62
62