@cloudbase/cloudbase-mcp 1.7.6 → 1.7.8
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/dist/cloudbase-manager.js +1 -1
- package/dist/index.js +58 -7
- package/dist/interactive-server.js +1 -1
- package/dist/tools/database.js +0 -1
- package/dist/tools/rag.js +0 -1
- package/dist/utils/telemetry.js +51 -2
- package/package.json +2 -1
|
@@ -2,7 +2,7 @@ import { getLoginState } from './auth.js';
|
|
|
2
2
|
import { loadEnvIdFromUserConfig, saveEnvIdToUserConfig, autoSetupEnvironmentId } from './tools/interactive.js';
|
|
3
3
|
import CloudBase from "@cloudbase/manager-node";
|
|
4
4
|
import { debug, error } from './utils/logger.js';
|
|
5
|
-
const ENV_ID_TIMEOUT =
|
|
5
|
+
const ENV_ID_TIMEOUT = 300000; // 300 seconds
|
|
6
6
|
// 统一的环境ID管理类
|
|
7
7
|
class EnvironmentManager {
|
|
8
8
|
cachedEnvId = null;
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,10 @@ import { registerRagTools } from './tools/rag.js';
|
|
|
12
12
|
import { registerSetupTools } from "./tools/setup.js";
|
|
13
13
|
import { registerInteractiveTools } from "./tools/interactive.js";
|
|
14
14
|
import { wrapServerWithTelemetry } from "./utils/tool-wrapper.js";
|
|
15
|
-
import { telemetryReporter } from "./utils/telemetry.js";
|
|
15
|
+
import { telemetryReporter, reportToolkitLifecycle } from "./utils/telemetry.js";
|
|
16
|
+
import { info } from "./utils/logger.js";
|
|
17
|
+
// 记录启动时间
|
|
18
|
+
const startTime = Date.now();
|
|
16
19
|
// Create server instance
|
|
17
20
|
const server = new McpServer({
|
|
18
21
|
name: "cloudbase-mcp",
|
|
@@ -47,17 +50,65 @@ registerInteractiveTools(server);
|
|
|
47
50
|
async function main() {
|
|
48
51
|
const transport = new StdioServerTransport();
|
|
49
52
|
await server.connect(transport);
|
|
50
|
-
|
|
53
|
+
info("TencentCloudBase MCP Server running on stdio");
|
|
51
54
|
// 上报启动信息
|
|
52
55
|
if (telemetryReporter.isEnabled()) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
nodeVersion: process.version,
|
|
56
|
-
platform: process.platform
|
|
56
|
+
await reportToolkitLifecycle({
|
|
57
|
+
event: 'start'
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
// 设置进程退出处理
|
|
62
|
+
function setupExitHandlers() {
|
|
63
|
+
const handleExit = async (exitCode, signal) => {
|
|
64
|
+
if (telemetryReporter.isEnabled()) {
|
|
65
|
+
const duration = Date.now() - startTime;
|
|
66
|
+
await reportToolkitLifecycle({
|
|
67
|
+
event: 'exit',
|
|
68
|
+
duration,
|
|
69
|
+
exitCode,
|
|
70
|
+
error: signal ? `Process terminated by signal: ${signal}` : undefined
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
// 正常退出
|
|
75
|
+
process.on('exit', (code) => {
|
|
76
|
+
// 注意:exit 事件中不能使用异步操作,所以这里只能同步处理
|
|
77
|
+
// 异步上报在其他信号处理中完成
|
|
78
|
+
});
|
|
79
|
+
// 异常退出处理
|
|
80
|
+
process.on('SIGINT', async () => {
|
|
81
|
+
await handleExit(0, 'SIGINT');
|
|
82
|
+
process.exit(0);
|
|
83
|
+
});
|
|
84
|
+
process.on('SIGTERM', async () => {
|
|
85
|
+
await handleExit(0, 'SIGTERM');
|
|
86
|
+
process.exit(0);
|
|
87
|
+
});
|
|
88
|
+
process.on('uncaughtException', async (error) => {
|
|
89
|
+
console.error('Uncaught Exception:', error);
|
|
90
|
+
await handleExit(1, `uncaughtException: ${error.message}`);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
});
|
|
93
|
+
process.on('unhandledRejection', async (reason) => {
|
|
94
|
+
console.error('Unhandled Rejection:', reason);
|
|
95
|
+
await handleExit(1, `unhandledRejection: ${String(reason)}`);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// 设置退出处理器
|
|
100
|
+
setupExitHandlers();
|
|
101
|
+
main().catch(async (error) => {
|
|
61
102
|
console.error("Fatal error in main():", error);
|
|
103
|
+
// 上报启动失败
|
|
104
|
+
if (telemetryReporter.isEnabled()) {
|
|
105
|
+
const duration = Date.now() - startTime;
|
|
106
|
+
await reportToolkitLifecycle({
|
|
107
|
+
event: 'exit',
|
|
108
|
+
duration,
|
|
109
|
+
exitCode: 1,
|
|
110
|
+
error: `Startup failed: ${error.message}`
|
|
111
|
+
});
|
|
112
|
+
}
|
|
62
113
|
process.exit(1);
|
|
63
114
|
});
|
package/dist/tools/database.js
CHANGED
|
@@ -1171,7 +1171,6 @@ export function registerDatabaseTools(server) {
|
|
|
1171
1171
|
if (result.Data.Schema) {
|
|
1172
1172
|
try {
|
|
1173
1173
|
const schema = JSON.parse(result.Data.Schema);
|
|
1174
|
-
console.log(result.Data);
|
|
1175
1174
|
const properties = schema.properties || {};
|
|
1176
1175
|
// 提取用户定义的字段
|
|
1177
1176
|
userFields = Object.keys(properties)
|
package/dist/tools/rag.js
CHANGED
package/dist/utils/telemetry.js
CHANGED
|
@@ -6,7 +6,6 @@ import { readFileSync } from 'fs';
|
|
|
6
6
|
import { join, dirname } from 'path';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import { debug } from './logger.js';
|
|
9
|
-
import { getEnvId } from '../cloudbase-manager.js';
|
|
10
9
|
/**
|
|
11
10
|
* 数据上报类
|
|
12
11
|
* 用于收集 MCP 工具使用情况和错误信息,帮助改进产品
|
|
@@ -207,13 +206,29 @@ export const telemetryReporter = new TelemetryReporter();
|
|
|
207
206
|
// 便捷方法
|
|
208
207
|
export const reportToolCall = async (params) => {
|
|
209
208
|
const { nodeVersion, osType, osRelease, arch, mcpVersion } = telemetryReporter.getUserAgent();
|
|
209
|
+
// 安全获取环境ID,避免循环依赖
|
|
210
|
+
let envId;
|
|
211
|
+
try {
|
|
212
|
+
// 只从缓存或环境变量获取,不触发自动设置
|
|
213
|
+
envId = process.env.CLOUDBASE_ENV_ID || undefined;
|
|
214
|
+
if (!envId) {
|
|
215
|
+
// 尝试从配置文件读取,但不触发交互式设置
|
|
216
|
+
const { loadEnvIdFromUserConfig } = await import('../tools/interactive.js');
|
|
217
|
+
envId = await loadEnvIdFromUserConfig() || undefined;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
// 忽略错误,使用 undefined
|
|
222
|
+
debug('获取环境ID失败,遥测数据将不包含环境ID', err);
|
|
223
|
+
envId = undefined;
|
|
224
|
+
}
|
|
210
225
|
// 报告工具调用情况
|
|
211
226
|
const eventData = {
|
|
212
227
|
toolName: params.toolName,
|
|
213
228
|
success: params.success ? 'true' : 'false',
|
|
214
229
|
duration: params.duration,
|
|
215
230
|
error: params.error ? params.error.substring(0, 200) : undefined, // 限制错误信息长度
|
|
216
|
-
envId:
|
|
231
|
+
envId: envId || 'unknown',
|
|
217
232
|
nodeVersion,
|
|
218
233
|
osType,
|
|
219
234
|
osRelease,
|
|
@@ -236,3 +251,37 @@ export const reportToolCall = async (params) => {
|
|
|
236
251
|
}
|
|
237
252
|
telemetryReporter.report('toolkit_tool_call', eventData);
|
|
238
253
|
};
|
|
254
|
+
// Toolkit 生命周期上报
|
|
255
|
+
export const reportToolkitLifecycle = async (params) => {
|
|
256
|
+
const { nodeVersion, osType, osRelease, arch, mcpVersion } = telemetryReporter.getUserAgent();
|
|
257
|
+
// 安全获取环境ID,避免循环依赖
|
|
258
|
+
let envId;
|
|
259
|
+
try {
|
|
260
|
+
// 只从缓存或环境变量获取,不触发自动设置
|
|
261
|
+
envId = process.env.CLOUDBASE_ENV_ID || undefined;
|
|
262
|
+
if (!envId) {
|
|
263
|
+
// 尝试从配置文件读取,但不触发交互式设置
|
|
264
|
+
const { loadEnvIdFromUserConfig } = await import('../tools/interactive.js');
|
|
265
|
+
envId = await loadEnvIdFromUserConfig() || undefined;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch (err) {
|
|
269
|
+
// 忽略错误,使用 undefined
|
|
270
|
+
debug('获取环境ID失败,遥测数据将不包含环境ID', err);
|
|
271
|
+
envId = undefined;
|
|
272
|
+
}
|
|
273
|
+
// 报告 Toolkit 生命周期事件
|
|
274
|
+
const eventData = {
|
|
275
|
+
event: params.event,
|
|
276
|
+
duration: params.duration,
|
|
277
|
+
exitCode: params.exitCode,
|
|
278
|
+
error: params.error ? params.error.substring(0, 200) : undefined, // 限制错误信息长度
|
|
279
|
+
envId: envId || 'unknown',
|
|
280
|
+
nodeVersion,
|
|
281
|
+
osType,
|
|
282
|
+
osRelease,
|
|
283
|
+
arch,
|
|
284
|
+
mcpVersion
|
|
285
|
+
};
|
|
286
|
+
telemetryReporter.report('toolkit_lifecycle', eventData);
|
|
287
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/cloudbase-mcp",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.8",
|
|
4
4
|
"description": "腾讯云开发 MCP Server,支持静态托管/环境查询/",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"clean": "rm -rf dist",
|
|
17
17
|
"prebuild": "npm run clean",
|
|
18
18
|
"build": "tsc && chmod 755 dist/index.js",
|
|
19
|
+
"test": "npm run build && npx @modelcontextprotocol/inspector node ./dist/index.js",
|
|
19
20
|
"prepublishOnly": "npm run build"
|
|
20
21
|
},
|
|
21
22
|
"files": [
|