Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions mcp/src/tools/databaseNoSQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,80 @@ deleteCollection: 删除集合`),
throw new Error(`不支持的操作类型: ${action}`);
},
);

// queryNoSqlDatabaseBackupTime - 查询 NoSQL 数据库可回档时间范围
server.registerTool?.(
"queryNoSqlDatabaseBackupTime",
{
title: "查询 NoSQL 数据库可回档时间范围",
description:
"查询 NoSQL 数据库(文档型数据库)的可回档时间范围,返回最早可回档时间和最晚可回档时间。适用于需要了解数据库备份恢复时间范围的场景。",
inputSchema: {
collectionName: z
.string()
.optional()
.describe("集合名称(可选),如需查询特定集合的回档时间范围可传入"),
instanceId: z
.string()
.optional()
.describe("可选:显式指定数据库实例ID;未传时会自动解析并缓存"),
},
annotations: {
readOnlyHint: true,
openWorldHint: true,
category: CATEGORY,
},
},
async ({ collectionName, instanceId }) => {
const cloudbase = await getManager();

const resolvedInstance = await resolveNoSqlInstanceId({
toolName: "queryNoSqlDatabaseBackupTime",
cloudbase,
cloudBaseOptions,
instanceIdOverride: instanceId,
collectionName: collectionName || "default",
});

const result = await cloudbase
.commonService("tcb", "2018-06-08")
.call({
Action: "DescribeBackupTime",
Param: {
EnvId: cloudBaseOptions?.envId,
TableName: collectionName,
Tag: resolvedInstance.instanceId,
},
Comment on lines +941 to +946
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use DescribeRestoreTime API contract for backup-time query

This new tool calls commonService("tcb", "2018-06-08") with Action: "DescribeBackupTime" and params TableName/Tag, but the repository’s CloudBase manager docs for “查询可回档时间” specify commonService('flexdb').call with Action: 'DescribeRestoreTime' and Param.InstanceId. In environments that follow the documented contract, this request shape can fail outright or hit a different backend action, so users asking for restoreable timestamps may not get a valid response.

Useful? React with 👍 / 👎.

});

logCloudBaseResult(server.logger, result);

return {
content: [
{
type: "text",
text: JSON.stringify(
{
success: true,
requestId: result?.RequestId,
backupTimeRange: {
earliestTime: result?.EarliestTime,
latestTime: result?.LatestTime,
startTime: result?.StartTime,
endTime: result?.EndTime,
},
Comment on lines +959 to +964
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Return documented restore-time fields from API response

The response formatter reads EarliestTime/LatestTime/StartTime/EndTime, but the documented restore-time response uses RestoreTimes (and optionally RestoreTimeRanges). If the API returns the documented fields, this tool will emit backupTimeRange with null/empty values even when the call succeeds, which breaks downstream consumers expecting actual restore-time data.

Useful? React with 👍 / 👎.

instanceId: resolvedInstance.instanceId,
collectionName: collectionName || null,
message: "获取 NoSQL 数据库可回档时间范围成功",
},
null,
2,
),
},
],
};
},
);
}

async function insertDocuments({
Expand Down
Loading