@cloudbase/cloudbase-mcp 1.6.0 → 1.7.0
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 +10 -0
- package/dist/auth.js +4 -0
- package/dist/cloudbase-manager.js +81 -10
- package/dist/index.js +3 -0
- package/dist/interactive-server.js +1621 -0
- package/dist/tools/env.js +59 -13
- package/dist/tools/interactive.js +198 -0
- package/dist/utils/logger.js +119 -0
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -100,6 +100,15 @@ https://github.com/user-attachments/assets/2b402fa6-c5c4-495a-b85b-f5d4a25daa4a
|
|
|
100
100
|
>
|
|
101
101
|
> 默认模式下需要手动确认执行,较为安全。
|
|
102
102
|
|
|
103
|
+
#### 环境登录
|
|
104
|
+
|
|
105
|
+
CloudBase AI ToolKit 提供了简单的环境登录管理:
|
|
106
|
+
|
|
107
|
+
- **登录环境**: 使用 `login` 工具登录并选择云开发环境
|
|
108
|
+
- **退出登录**: 使用 `logout` 工具退出当前环境
|
|
109
|
+
|
|
110
|
+
登录成功后会自动保存环境配置,无需重启服务即可生效。
|
|
111
|
+
|
|
103
112
|
以下工具均支持 CloudBase AI ToolKit,可根据你的开发环境选择合适的工具:
|
|
104
113
|
|
|
105
114
|
| 工具 | 支持平台 |
|
|
@@ -623,6 +632,7 @@ AI 会自动:
|
|
|
623
632
|
|
|
624
633
|
| 工具名称 | 功能简介 |
|
|
625
634
|
|----------|----------|
|
|
635
|
+
| login | 登录并选择云开发环境 |
|
|
626
636
|
| logout | 登出当前云开发账户 |
|
|
627
637
|
| downloadTemplate | 下载CloudBase项目模板(React、小程序、AI编辑器配置等) |
|
|
628
638
|
| listEnvs | 获取所有云开发环境信息 |
|
package/dist/auth.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { AuthSupevisor } from '@cloudbase/toolbox';
|
|
2
|
+
import { debug } from './utils/logger.js';
|
|
2
3
|
const auth = AuthSupevisor.getInstance({});
|
|
3
4
|
export async function getLoginState() {
|
|
4
5
|
const { TENCENTCLOUD_SECRETID, TENCENTCLOUD_SECRETKEY, TENCENTCLOUD_SESSIONTOKEN } = process.env;
|
|
6
|
+
debug('TENCENTCLOUD_SECRETID', TENCENTCLOUD_SECRETID);
|
|
5
7
|
if (TENCENTCLOUD_SECRETID && TENCENTCLOUD_SECRETKEY) {
|
|
8
|
+
debug('loginByApiSecret');
|
|
6
9
|
await auth.loginByApiSecret(TENCENTCLOUD_SECRETID, TENCENTCLOUD_SECRETKEY, TENCENTCLOUD_SESSIONTOKEN);
|
|
7
10
|
}
|
|
8
11
|
const loginState = await auth.getLoginState();
|
|
9
12
|
if (!loginState) {
|
|
13
|
+
debug('loginByApiSecret');
|
|
10
14
|
await auth.loginByWebAuth({});
|
|
11
15
|
const loginState = await auth.getLoginState();
|
|
12
16
|
return loginState;
|
|
@@ -1,13 +1,84 @@
|
|
|
1
|
-
import CloudBase from "@cloudbase/manager-node";
|
|
2
1
|
import { getLoginState } from './auth.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { ensureEnvId, autoSetupEnvironmentId } from './tools/interactive.js';
|
|
3
|
+
import CloudBase from "@cloudbase/manager-node";
|
|
4
|
+
import { debug, error } from './utils/logger.js';
|
|
5
|
+
let initializationPromise = null;
|
|
6
|
+
let noEnvIdInitializationPromise = null;
|
|
7
|
+
const INITIALIZATION_TIMEOUT = 30000; // 30 seconds
|
|
8
|
+
export function getCloudBaseManager(options = {}) {
|
|
9
|
+
const { requireEnvId = true } = options;
|
|
10
|
+
if (requireEnvId) {
|
|
11
|
+
if (initializationPromise) {
|
|
12
|
+
return initializationPromise;
|
|
13
|
+
}
|
|
14
|
+
const executor = async () => {
|
|
15
|
+
try {
|
|
16
|
+
// 检查并确保环境ID已配置
|
|
17
|
+
let userEnvId = await ensureEnvId();
|
|
18
|
+
if (!userEnvId) {
|
|
19
|
+
debug("未找到环境ID,尝试自动设置...");
|
|
20
|
+
userEnvId = await autoSetupEnvironmentId();
|
|
21
|
+
if (!userEnvId) {
|
|
22
|
+
throw new Error("CloudBase Environment ID not found after auto setup. Please set CLOUDBASE_ENV_ID or run setupEnvironmentId tool.");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const loginState = await getLoginState();
|
|
26
|
+
const { envId, secretId, secretKey, token } = loginState;
|
|
27
|
+
const manager = new CloudBase({
|
|
28
|
+
secretId,
|
|
29
|
+
secretKey,
|
|
30
|
+
envId: userEnvId,
|
|
31
|
+
token,
|
|
32
|
+
proxy: process.env.http_proxy
|
|
33
|
+
});
|
|
34
|
+
return manager;
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
error('Failed to initialize CloudBase Manager:', err);
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
42
|
+
const id = setTimeout(() => {
|
|
43
|
+
clearTimeout(id);
|
|
44
|
+
reject(new Error(`CloudBase Manager initialization timed out after ${INITIALIZATION_TIMEOUT / 1000} seconds.`));
|
|
45
|
+
}, INITIALIZATION_TIMEOUT);
|
|
46
|
+
});
|
|
47
|
+
initializationPromise = Promise.race([executor(), timeoutPromise]);
|
|
48
|
+
initializationPromise.catch(() => {
|
|
49
|
+
initializationPromise = null;
|
|
50
|
+
});
|
|
51
|
+
return initializationPromise;
|
|
52
|
+
}
|
|
53
|
+
if (noEnvIdInitializationPromise) {
|
|
54
|
+
return noEnvIdInitializationPromise;
|
|
55
|
+
}
|
|
56
|
+
const noEnvIdExecutor = async () => {
|
|
57
|
+
try {
|
|
58
|
+
const loginState = await getLoginState();
|
|
59
|
+
const { secretId, secretKey, token } = loginState;
|
|
60
|
+
const manager = new CloudBase({
|
|
61
|
+
secretId,
|
|
62
|
+
secretKey,
|
|
63
|
+
token,
|
|
64
|
+
proxy: process.env.http_proxy
|
|
65
|
+
});
|
|
66
|
+
return manager;
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
error('Failed to initialize CloudBase Manager (no envId):', err instanceof Error ? err.message : String(err));
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
74
|
+
const id = setTimeout(() => {
|
|
75
|
+
clearTimeout(id);
|
|
76
|
+
reject(new Error(`CloudBase Manager (no envId) initialization timed out after ${INITIALIZATION_TIMEOUT / 1000} seconds.`));
|
|
77
|
+
}, INITIALIZATION_TIMEOUT);
|
|
78
|
+
});
|
|
79
|
+
noEnvIdInitializationPromise = Promise.race([noEnvIdExecutor(), timeoutPromise]);
|
|
80
|
+
noEnvIdInitializationPromise.catch(() => {
|
|
81
|
+
noEnvIdInitializationPromise = null;
|
|
11
82
|
});
|
|
12
|
-
return
|
|
83
|
+
return noEnvIdInitializationPromise;
|
|
13
84
|
}
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { registerDownloadTools } from "./tools/download.js";
|
|
|
9
9
|
import { registerStorageTools } from "./tools/storage.js";
|
|
10
10
|
import { registerRagTools } from './tools/rag.js';
|
|
11
11
|
import { registerSetupTools } from "./tools/setup.js";
|
|
12
|
+
import { registerInteractiveTools } from "./tools/interactive.js";
|
|
12
13
|
// Create server instance
|
|
13
14
|
const server = new McpServer({
|
|
14
15
|
name: "cloudbase-mcp",
|
|
@@ -36,6 +37,8 @@ registerDownloadTools(server);
|
|
|
36
37
|
registerStorageTools(server);
|
|
37
38
|
// Register setup tools
|
|
38
39
|
registerSetupTools(server);
|
|
40
|
+
// Register interactive tools
|
|
41
|
+
registerInteractiveTools(server);
|
|
39
42
|
async function main() {
|
|
40
43
|
const transport = new StdioServerTransport();
|
|
41
44
|
await server.connect(transport);
|