@cloudbase/cloudbase-mcp 2.3.0 → 2.4.0-alpha.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 +1 -1
- package/dist/cli.cjs +731 -141
- package/dist/index.cjs +731 -141
- package/dist/index.js +314 -106
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -895,6 +895,7 @@ const fs_1 = __importDefault(__webpack_require__(421));
|
|
|
895
895
|
const os_1 = __importDefault(__webpack_require__(116));
|
|
896
896
|
const path_1 = __importDefault(__webpack_require__(521));
|
|
897
897
|
const winston_1 = __importDefault(__webpack_require__(322));
|
|
898
|
+
const cloud_mode_js_1 = __webpack_require__(684);
|
|
898
899
|
// Use require for winston-daily-rotate-file to avoid webpack bundling issues
|
|
899
900
|
// Handle both CommonJS and ES module exports
|
|
900
901
|
const DailyRotateFileModule = __webpack_require__(259);
|
|
@@ -946,16 +947,18 @@ if (shouldUseConsole()) {
|
|
|
946
947
|
stderrLevels: ['error', 'warn', 'info', 'debug'], // All logs go to stderr
|
|
947
948
|
}));
|
|
948
949
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
950
|
+
if (!(0, cloud_mode_js_1.isCloudMode)()) {
|
|
951
|
+
// File transport with daily rotation
|
|
952
|
+
transports.push(new DailyRotateFile({
|
|
953
|
+
dirname: logDir,
|
|
954
|
+
filename: 'cloudbase-mcp-%DATE%.log',
|
|
955
|
+
datePattern: 'YYYY-MM-DD',
|
|
956
|
+
format: winston_1.default.format.combine(winston_1.default.format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ss.SSSZ' }), logFormat),
|
|
957
|
+
maxFiles: '30d', // Keep logs for 30 days
|
|
958
|
+
maxSize: '20m', // Max file size before rotation
|
|
959
|
+
zippedArchive: false, // Don't compress old logs
|
|
960
|
+
}));
|
|
961
|
+
}
|
|
959
962
|
// Create winston logger instance
|
|
960
963
|
const logger = winston_1.default.createLogger({
|
|
961
964
|
level: getLogLevel(),
|
|
@@ -1577,6 +1580,7 @@ function registerDataModelTools(server) {
|
|
|
1577
1580
|
Name: name,
|
|
1578
1581
|
},
|
|
1579
1582
|
});
|
|
1583
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1580
1584
|
// 只保留基础字段,过滤掉冗余信息,并简化Schema
|
|
1581
1585
|
let simplifiedSchema = null;
|
|
1582
1586
|
// 解析并简化Schema
|
|
@@ -1715,6 +1719,7 @@ function registerDataModelTools(server) {
|
|
|
1715
1719
|
Action: "DescribeDataSourceList",
|
|
1716
1720
|
Param: listParams,
|
|
1717
1721
|
});
|
|
1722
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1718
1723
|
const models = result.Data?.Rows || [];
|
|
1719
1724
|
// 只保留基础字段,list操作不返回Schema
|
|
1720
1725
|
const simplifiedModels = models.map((model) => ({
|
|
@@ -1751,6 +1756,7 @@ function registerDataModelTools(server) {
|
|
|
1751
1756
|
Name: name,
|
|
1752
1757
|
},
|
|
1753
1758
|
});
|
|
1759
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1754
1760
|
if (!result.Data) {
|
|
1755
1761
|
throw new Error(`数据模型 ${name} 不存在`);
|
|
1756
1762
|
}
|
|
@@ -1955,6 +1961,7 @@ classDiagram
|
|
|
1955
1961
|
EnvId: currentEnvId,
|
|
1956
1962
|
},
|
|
1957
1963
|
});
|
|
1964
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
1958
1965
|
const taskId = result.Data?.TaskId;
|
|
1959
1966
|
if (!taskId) {
|
|
1960
1967
|
return {
|
|
@@ -1985,6 +1992,7 @@ classDiagram
|
|
|
1985
1992
|
TaskId: taskId,
|
|
1986
1993
|
},
|
|
1987
1994
|
});
|
|
1995
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, statusResult);
|
|
1988
1996
|
status = statusResult.Data?.Status || "init";
|
|
1989
1997
|
}
|
|
1990
1998
|
// 返回最终结果
|
|
@@ -2525,7 +2533,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
2525
2533
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2526
2534
|
};
|
|
2527
2535
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2528
|
-
exports.downloadWebTemplate = downloadWebTemplate;
|
|
2529
2536
|
exports.getClaudePrompt = getClaudePrompt;
|
|
2530
2537
|
exports.registerRagTools = registerRagTools;
|
|
2531
2538
|
const adm_zip_1 = __importDefault(__webpack_require__(872));
|
|
@@ -2543,6 +2550,58 @@ const KnowledgeBaseIdMap = {
|
|
|
2543
2550
|
scf: "scfsczskzyws_4bdc",
|
|
2544
2551
|
miniprogram: "xcxzskws_25d8",
|
|
2545
2552
|
};
|
|
2553
|
+
// ============ 缓存配置 ============
|
|
2554
|
+
const CACHE_BASE_DIR = path.join(os.homedir(), ".cloudbase-mcp");
|
|
2555
|
+
const CACHE_META_FILE = path.join(CACHE_BASE_DIR, "cache-meta.json");
|
|
2556
|
+
const DEFAULT_CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 默认 24 小时
|
|
2557
|
+
// 支持环境变量 CLOUDBASE_MCP_CACHE_TTL_MS 控制缓存过期时间(毫秒)
|
|
2558
|
+
const parsedCacheTTL = process.env.CLOUDBASE_MCP_CACHE_TTL_MS
|
|
2559
|
+
? parseInt(process.env.CLOUDBASE_MCP_CACHE_TTL_MS, 10)
|
|
2560
|
+
: NaN;
|
|
2561
|
+
const CACHE_TTL_MS = Number.isNaN(parsedCacheTTL) || parsedCacheTTL < 0
|
|
2562
|
+
? DEFAULT_CACHE_TTL_MS
|
|
2563
|
+
: parsedCacheTTL;
|
|
2564
|
+
if (!Number.isNaN(parsedCacheTTL) && parsedCacheTTL >= 0) {
|
|
2565
|
+
(0, logger_js_1.debug)("[cache] Using TTL from CLOUDBASE_MCP_CACHE_TTL_MS", {
|
|
2566
|
+
ttlMs: CACHE_TTL_MS,
|
|
2567
|
+
});
|
|
2568
|
+
}
|
|
2569
|
+
else {
|
|
2570
|
+
(0, logger_js_1.debug)("[cache] Using default TTL", { ttlMs: CACHE_TTL_MS });
|
|
2571
|
+
}
|
|
2572
|
+
// 共享的下载 Promise,防止并发重复下载
|
|
2573
|
+
let resourceDownloadPromise = null;
|
|
2574
|
+
// 检查缓存是否可用(未过期)
|
|
2575
|
+
async function canUseCache() {
|
|
2576
|
+
try {
|
|
2577
|
+
const content = await fs.readFile(CACHE_META_FILE, "utf8");
|
|
2578
|
+
const meta = JSON.parse(content);
|
|
2579
|
+
if (!meta.timestamp) {
|
|
2580
|
+
(0, logger_js_1.debug)("[cache] cache-meta missing timestamp, treating as invalid", {
|
|
2581
|
+
ttlMs: CACHE_TTL_MS,
|
|
2582
|
+
});
|
|
2583
|
+
return false;
|
|
2584
|
+
}
|
|
2585
|
+
const ageMs = Date.now() - meta.timestamp;
|
|
2586
|
+
const isValid = ageMs <= CACHE_TTL_MS;
|
|
2587
|
+
(0, logger_js_1.debug)("[cache] evaluated cache meta", {
|
|
2588
|
+
timestamp: meta.timestamp,
|
|
2589
|
+
ageMs,
|
|
2590
|
+
ttlMs: CACHE_TTL_MS,
|
|
2591
|
+
valid: isValid,
|
|
2592
|
+
});
|
|
2593
|
+
return isValid;
|
|
2594
|
+
}
|
|
2595
|
+
catch (error) {
|
|
2596
|
+
(0, logger_js_1.debug)("[cache] failed to read cache meta, treating as miss", { error });
|
|
2597
|
+
return false;
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
// 更新缓存时间戳
|
|
2601
|
+
async function updateCache() {
|
|
2602
|
+
await fs.mkdir(CACHE_BASE_DIR, { recursive: true });
|
|
2603
|
+
await fs.writeFile(CACHE_META_FILE, JSON.stringify({ timestamp: Date.now() }, null, 2), "utf8");
|
|
2604
|
+
}
|
|
2546
2605
|
// 安全 JSON.parse
|
|
2547
2606
|
function safeParse(str) {
|
|
2548
2607
|
try {
|
|
@@ -2569,31 +2628,141 @@ function safeStringify(obj) {
|
|
|
2569
2628
|
return "";
|
|
2570
2629
|
}
|
|
2571
2630
|
}
|
|
2572
|
-
//
|
|
2573
|
-
|
|
2631
|
+
// OpenAPI 文档 URL 列表
|
|
2632
|
+
const OPENAPI_SOURCES = [
|
|
2633
|
+
{
|
|
2634
|
+
name: "mysqldb",
|
|
2635
|
+
description: "MySQL RESTful API - 云开发 MySQL 数据库 HTTP API",
|
|
2636
|
+
url: "https://docs.cloudbase.net/openapi/mysqldb.v1.openapi.yaml",
|
|
2637
|
+
},
|
|
2638
|
+
{
|
|
2639
|
+
name: "functions",
|
|
2640
|
+
description: "Cloud Functions API - 云函数 HTTP API",
|
|
2641
|
+
url: "https://docs.cloudbase.net/openapi/functions.v1.openapi.yaml",
|
|
2642
|
+
},
|
|
2643
|
+
{
|
|
2644
|
+
name: "auth",
|
|
2645
|
+
description: "Authentication API - 身份认证 HTTP API",
|
|
2646
|
+
url: "https://docs.cloudbase.net/openapi/auth.v1.openapi.yaml",
|
|
2647
|
+
},
|
|
2648
|
+
{
|
|
2649
|
+
name: "cloudrun",
|
|
2650
|
+
description: "CloudRun API - 云托管服务 HTTP API",
|
|
2651
|
+
url: "https://docs.cloudbase.net/openapi/cloudrun.v1.openapi.yaml",
|
|
2652
|
+
},
|
|
2653
|
+
{
|
|
2654
|
+
name: "storage",
|
|
2655
|
+
description: "Storage API - 云存储 HTTP API",
|
|
2656
|
+
url: "https://docs.cloudbase.net/openapi/storage.v1.openapi.yaml",
|
|
2657
|
+
},
|
|
2658
|
+
];
|
|
2574
2659
|
async function downloadWebTemplate() {
|
|
2575
|
-
const
|
|
2576
|
-
const
|
|
2577
|
-
const extractDir = path.join(baseDir, "web-template");
|
|
2660
|
+
const zipPath = path.join(CACHE_BASE_DIR, "web-cloudbase-project.zip");
|
|
2661
|
+
const extractDir = path.join(CACHE_BASE_DIR, "web-template");
|
|
2578
2662
|
const url = "https://static.cloudbase.net/cloudbase-examples/web-cloudbase-project.zip";
|
|
2579
|
-
await fs.mkdir(baseDir, { recursive: true });
|
|
2580
|
-
// Download zip to specified path (overwrite)
|
|
2581
2663
|
const response = await fetch(url);
|
|
2582
2664
|
if (!response.ok) {
|
|
2583
2665
|
throw new Error(`下载模板失败,状态码: ${response.status}`);
|
|
2584
2666
|
}
|
|
2585
2667
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
2586
2668
|
await fs.writeFile(zipPath, buffer);
|
|
2587
|
-
// Clean and recreate extract directory
|
|
2588
2669
|
await fs.rm(extractDir, { recursive: true, force: true });
|
|
2589
2670
|
await fs.mkdir(extractDir, { recursive: true });
|
|
2590
2671
|
const zip = new adm_zip_1.default(zipPath);
|
|
2591
2672
|
zip.extractAllTo(extractDir, true);
|
|
2673
|
+
(0, logger_js_1.debug)("[downloadResources] webTemplate 下载完成");
|
|
2592
2674
|
return extractDir;
|
|
2593
2675
|
}
|
|
2594
|
-
async function
|
|
2595
|
-
const
|
|
2596
|
-
|
|
2676
|
+
async function downloadOpenAPI() {
|
|
2677
|
+
const baseDir = path.join(CACHE_BASE_DIR, "openapi");
|
|
2678
|
+
await fs.mkdir(baseDir, { recursive: true });
|
|
2679
|
+
const results = [];
|
|
2680
|
+
await Promise.all(OPENAPI_SOURCES.map(async (source) => {
|
|
2681
|
+
try {
|
|
2682
|
+
const response = await fetch(source.url);
|
|
2683
|
+
if (!response.ok) {
|
|
2684
|
+
(0, logger_js_1.warn)(`[downloadOpenAPI] Failed to download ${source.name}`, {
|
|
2685
|
+
status: response.status,
|
|
2686
|
+
});
|
|
2687
|
+
return;
|
|
2688
|
+
}
|
|
2689
|
+
const content = await response.text();
|
|
2690
|
+
const filePath = path.join(baseDir, `${source.name}.openapi.yaml`);
|
|
2691
|
+
await fs.writeFile(filePath, content, "utf8");
|
|
2692
|
+
results.push({
|
|
2693
|
+
name: source.name,
|
|
2694
|
+
description: source.description,
|
|
2695
|
+
absolutePath: filePath,
|
|
2696
|
+
});
|
|
2697
|
+
}
|
|
2698
|
+
catch (error) {
|
|
2699
|
+
(0, logger_js_1.warn)(`[downloadOpenAPI] Failed to download ${source.name}`, {
|
|
2700
|
+
error,
|
|
2701
|
+
});
|
|
2702
|
+
}
|
|
2703
|
+
}));
|
|
2704
|
+
(0, logger_js_1.debug)("[downloadOpenAPI] openAPIDocs 下载完成", {
|
|
2705
|
+
successCount: results.length,
|
|
2706
|
+
total: OPENAPI_SOURCES.length,
|
|
2707
|
+
});
|
|
2708
|
+
return results;
|
|
2709
|
+
}
|
|
2710
|
+
// 实际执行下载所有资源的函数(webTemplate 和 openAPI 并发下载)
|
|
2711
|
+
async function _doDownloadResources() {
|
|
2712
|
+
// 并发下载 webTemplate 和 openAPIDocs
|
|
2713
|
+
const [webTemplateDir, openAPIDocs] = await Promise.all([
|
|
2714
|
+
// 下载 web 模板
|
|
2715
|
+
downloadWebTemplate(),
|
|
2716
|
+
// 并发下载所有 OpenAPI 文档
|
|
2717
|
+
downloadOpenAPI(),
|
|
2718
|
+
]);
|
|
2719
|
+
(0, logger_js_1.debug)("[downloadResources] 所有资源下载完成");
|
|
2720
|
+
return { webTemplateDir, openAPIDocs };
|
|
2721
|
+
}
|
|
2722
|
+
// 下载所有资源(带缓存和共享 Promise 机制)
|
|
2723
|
+
async function downloadResources() {
|
|
2724
|
+
const webTemplateDir = path.join(CACHE_BASE_DIR, "web-template");
|
|
2725
|
+
const openAPIDir = path.join(CACHE_BASE_DIR, "openapi");
|
|
2726
|
+
// 检查缓存是否有效
|
|
2727
|
+
if (await canUseCache()) {
|
|
2728
|
+
try {
|
|
2729
|
+
// 检查两个目录都存在
|
|
2730
|
+
await Promise.all([fs.access(webTemplateDir), fs.access(openAPIDir)]);
|
|
2731
|
+
const files = await fs.readdir(openAPIDir);
|
|
2732
|
+
if (files.length > 0) {
|
|
2733
|
+
(0, logger_js_1.debug)("[downloadResources] 使用缓存");
|
|
2734
|
+
return {
|
|
2735
|
+
webTemplateDir,
|
|
2736
|
+
openAPIDocs: OPENAPI_SOURCES.map((source) => ({
|
|
2737
|
+
name: source.name,
|
|
2738
|
+
description: source.description,
|
|
2739
|
+
absolutePath: path.join(openAPIDir, `${source.name}.openapi.yaml`),
|
|
2740
|
+
})).filter((item) => files.includes(`${item.name}.openapi.yaml`)),
|
|
2741
|
+
};
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
catch {
|
|
2745
|
+
// 缓存无效,需要重新下载
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
// 如果已有下载任务在进行中,共享该 Promise
|
|
2749
|
+
if (resourceDownloadPromise) {
|
|
2750
|
+
(0, logger_js_1.debug)("[downloadResources] 共享已有下载任务");
|
|
2751
|
+
return resourceDownloadPromise;
|
|
2752
|
+
}
|
|
2753
|
+
// 创建新的下载任务
|
|
2754
|
+
(0, logger_js_1.debug)("[downloadResources] 开始新下载任务");
|
|
2755
|
+
await fs.mkdir(CACHE_BASE_DIR, { recursive: true });
|
|
2756
|
+
resourceDownloadPromise = _doDownloadResources()
|
|
2757
|
+
.then(async (result) => {
|
|
2758
|
+
await updateCache();
|
|
2759
|
+
(0, logger_js_1.debug)("[downloadResources] 缓存已更新");
|
|
2760
|
+
return result;
|
|
2761
|
+
})
|
|
2762
|
+
.finally(() => {
|
|
2763
|
+
resourceDownloadPromise = null;
|
|
2764
|
+
});
|
|
2765
|
+
return resourceDownloadPromise;
|
|
2597
2766
|
}
|
|
2598
2767
|
// Get CLAUDE.md prompt content
|
|
2599
2768
|
// Priority: 1. From downloaded template, 2. Fallback to embedded constant
|
|
@@ -2717,23 +2886,15 @@ async function registerRagTools(server) {
|
|
|
2717
2886
|
};
|
|
2718
2887
|
}
|
|
2719
2888
|
});
|
|
2720
|
-
let skills = [];
|
|
2721
2889
|
let openapis = [];
|
|
2722
|
-
|
|
2723
|
-
try {
|
|
2724
|
-
skills = await prepareKnowledgeBaseWebTemplate();
|
|
2725
|
-
}
|
|
2726
|
-
catch (error) {
|
|
2727
|
-
(0, logger_js_1.warn)("[searchKnowledgeBase] Failed to prepare web template", {
|
|
2728
|
-
error,
|
|
2729
|
-
});
|
|
2730
|
-
}
|
|
2731
|
-
// OpenAPI 文档准备
|
|
2890
|
+
let skills = [];
|
|
2732
2891
|
try {
|
|
2733
|
-
|
|
2892
|
+
const { webTemplateDir, openAPIDocs } = await downloadResources();
|
|
2893
|
+
openapis = openAPIDocs;
|
|
2894
|
+
skills = await collectSkillDescriptions(path.join(webTemplateDir, ".claude", "skills"));
|
|
2734
2895
|
}
|
|
2735
2896
|
catch (error) {
|
|
2736
|
-
(0, logger_js_1.warn)("[
|
|
2897
|
+
(0, logger_js_1.warn)("[downloadResources] Failed to download resources", {
|
|
2737
2898
|
error,
|
|
2738
2899
|
});
|
|
2739
2900
|
}
|
|
@@ -2900,65 +3061,6 @@ function extractDescriptionFromFrontMatter(content) {
|
|
|
2900
3061
|
.match(/^(?:decsription|description)\s*:\s*(.*)$/m);
|
|
2901
3062
|
return match ? match[1].trim() : null;
|
|
2902
3063
|
}
|
|
2903
|
-
// OpenAPI 文档 URL 列表
|
|
2904
|
-
const OPENAPI_SOURCES = [
|
|
2905
|
-
{
|
|
2906
|
-
name: "mysqldb",
|
|
2907
|
-
description: "MySQL RESTful API - 云开发 MySQL 数据库 HTTP API",
|
|
2908
|
-
url: "https://docs.cloudbase.net/openapi/mysqldb.v1.openapi.yaml",
|
|
2909
|
-
},
|
|
2910
|
-
{
|
|
2911
|
-
name: "functions",
|
|
2912
|
-
description: "Cloud Functions API - 云函数 HTTP API",
|
|
2913
|
-
url: "https://docs.cloudbase.net/openapi/functions.v1.openapi.yaml",
|
|
2914
|
-
},
|
|
2915
|
-
{
|
|
2916
|
-
name: "auth",
|
|
2917
|
-
description: "Authentication API - 身份认证 HTTP API",
|
|
2918
|
-
url: "https://docs.cloudbase.net/openapi/auth.v1.openapi.yaml",
|
|
2919
|
-
},
|
|
2920
|
-
{
|
|
2921
|
-
name: "cloudrun",
|
|
2922
|
-
description: "CloudRun API - 云托管服务 HTTP API",
|
|
2923
|
-
url: "https://docs.cloudbase.net/openapi/cloudrun.v1.openapi.yaml",
|
|
2924
|
-
},
|
|
2925
|
-
{
|
|
2926
|
-
name: "storage",
|
|
2927
|
-
description: "Storage API - 云存储 HTTP API",
|
|
2928
|
-
url: "https://docs.cloudbase.net/openapi/storage.v1.openapi.yaml",
|
|
2929
|
-
},
|
|
2930
|
-
];
|
|
2931
|
-
// 下载并准备 OpenAPI 文档
|
|
2932
|
-
async function prepareOpenAPIDocs() {
|
|
2933
|
-
const baseDir = path.join(os.homedir(), ".cloudbase-mcp", "openapi");
|
|
2934
|
-
await fs.mkdir(baseDir, { recursive: true });
|
|
2935
|
-
const results = [];
|
|
2936
|
-
await Promise.all(OPENAPI_SOURCES.map(async (source) => {
|
|
2937
|
-
try {
|
|
2938
|
-
const response = await fetch(source.url);
|
|
2939
|
-
if (!response.ok) {
|
|
2940
|
-
(0, logger_js_1.warn)(`[prepareOpenAPIDocs] Failed to download ${source.name}`, {
|
|
2941
|
-
status: response.status,
|
|
2942
|
-
});
|
|
2943
|
-
return;
|
|
2944
|
-
}
|
|
2945
|
-
const content = await response.text();
|
|
2946
|
-
const filePath = path.join(baseDir, `${source.name}.openapi.yaml`);
|
|
2947
|
-
await fs.writeFile(filePath, content, "utf8");
|
|
2948
|
-
results.push({
|
|
2949
|
-
name: source.name,
|
|
2950
|
-
description: source.description,
|
|
2951
|
-
absolutePath: filePath,
|
|
2952
|
-
});
|
|
2953
|
-
}
|
|
2954
|
-
catch (error) {
|
|
2955
|
-
(0, logger_js_1.warn)(`[prepareOpenAPIDocs] Failed to download ${source.name}`, {
|
|
2956
|
-
error,
|
|
2957
|
-
});
|
|
2958
|
-
}
|
|
2959
|
-
}));
|
|
2960
|
-
return results;
|
|
2961
|
-
}
|
|
2962
3064
|
async function collectSkillDescriptions(rootDir) {
|
|
2963
3065
|
const result = [];
|
|
2964
3066
|
async function walk(dir) {
|
|
@@ -3128,6 +3230,7 @@ function registerEnvTools(server) {
|
|
|
3128
3230
|
Channels: ['dcloud', 'iotenable', 'tem', 'scene_module'] // Filter special channels
|
|
3129
3231
|
}
|
|
3130
3232
|
});
|
|
3233
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3131
3234
|
// Transform response format to match original listEnvs() format
|
|
3132
3235
|
if (result && result.EnvList) {
|
|
3133
3236
|
result = { EnvList: result.EnvList };
|
|
@@ -3139,6 +3242,7 @@ function registerEnvTools(server) {
|
|
|
3139
3242
|
// Fallback to original method if format is unexpected
|
|
3140
3243
|
(0, logger_js_1.debug)('Unexpected response format, falling back to listEnvs()');
|
|
3141
3244
|
result = await cloudbaseList.env.listEnvs();
|
|
3245
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3142
3246
|
}
|
|
3143
3247
|
}
|
|
3144
3248
|
catch (error) {
|
|
@@ -3147,10 +3251,12 @@ function registerEnvTools(server) {
|
|
|
3147
3251
|
try {
|
|
3148
3252
|
const cloudbaseList = await (0, cloudbase_manager_js_1.getCloudBaseManager)({ cloudBaseOptions, requireEnvId: true });
|
|
3149
3253
|
result = await cloudbaseList.env.listEnvs();
|
|
3254
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3150
3255
|
}
|
|
3151
3256
|
catch (fallbackError) {
|
|
3152
3257
|
(0, logger_js_1.debug)('降级到 listEnvs() 也失败:', fallbackError);
|
|
3153
|
-
return {
|
|
3258
|
+
return {
|
|
3259
|
+
content: [{ type: "text", text: "获取环境列表时出错: " + (fallbackError instanceof Error ? fallbackError.message : String(fallbackError)) }]
|
|
3154
3260
|
};
|
|
3155
3261
|
}
|
|
3156
3262
|
}
|
|
@@ -3158,14 +3264,17 @@ function registerEnvTools(server) {
|
|
|
3158
3264
|
case "info":
|
|
3159
3265
|
const cloudbaseInfo = await getManager();
|
|
3160
3266
|
result = await cloudbaseInfo.env.getEnvInfo();
|
|
3267
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3161
3268
|
break;
|
|
3162
3269
|
case "domains":
|
|
3163
3270
|
const cloudbaseDomains = await getManager();
|
|
3164
3271
|
result = await cloudbaseDomains.env.getEnvAuthDomains();
|
|
3272
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3165
3273
|
break;
|
|
3166
3274
|
case "hosting":
|
|
3167
3275
|
const cloudbaseHosting = await getManager();
|
|
3168
3276
|
result = await cloudbaseHosting.hosting.getWebsiteConfig();
|
|
3277
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3169
3278
|
break;
|
|
3170
3279
|
default:
|
|
3171
3280
|
throw new Error(`不支持的查询类型: ${action}`);
|
|
@@ -3223,9 +3332,11 @@ function registerEnvTools(server) {
|
|
|
3223
3332
|
switch (action) {
|
|
3224
3333
|
case "create":
|
|
3225
3334
|
result = await cloudbase.env.createEnvDomain(domains);
|
|
3335
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3226
3336
|
break;
|
|
3227
3337
|
case "delete":
|
|
3228
3338
|
result = await cloudbase.env.deleteEnvDomain(domains);
|
|
3339
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3229
3340
|
break;
|
|
3230
3341
|
default:
|
|
3231
3342
|
throw new Error(`不支持的操作类型: ${action}`);
|
|
@@ -3305,8 +3416,10 @@ function registerHostingTools(server) {
|
|
|
3305
3416
|
files,
|
|
3306
3417
|
ignore
|
|
3307
3418
|
});
|
|
3419
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3308
3420
|
// 获取环境信息
|
|
3309
3421
|
const envInfo = await cloudbase.env.getEnvInfo();
|
|
3422
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, envInfo);
|
|
3310
3423
|
const staticDomain = envInfo.EnvInfo?.StaticStorages?.[0]?.StaticDomain;
|
|
3311
3424
|
const accessUrl = staticDomain ? `https://${staticDomain}/${cloudPath || ''}` : "";
|
|
3312
3425
|
// Send deployment notification to CodeBuddy IDE
|
|
@@ -3380,6 +3493,7 @@ function registerHostingTools(server) {
|
|
|
3380
3493
|
cloudPath,
|
|
3381
3494
|
isDir
|
|
3382
3495
|
});
|
|
3496
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3383
3497
|
return {
|
|
3384
3498
|
content: [
|
|
3385
3499
|
{
|
|
@@ -3410,6 +3524,7 @@ function registerHostingTools(server) {
|
|
|
3410
3524
|
marker,
|
|
3411
3525
|
maxKeys
|
|
3412
3526
|
});
|
|
3527
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3413
3528
|
return {
|
|
3414
3529
|
content: [
|
|
3415
3530
|
{
|
|
@@ -3475,6 +3590,7 @@ function registerHostingTools(server) {
|
|
|
3475
3590
|
domain,
|
|
3476
3591
|
certId
|
|
3477
3592
|
});
|
|
3593
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3478
3594
|
break;
|
|
3479
3595
|
case "delete":
|
|
3480
3596
|
if (!domain) {
|
|
@@ -3483,6 +3599,7 @@ function registerHostingTools(server) {
|
|
|
3483
3599
|
result = await cloudbase.hosting.deleteHostingDomain({
|
|
3484
3600
|
domain
|
|
3485
3601
|
});
|
|
3602
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3486
3603
|
break;
|
|
3487
3604
|
case "check":
|
|
3488
3605
|
if (!domains || domains.length === 0) {
|
|
@@ -3491,6 +3608,7 @@ function registerHostingTools(server) {
|
|
|
3491
3608
|
result = await cloudbase.hosting.tcbCheckResource({
|
|
3492
3609
|
domains
|
|
3493
3610
|
});
|
|
3611
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3494
3612
|
break;
|
|
3495
3613
|
case "modify":
|
|
3496
3614
|
if (!domain || domainId === undefined || !domainConfig) {
|
|
@@ -3501,6 +3619,7 @@ function registerHostingTools(server) {
|
|
|
3501
3619
|
domainId,
|
|
3502
3620
|
domainConfig
|
|
3503
3621
|
});
|
|
3622
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3504
3623
|
break;
|
|
3505
3624
|
default:
|
|
3506
3625
|
throw new Error(`不支持的操作类型: ${action}`);
|
|
@@ -3594,6 +3713,7 @@ function registerGatewayTools(server) {
|
|
|
3594
3713
|
name,
|
|
3595
3714
|
path
|
|
3596
3715
|
});
|
|
3716
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
3597
3717
|
return {
|
|
3598
3718
|
content: [
|
|
3599
3719
|
{
|
|
@@ -6179,11 +6299,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6179
6299
|
};
|
|
6180
6300
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
6181
6301
|
exports.wrapServerWithTelemetry = wrapServerWithTelemetry;
|
|
6182
|
-
const
|
|
6183
|
-
const logger_js_1 = __webpack_require__(39);
|
|
6302
|
+
const os_1 = __importDefault(__webpack_require__(116));
|
|
6184
6303
|
const cloudbase_manager_js_1 = __webpack_require__(431);
|
|
6185
6304
|
const cloud_mode_js_1 = __webpack_require__(684);
|
|
6186
|
-
const
|
|
6305
|
+
const logger_js_1 = __webpack_require__(39);
|
|
6306
|
+
const telemetry_js_1 = __webpack_require__(880);
|
|
6187
6307
|
/**
|
|
6188
6308
|
* 生成 GitHub Issue 创建链接
|
|
6189
6309
|
* @param toolName 工具名称
|
|
@@ -6224,7 +6344,7 @@ ${envIdSection}
|
|
|
6224
6344
|
## 环境信息
|
|
6225
6345
|
- 操作系统: ${os_1.default.type()} ${os_1.default.release()}
|
|
6226
6346
|
- Node.js版本: ${process.version}
|
|
6227
|
-
- MCP 版本:${process.env.npm_package_version || "2.
|
|
6347
|
+
- MCP 版本:${process.env.npm_package_version || "2.4.0-alpha.0" || 0}
|
|
6228
6348
|
- 系统架构: ${os_1.default.arch()}
|
|
6229
6349
|
- 时间: ${new Date().toISOString()}
|
|
6230
6350
|
- 请求ID: ${requestId}
|
|
@@ -6262,10 +6382,13 @@ function createWrappedHandler(name, handler, server) {
|
|
|
6262
6382
|
let requestId;
|
|
6263
6383
|
try {
|
|
6264
6384
|
(0, logger_js_1.debug)(`开始执行工具: ${name}`, { args: sanitizeArgs(args) });
|
|
6385
|
+
server.logger?.({ type: 'beforeToolCall', toolName: name, args: sanitizeArgs(args) });
|
|
6265
6386
|
// 执行原始处理函数
|
|
6266
6387
|
const result = await handler(args);
|
|
6267
6388
|
success = true;
|
|
6268
|
-
|
|
6389
|
+
const duration = Date.now() - startTime;
|
|
6390
|
+
(0, logger_js_1.debug)(`工具执行成功: ${name}`, { duration });
|
|
6391
|
+
server.logger?.({ type: 'afterToolCall', toolName: name, args: sanitizeArgs(args), result: result, duration });
|
|
6269
6392
|
return result;
|
|
6270
6393
|
}
|
|
6271
6394
|
catch (error) {
|
|
@@ -6276,6 +6399,7 @@ function createWrappedHandler(name, handler, server) {
|
|
|
6276
6399
|
error: errorMessage,
|
|
6277
6400
|
duration: Date.now() - startTime
|
|
6278
6401
|
});
|
|
6402
|
+
server.logger?.({ type: 'errorToolCall', toolName: name, args: sanitizeArgs(args), message: errorMessage, duration: Date.now() - startTime });
|
|
6279
6403
|
// 生成 GitHub Issue 创建链接
|
|
6280
6404
|
const issueLink = await generateGitHubIssueLink(name, errorMessage, args, server.cloudBaseOptions, {
|
|
6281
6405
|
requestId: (typeof error === 'object' && error && 'requestId' in error) ? error.requestId : '',
|
|
@@ -6419,6 +6543,7 @@ function registerSQLDatabaseTools(server) {
|
|
|
6419
6543
|
},
|
|
6420
6544
|
},
|
|
6421
6545
|
});
|
|
6546
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
6422
6547
|
return {
|
|
6423
6548
|
content: [
|
|
6424
6549
|
{
|
|
@@ -6482,6 +6607,7 @@ function registerSQLDatabaseTools(server) {
|
|
|
6482
6607
|
},
|
|
6483
6608
|
},
|
|
6484
6609
|
});
|
|
6610
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
6485
6611
|
return {
|
|
6486
6612
|
content: [
|
|
6487
6613
|
{
|
|
@@ -6635,7 +6761,7 @@ function parseEnabledPlugins() {
|
|
|
6635
6761
|
* await server.connect(transport);
|
|
6636
6762
|
*/
|
|
6637
6763
|
async function createCloudBaseMcpServer(options) {
|
|
6638
|
-
const { name = "cloudbase-mcp", version = "1.0.0", enableTelemetry = true, cloudBaseOptions, cloudMode = false, ide, } = options ?? {};
|
|
6764
|
+
const { name = "cloudbase-mcp", version = "1.0.0", enableTelemetry = true, cloudBaseOptions, cloudMode = false, ide, logger, } = options ?? {};
|
|
6639
6765
|
// Enable cloud mode if specified
|
|
6640
6766
|
if (cloudMode) {
|
|
6641
6767
|
(0, cloud_mode_js_1.enableCloudMode)();
|
|
@@ -6665,6 +6791,10 @@ async function createCloudBaseMcpServer(options) {
|
|
|
6665
6791
|
if (ide) {
|
|
6666
6792
|
server.ide = ide;
|
|
6667
6793
|
}
|
|
6794
|
+
// Store logger in server instance for tools to access
|
|
6795
|
+
if (logger) {
|
|
6796
|
+
server.logger = logger;
|
|
6797
|
+
}
|
|
6668
6798
|
// Enable telemetry if requested
|
|
6669
6799
|
if (enableTelemetry) {
|
|
6670
6800
|
(0, tool_wrapper_js_1.wrapServerWithTelemetry)(server);
|
|
@@ -6712,6 +6842,8 @@ exports.getEnvId = getEnvId;
|
|
|
6712
6842
|
exports.resetCloudBaseManagerCache = resetCloudBaseManagerCache;
|
|
6713
6843
|
exports.getCloudBaseManager = getCloudBaseManager;
|
|
6714
6844
|
exports.createCloudBaseManagerWithOptions = createCloudBaseManagerWithOptions;
|
|
6845
|
+
exports.extractRequestId = extractRequestId;
|
|
6846
|
+
exports.logCloudBaseResult = logCloudBaseResult;
|
|
6715
6847
|
const manager_node_1 = __importDefault(__webpack_require__(665));
|
|
6716
6848
|
const auth_js_1 = __webpack_require__(291);
|
|
6717
6849
|
const interactive_js_1 = __webpack_require__(461);
|
|
@@ -6874,6 +7006,39 @@ function createCloudBaseManagerWithOptions(cloudBaseOptions) {
|
|
|
6874
7006
|
});
|
|
6875
7007
|
return manager;
|
|
6876
7008
|
}
|
|
7009
|
+
/**
|
|
7010
|
+
* Extract RequestId from result object
|
|
7011
|
+
*/
|
|
7012
|
+
function extractRequestId(result) {
|
|
7013
|
+
if (!result || typeof result !== 'object') {
|
|
7014
|
+
return undefined;
|
|
7015
|
+
}
|
|
7016
|
+
// Try common RequestId field names
|
|
7017
|
+
if ('RequestId' in result && result.RequestId) {
|
|
7018
|
+
return String(result.RequestId);
|
|
7019
|
+
}
|
|
7020
|
+
if ('requestId' in result && result.requestId) {
|
|
7021
|
+
return String(result.requestId);
|
|
7022
|
+
}
|
|
7023
|
+
if ('request_id' in result && result.request_id) {
|
|
7024
|
+
return String(result.request_id);
|
|
7025
|
+
}
|
|
7026
|
+
return undefined;
|
|
7027
|
+
}
|
|
7028
|
+
/**
|
|
7029
|
+
* Log CloudBase manager call result with RequestId
|
|
7030
|
+
*/
|
|
7031
|
+
function logCloudBaseResult(logger, result) {
|
|
7032
|
+
if (!logger) {
|
|
7033
|
+
return;
|
|
7034
|
+
}
|
|
7035
|
+
const requestId = extractRequestId(result);
|
|
7036
|
+
logger({
|
|
7037
|
+
type: 'capiResult',
|
|
7038
|
+
requestId,
|
|
7039
|
+
result,
|
|
7040
|
+
});
|
|
7041
|
+
}
|
|
6877
7042
|
|
|
6878
7043
|
|
|
6879
7044
|
/***/ }),
|
|
@@ -7000,6 +7165,7 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, server) {
|
|
|
7000
7165
|
Channels: ['dcloud', 'iotenable', 'tem', 'scene_module'] // Filter special channels
|
|
7001
7166
|
}
|
|
7002
7167
|
});
|
|
7168
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server?.logger, envResult);
|
|
7003
7169
|
// Transform response format to match original listEnvs() format
|
|
7004
7170
|
if (envResult && envResult.EnvList) {
|
|
7005
7171
|
envResult = { EnvList: envResult.EnvList };
|
|
@@ -7011,6 +7177,7 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, server) {
|
|
|
7011
7177
|
// Fallback to original method if format is unexpected
|
|
7012
7178
|
(0, logger_js_1.debug)('Unexpected response format, falling back to listEnvs()');
|
|
7013
7179
|
envResult = await cloudbase.env.listEnvs();
|
|
7180
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server?.logger, envResult);
|
|
7014
7181
|
}
|
|
7015
7182
|
}
|
|
7016
7183
|
catch (error) {
|
|
@@ -7018,6 +7185,7 @@ async function _promptAndSetEnvironmentId(autoSelectSingle, server) {
|
|
|
7018
7185
|
// Fallback to original method on error
|
|
7019
7186
|
try {
|
|
7020
7187
|
envResult = await cloudbase.env.listEnvs();
|
|
7188
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server?.logger, envResult);
|
|
7021
7189
|
}
|
|
7022
7190
|
catch (fallbackError) {
|
|
7023
7191
|
(0, logger_js_1.debug)('降级到 listEnvs() 也失败:', fallbackError);
|
|
@@ -7167,6 +7335,7 @@ const IDE_TYPES = [
|
|
|
7167
7335
|
"qoder", // Qoder AI编辑器
|
|
7168
7336
|
"antigravity", // Google Antigravity AI编辑器
|
|
7169
7337
|
"vscode", // Visual Studio Code
|
|
7338
|
+
"kiro", // Kiro AI编辑器
|
|
7170
7339
|
];
|
|
7171
7340
|
// IDE到文件的映射关系
|
|
7172
7341
|
// 注意:以 "/" 结尾的路径表示目录,会包含该目录下的所有文件
|
|
@@ -7200,6 +7369,7 @@ const IDE_FILE_MAPPINGS = {
|
|
|
7200
7369
|
qoder: [".qoder/rules/"],
|
|
7201
7370
|
antigravity: [".agent/rules/"],
|
|
7202
7371
|
vscode: [".vscode/mcp.json", ".vscode/settings.json"],
|
|
7372
|
+
kiro: [".kiro/settings/mcp.json", ".kiro/steering/"],
|
|
7203
7373
|
};
|
|
7204
7374
|
// 所有IDE配置文件的完整列表 - 通过IDE_FILE_MAPPINGS计算得出
|
|
7205
7375
|
const ALL_IDE_FILES = Array.from(new Set(Object.values(IDE_FILE_MAPPINGS).flat()));
|
|
@@ -7226,6 +7396,7 @@ const IDE_DESCRIPTIONS = {
|
|
|
7226
7396
|
qoder: "Qoder AI编辑器",
|
|
7227
7397
|
antigravity: "Google Antigravity AI编辑器",
|
|
7228
7398
|
vscode: "Visual Studio Code",
|
|
7399
|
+
kiro: "Kiro AI编辑器",
|
|
7229
7400
|
};
|
|
7230
7401
|
// INTEGRATION_IDE 环境变量值到 IDE 类型的映射
|
|
7231
7402
|
const INTEGRATION_IDE_MAPPING = {
|
|
@@ -7249,6 +7420,7 @@ const INTEGRATION_IDE_MAPPING = {
|
|
|
7249
7420
|
Qoder: "qoder",
|
|
7250
7421
|
Antigravity: "antigravity",
|
|
7251
7422
|
VSCode: "vscode",
|
|
7423
|
+
Kiro: "kiro",
|
|
7252
7424
|
};
|
|
7253
7425
|
// 根据 INTEGRATION_IDE 环境变量获取默认 IDE 类型
|
|
7254
7426
|
function getDefaultIDEFromEnv() {
|
|
@@ -7471,7 +7643,7 @@ function registerSetupTools(server) {
|
|
|
7471
7643
|
title: "下载项目模板",
|
|
7472
7644
|
description: `自动下载并部署CloudBase项目模板。⚠️ **MANDATORY FOR NEW PROJECTS** ⚠️
|
|
7473
7645
|
|
|
7474
|
-
**CRITICAL**: This tool MUST be called FIRST when starting a new project.\n\n支持的模板:\n- react: React + CloudBase 全栈应用模板\n- vue: Vue + CloudBase 全栈应用模板\n- miniprogram: 微信小程序 + 云开发模板 \n- uniapp: UniApp + CloudBase 跨端应用模板\n- rules: 只包含AI编辑器配置文件(包含Cursor、WindSurf、CodeBuddy等所有主流编辑器配置),适合在已有项目中补充AI编辑器配置\n\n支持的IDE类型:\n- all: 下载所有IDE配置(默认)\n- cursor: Cursor AI编辑器\n- windsurf: WindSurf AI编辑器\n- codebuddy: CodeBuddy AI编辑器\n- claude-code: Claude Code AI编辑器\n- cline: Cline AI编辑器\n- gemini-cli: Gemini CLI\n- opencode: OpenCode AI编辑器\n- qwen-code: 通义灵码\n- baidu-comate: 百度Comate\n- openai-codex-cli: OpenAI Codex CLI\n- augment-code: Augment Code\n- github-copilot: GitHub Copilot\n- roocode: RooCode AI编辑器\n- tongyi-lingma: 通义灵码\n- trae: Trae AI编辑器\n- qoder: Qoder AI编辑器\n- antigravity: Google Antigravity AI编辑器\n- vscode: Visual Studio Code\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "2.
|
|
7646
|
+
**CRITICAL**: This tool MUST be called FIRST when starting a new project.\n\n支持的模板:\n- react: React + CloudBase 全栈应用模板\n- vue: Vue + CloudBase 全栈应用模板\n- miniprogram: 微信小程序 + 云开发模板 \n- uniapp: UniApp + CloudBase 跨端应用模板\n- rules: 只包含AI编辑器配置文件(包含Cursor、WindSurf、CodeBuddy等所有主流编辑器配置),适合在已有项目中补充AI编辑器配置\n\n支持的IDE类型:\n- all: 下载所有IDE配置(默认)\n- cursor: Cursor AI编辑器\n- windsurf: WindSurf AI编辑器\n- codebuddy: CodeBuddy AI编辑器\n- claude-code: Claude Code AI编辑器\n- cline: Cline AI编辑器\n- gemini-cli: Gemini CLI\n- opencode: OpenCode AI编辑器\n- qwen-code: 通义灵码\n- baidu-comate: 百度Comate\n- openai-codex-cli: OpenAI Codex CLI\n- augment-code: Augment Code\n- github-copilot: GitHub Copilot\n- roocode: RooCode AI编辑器\n- tongyi-lingma: 通义灵码\n- trae: Trae AI编辑器\n- qoder: Qoder AI编辑器\n- antigravity: Google Antigravity AI编辑器\n- vscode: Visual Studio Code\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "2.4.0-alpha.0" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
|
|
7475
7647
|
inputSchema: {
|
|
7476
7648
|
template: zod_1.z
|
|
7477
7649
|
.enum(["react", "vue", "miniprogram", "uniapp", "rules"])
|
|
@@ -7851,6 +8023,7 @@ function registerInviteCodeTools(server) {
|
|
|
7851
8023
|
Action: 'ActivateInviteCode',
|
|
7852
8024
|
Param: { InviteCode, EnvId }
|
|
7853
8025
|
});
|
|
8026
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
7854
8027
|
return {
|
|
7855
8028
|
content: [
|
|
7856
8029
|
{
|
|
@@ -8254,6 +8427,7 @@ function registerSecurityRuleTools(server) {
|
|
|
8254
8427
|
EnvId: envId,
|
|
8255
8428
|
},
|
|
8256
8429
|
});
|
|
8430
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8257
8431
|
}
|
|
8258
8432
|
else if (resourceType === "function") {
|
|
8259
8433
|
// 查询云函数安全规则
|
|
@@ -8264,6 +8438,7 @@ function registerSecurityRuleTools(server) {
|
|
|
8264
8438
|
EnvId: envId,
|
|
8265
8439
|
},
|
|
8266
8440
|
});
|
|
8441
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8267
8442
|
}
|
|
8268
8443
|
else if (resourceType === "storage") {
|
|
8269
8444
|
// 查询存储安全规则
|
|
@@ -8274,6 +8449,7 @@ function registerSecurityRuleTools(server) {
|
|
|
8274
8449
|
EnvId: envId,
|
|
8275
8450
|
},
|
|
8276
8451
|
});
|
|
8452
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8277
8453
|
}
|
|
8278
8454
|
else if (resourceType === "sqlDatabase") {
|
|
8279
8455
|
// TODO: 考虑是否有支持指定其他 instance、schema 的需求
|
|
@@ -8289,6 +8465,7 @@ function registerSecurityRuleTools(server) {
|
|
|
8289
8465
|
RoleIdentityList: ["allUser"],
|
|
8290
8466
|
},
|
|
8291
8467
|
});
|
|
8468
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8292
8469
|
}
|
|
8293
8470
|
else {
|
|
8294
8471
|
throw new Error(`不支持的资源类型: ${resourceType}`);
|
|
@@ -8365,6 +8542,7 @@ function registerSecurityRuleTools(server) {
|
|
|
8365
8542
|
Rule: rule,
|
|
8366
8543
|
},
|
|
8367
8544
|
});
|
|
8545
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8368
8546
|
}
|
|
8369
8547
|
else {
|
|
8370
8548
|
result = await cloudbase.commonService().call({
|
|
@@ -8375,6 +8553,7 @@ function registerSecurityRuleTools(server) {
|
|
|
8375
8553
|
AclTag: aclTag,
|
|
8376
8554
|
},
|
|
8377
8555
|
});
|
|
8556
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8378
8557
|
}
|
|
8379
8558
|
}
|
|
8380
8559
|
else if (resourceType === "function") {
|
|
@@ -8391,6 +8570,7 @@ function registerSecurityRuleTools(server) {
|
|
|
8391
8570
|
Rule: rule,
|
|
8392
8571
|
},
|
|
8393
8572
|
});
|
|
8573
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8394
8574
|
}
|
|
8395
8575
|
else if (resourceType === "storage") {
|
|
8396
8576
|
if (aclTag === "CUSTOM") {
|
|
@@ -8405,6 +8585,7 @@ function registerSecurityRuleTools(server) {
|
|
|
8405
8585
|
Rule: rule,
|
|
8406
8586
|
},
|
|
8407
8587
|
});
|
|
8588
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8408
8589
|
}
|
|
8409
8590
|
else {
|
|
8410
8591
|
result = await cloudbase.commonService().call({
|
|
@@ -8415,6 +8596,7 @@ function registerSecurityRuleTools(server) {
|
|
|
8415
8596
|
AclTag: aclTag,
|
|
8416
8597
|
},
|
|
8417
8598
|
});
|
|
8599
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8418
8600
|
}
|
|
8419
8601
|
}
|
|
8420
8602
|
else if (resourceType === "sqlDatabase") {
|
|
@@ -8447,6 +8629,7 @@ function registerSecurityRuleTools(server) {
|
|
|
8447
8629
|
PolicyList: policyList,
|
|
8448
8630
|
},
|
|
8449
8631
|
});
|
|
8632
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8450
8633
|
function getRowPermission(policy) {
|
|
8451
8634
|
return {
|
|
8452
8635
|
READONLY: [
|
|
@@ -8569,7 +8752,7 @@ class TelemetryReporter {
|
|
|
8569
8752
|
const nodeVersion = process.version; // Node.js版本
|
|
8570
8753
|
const arch = os_1.default.arch(); // 系统架构
|
|
8571
8754
|
// 从构建时注入的版本号获取MCP版本信息
|
|
8572
|
-
const mcpVersion = process.env.npm_package_version || "2.
|
|
8755
|
+
const mcpVersion = process.env.npm_package_version || "2.4.0-alpha.0" || 0;
|
|
8573
8756
|
return {
|
|
8574
8757
|
userAgent: `${osType} ${osRelease} ${arch} ${nodeVersion} CloudBase-MCP/${mcpVersion}`,
|
|
8575
8758
|
deviceId: this.deviceId,
|
|
@@ -8835,6 +9018,7 @@ async function getDatabaseInstanceId(getManager) {
|
|
|
8835
9018
|
function registerDatabaseTools(server) {
|
|
8836
9019
|
// 获取 cloudBaseOptions,如果没有则为 undefined
|
|
8837
9020
|
const cloudBaseOptions = server.cloudBaseOptions;
|
|
9021
|
+
const logger = server.logger;
|
|
8838
9022
|
// 创建闭包函数来获取 CloudBase Manager
|
|
8839
9023
|
const getManager = () => (0, cloudbase_manager_js_1.getCloudBaseManager)({ cloudBaseOptions });
|
|
8840
9024
|
// readNoSqlDatabaseStructure
|
|
@@ -8882,6 +9066,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
8882
9066
|
MgoOffset: offset,
|
|
8883
9067
|
MgoLimit: limit,
|
|
8884
9068
|
});
|
|
9069
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8885
9070
|
return {
|
|
8886
9071
|
content: [
|
|
8887
9072
|
{
|
|
@@ -8902,6 +9087,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
8902
9087
|
throw new Error("检查集合时必须提供 collectionName");
|
|
8903
9088
|
}
|
|
8904
9089
|
const result = await cloudbase.database.checkCollectionExists(collectionName);
|
|
9090
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8905
9091
|
return {
|
|
8906
9092
|
content: [
|
|
8907
9093
|
{
|
|
@@ -8923,6 +9109,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
8923
9109
|
throw new Error("查看集合详情时必须提供 collectionName");
|
|
8924
9110
|
}
|
|
8925
9111
|
const result = await cloudbase.database.describeCollection(collectionName);
|
|
9112
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8926
9113
|
return {
|
|
8927
9114
|
content: [
|
|
8928
9115
|
{
|
|
@@ -8943,6 +9130,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
8943
9130
|
throw new Error("获取索引列表时必须提供 collectionName");
|
|
8944
9131
|
}
|
|
8945
9132
|
const result = await cloudbase.database.describeCollection(collectionName);
|
|
9133
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8946
9134
|
return {
|
|
8947
9135
|
content: [
|
|
8948
9136
|
{
|
|
@@ -8963,6 +9151,7 @@ checkIndex: 检查索引是否存在`),
|
|
|
8963
9151
|
throw new Error("检查索引时必须提供 collectionName 和 indexName");
|
|
8964
9152
|
}
|
|
8965
9153
|
const result = await cloudbase.database.checkIndexExists(collectionName, indexName);
|
|
9154
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
8966
9155
|
return {
|
|
8967
9156
|
content: [
|
|
8968
9157
|
{
|
|
@@ -9023,6 +9212,7 @@ updateCollection: 更新集合`),
|
|
|
9023
9212
|
const cloudbase = await getManager();
|
|
9024
9213
|
if (action === "createCollection") {
|
|
9025
9214
|
const result = await cloudbase.database.createCollection(collectionName);
|
|
9215
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9026
9216
|
return {
|
|
9027
9217
|
content: [
|
|
9028
9218
|
{
|
|
@@ -9042,6 +9232,7 @@ updateCollection: 更新集合`),
|
|
|
9042
9232
|
throw new Error("更新集合时必须提供 options");
|
|
9043
9233
|
}
|
|
9044
9234
|
const result = await cloudbase.database.updateCollection(collectionName, updateOptions);
|
|
9235
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9045
9236
|
return {
|
|
9046
9237
|
content: [
|
|
9047
9238
|
{
|
|
@@ -9118,6 +9309,7 @@ updateCollection: 更新集合`),
|
|
|
9118
9309
|
Tag: instanceId,
|
|
9119
9310
|
},
|
|
9120
9311
|
});
|
|
9312
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9121
9313
|
return {
|
|
9122
9314
|
content: [
|
|
9123
9315
|
{
|
|
@@ -9195,6 +9387,7 @@ deleteCollection: 删除数据`),
|
|
|
9195
9387
|
collectionName,
|
|
9196
9388
|
documents,
|
|
9197
9389
|
getManager,
|
|
9390
|
+
logger,
|
|
9198
9391
|
});
|
|
9199
9392
|
return {
|
|
9200
9393
|
content: [
|
|
@@ -9219,6 +9412,7 @@ deleteCollection: 删除数据`),
|
|
|
9219
9412
|
isMulti,
|
|
9220
9413
|
upsert,
|
|
9221
9414
|
getManager,
|
|
9415
|
+
logger,
|
|
9222
9416
|
});
|
|
9223
9417
|
return {
|
|
9224
9418
|
content: [
|
|
@@ -9238,6 +9432,7 @@ deleteCollection: 删除数据`),
|
|
|
9238
9432
|
query,
|
|
9239
9433
|
isMulti,
|
|
9240
9434
|
getManager,
|
|
9435
|
+
logger,
|
|
9241
9436
|
});
|
|
9242
9437
|
return {
|
|
9243
9438
|
content: [
|
|
@@ -9251,7 +9446,7 @@ deleteCollection: 删除数据`),
|
|
|
9251
9446
|
throw new Error(`不支持的操作类型: ${action}`);
|
|
9252
9447
|
});
|
|
9253
9448
|
}
|
|
9254
|
-
async function insertDocuments({ collectionName, documents, getManager, }) {
|
|
9449
|
+
async function insertDocuments({ collectionName, documents, getManager, logger, }) {
|
|
9255
9450
|
try {
|
|
9256
9451
|
const cloudbase = await getManager();
|
|
9257
9452
|
const instanceId = await getDatabaseInstanceId(getManager);
|
|
@@ -9265,6 +9460,7 @@ async function insertDocuments({ collectionName, documents, getManager, }) {
|
|
|
9265
9460
|
Tag: instanceId,
|
|
9266
9461
|
},
|
|
9267
9462
|
});
|
|
9463
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(logger, result);
|
|
9268
9464
|
return JSON.stringify({
|
|
9269
9465
|
success: true,
|
|
9270
9466
|
requestId: result.RequestId,
|
|
@@ -9280,7 +9476,7 @@ async function insertDocuments({ collectionName, documents, getManager, }) {
|
|
|
9280
9476
|
}, null, 2);
|
|
9281
9477
|
}
|
|
9282
9478
|
}
|
|
9283
|
-
async function updateDocuments({ collectionName, query, update, isMulti, upsert, getManager, }) {
|
|
9479
|
+
async function updateDocuments({ collectionName, query, update, isMulti, upsert, getManager, logger, }) {
|
|
9284
9480
|
try {
|
|
9285
9481
|
const cloudbase = await getManager();
|
|
9286
9482
|
const instanceId = await getDatabaseInstanceId(getManager);
|
|
@@ -9296,6 +9492,7 @@ async function updateDocuments({ collectionName, query, update, isMulti, upsert,
|
|
|
9296
9492
|
Tag: instanceId,
|
|
9297
9493
|
},
|
|
9298
9494
|
});
|
|
9495
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(logger, result);
|
|
9299
9496
|
return JSON.stringify({
|
|
9300
9497
|
success: true,
|
|
9301
9498
|
requestId: result.RequestId,
|
|
@@ -9313,7 +9510,7 @@ async function updateDocuments({ collectionName, query, update, isMulti, upsert,
|
|
|
9313
9510
|
}, null, 2);
|
|
9314
9511
|
}
|
|
9315
9512
|
}
|
|
9316
|
-
async function deleteDocuments({ collectionName, query, isMulti, getManager, }) {
|
|
9513
|
+
async function deleteDocuments({ collectionName, query, isMulti, getManager, logger, }) {
|
|
9317
9514
|
try {
|
|
9318
9515
|
const cloudbase = await getManager();
|
|
9319
9516
|
const instanceId = await getDatabaseInstanceId(getManager);
|
|
@@ -9327,6 +9524,7 @@ async function deleteDocuments({ collectionName, query, isMulti, getManager, })
|
|
|
9327
9524
|
Tag: instanceId,
|
|
9328
9525
|
},
|
|
9329
9526
|
});
|
|
9527
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(logger, result);
|
|
9330
9528
|
return JSON.stringify({
|
|
9331
9529
|
success: true,
|
|
9332
9530
|
requestId: result.RequestId,
|
|
@@ -9437,6 +9635,7 @@ function registerFunctionTools(server) {
|
|
|
9437
9635
|
const cloudbase = await getManager();
|
|
9438
9636
|
if (action === "list") {
|
|
9439
9637
|
const result = await cloudbase.functions.getFunctionList(limit, offset);
|
|
9638
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9440
9639
|
return {
|
|
9441
9640
|
content: [
|
|
9442
9641
|
{
|
|
@@ -9451,6 +9650,7 @@ function registerFunctionTools(server) {
|
|
|
9451
9650
|
throw new Error("获取函数详情时,name 参数是必需的");
|
|
9452
9651
|
}
|
|
9453
9652
|
const result = await cloudbase.functions.getFunctionDetail(name, codeSecret);
|
|
9653
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9454
9654
|
return {
|
|
9455
9655
|
content: [
|
|
9456
9656
|
{
|
|
@@ -9532,6 +9732,7 @@ function registerFunctionTools(server) {
|
|
|
9532
9732
|
functionRootPath: processedRootPath,
|
|
9533
9733
|
force
|
|
9534
9734
|
});
|
|
9735
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9535
9736
|
return {
|
|
9536
9737
|
content: [
|
|
9537
9738
|
{
|
|
@@ -9579,6 +9780,7 @@ function registerFunctionTools(server) {
|
|
|
9579
9780
|
// 使用闭包中的 cloudBaseOptions
|
|
9580
9781
|
const cloudbase = await getManager();
|
|
9581
9782
|
const result = await cloudbase.functions.updateFunctionCode(updateParams);
|
|
9783
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9582
9784
|
return {
|
|
9583
9785
|
content: [
|
|
9584
9786
|
{
|
|
@@ -9619,6 +9821,7 @@ function registerFunctionTools(server) {
|
|
|
9619
9821
|
// 使用闭包中的 cloudBaseOptions
|
|
9620
9822
|
const cloudbase = await getManager();
|
|
9621
9823
|
const result = await cloudbase.functions.updateFunctionConfig(funcParam);
|
|
9824
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9622
9825
|
return {
|
|
9623
9826
|
content: [
|
|
9624
9827
|
{
|
|
@@ -9647,6 +9850,7 @@ function registerFunctionTools(server) {
|
|
|
9647
9850
|
// 使用闭包中的 cloudBaseOptions
|
|
9648
9851
|
const cloudbase = await getManager();
|
|
9649
9852
|
const result = await cloudbase.functions.invokeFunction(name, params);
|
|
9853
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9650
9854
|
return {
|
|
9651
9855
|
content: [
|
|
9652
9856
|
{
|
|
@@ -9687,6 +9891,7 @@ function registerFunctionTools(server) {
|
|
|
9687
9891
|
}
|
|
9688
9892
|
const cloudbase = await getManager();
|
|
9689
9893
|
const result = await cloudbase.functions.getFunctionLogsV2({ name, offset, limit, startTime, endTime, requestId, qualifier });
|
|
9894
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9690
9895
|
return {
|
|
9691
9896
|
content: [
|
|
9692
9897
|
{
|
|
@@ -9724,6 +9929,7 @@ function registerFunctionTools(server) {
|
|
|
9724
9929
|
endTime,
|
|
9725
9930
|
logRequestId: requestId
|
|
9726
9931
|
});
|
|
9932
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9727
9933
|
return {
|
|
9728
9934
|
content: [
|
|
9729
9935
|
{
|
|
@@ -9762,6 +9968,7 @@ function registerFunctionTools(server) {
|
|
|
9762
9968
|
throw new Error("创建触发器时,triggers 参数是必需的");
|
|
9763
9969
|
}
|
|
9764
9970
|
const result = await cloudbase.functions.createFunctionTriggers(name, triggers);
|
|
9971
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9765
9972
|
return {
|
|
9766
9973
|
content: [
|
|
9767
9974
|
{
|
|
@@ -9776,6 +9983,7 @@ function registerFunctionTools(server) {
|
|
|
9776
9983
|
throw new Error("删除触发器时,triggerName 参数是必需的");
|
|
9777
9984
|
}
|
|
9778
9985
|
const result = await cloudbase.functions.deleteFunctionTrigger(name, triggerName);
|
|
9986
|
+
(0, cloudbase_manager_js_1.logCloudBaseResult)(server.logger, result);
|
|
9779
9987
|
return {
|
|
9780
9988
|
content: [
|
|
9781
9989
|
{
|