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 +33 -7
- package/package.json +1 -1
- package/src/cos.js +50 -5
- package/src/index.js +1 -1
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.
|
|
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
|
-
|
|
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": "
|
|
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
|
|
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.
|
|
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
|
|
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
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
|
|
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
|
-
|
|
36
|
-
|
|
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
|
-
`当前工作目录: ${
|
|
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