mcp-cos-upload 1.1.3 → 1.1.5
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 +4 -2
- package/package.json +1 -1
- package/src/cos.js +50 -5
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ COS_CDN_DOMAIN=cdn.example.com
|
|
|
72
72
|
> **Note:** The `.env` file contains secrets — never commit it. Use `.env.example` as a reference template.
|
|
73
73
|
|
|
74
74
|
The server only reads one file:
|
|
75
|
-
1.
|
|
75
|
+
1. `<project-root>/.env`
|
|
76
76
|
|
|
77
77
|
It does **not** read:
|
|
78
78
|
1. MCP `env` configuration
|
|
@@ -80,6 +80,8 @@ It does **not** read:
|
|
|
80
80
|
3. Parent directory `.env`
|
|
81
81
|
4. `COS_ENV_PATH`
|
|
82
82
|
|
|
83
|
+
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.
|
|
84
|
+
|
|
83
85
|
### Environment Variables
|
|
84
86
|
|
|
85
87
|
| Variable | Required | Description |
|
|
@@ -247,7 +249,7 @@ This happens when using `npx -y mcp-cos-upload` directly — npm outputs package
|
|
|
247
249
|
|
|
248
250
|
### Missing COS_SECRET_ID or COS_SECRET_KEY
|
|
249
251
|
|
|
250
|
-
The server only reads
|
|
252
|
+
The server only reads `process.cwd()/.env`. If that file does not exist, or if it is missing `COS_SECRET_ID` / `COS_SECRET_KEY`, tool calls will return a clear error telling you which path it tried and what the current working directory was.
|
|
251
253
|
|
|
252
254
|
### MCP not working after code changes
|
|
253
255
|
|
package/package.json
CHANGED
package/src/cos.js
CHANGED
|
@@ -1,11 +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,
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
4
|
+
import { dirname, join, resolve } from "path";
|
|
6
5
|
|
|
7
|
-
const
|
|
8
|
-
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");
|
|
9
50
|
|
|
10
51
|
function parseEnvFile(filePath) {
|
|
11
52
|
const env = {};
|
|
@@ -34,7 +75,9 @@ function getMissingCredentialMessage() {
|
|
|
34
75
|
if (!fileEnv) {
|
|
35
76
|
return [
|
|
36
77
|
"[mcp-cos-upload] ❌ 未找到配置文件",
|
|
37
|
-
|
|
78
|
+
`项目根目录: ${PROJECT_ROOT}`,
|
|
79
|
+
`只会读取这个文件: ${PROJECT_ENV_PATH}`,
|
|
80
|
+
`当前工作目录: ${CURRENT_WORKING_DIRECTORY}`,
|
|
38
81
|
"请在该文件中设置:",
|
|
39
82
|
"COS_SECRET_ID=your_secret_id",
|
|
40
83
|
"COS_SECRET_KEY=your_secret_key",
|
|
@@ -45,7 +88,9 @@ function getMissingCredentialMessage() {
|
|
|
45
88
|
|
|
46
89
|
return [
|
|
47
90
|
"[mcp-cos-upload] ❌ .env 缺少 COS_SECRET_ID 或 COS_SECRET_KEY",
|
|
91
|
+
`项目根目录: ${PROJECT_ROOT}`,
|
|
48
92
|
`只读取此文件: ${PROJECT_ENV_PATH}`,
|
|
93
|
+
`当前工作目录: ${CURRENT_WORKING_DIRECTORY}`,
|
|
49
94
|
"请补全以下字段:",
|
|
50
95
|
"COS_SECRET_ID=your_secret_id",
|
|
51
96
|
"COS_SECRET_KEY=your_secret_key",
|