@junjun-org/bd-ke-mcp 1.0.1 → 1.0.2
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/index.js +34 -27
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -840,14 +840,15 @@ async function kePodsList(options = {}) {
|
|
|
840
840
|
* @param {string} options.domain - KE 平台域名,未指定时从配置文件获取
|
|
841
841
|
* @param {string} options.access_token - 访问令牌,未指定时从配置文件获取
|
|
842
842
|
* @param {string} options.tenant - 租户名称,未指定时从配置文件获取
|
|
843
|
-
* @param {string} options.
|
|
844
|
-
* @param {string} options.
|
|
845
|
-
* @param {string} options.
|
|
846
|
-
* @param {
|
|
847
|
-
* @param {
|
|
848
|
-
* @param {
|
|
849
|
-
* @param {number} options.
|
|
850
|
-
* @param {
|
|
843
|
+
* @param {string} options.project - 项目名称,未指定时从配置文件获取(用于构建默认 namespace)
|
|
844
|
+
* @param {string} options.namespace - 命名空间,未指定时从配置文件的 tenant-project 构建
|
|
845
|
+
* @param {string} options.application - 应用名称,未指定时从配置文件获取
|
|
846
|
+
* @param {string} options.env - 环境名称,未指定时从配置文件获取
|
|
847
|
+
* @param {string} options.startTime - 开始时间(纳秒时间戳字符串,必填)
|
|
848
|
+
* @param {string} options.endTime - 结束时间(纳秒时间戳字符串,必填)
|
|
849
|
+
* @param {number} options.size - 返回记录数量(必填)
|
|
850
|
+
* @param {number} options.offset - 偏移量(必填)
|
|
851
|
+
* @param {string} options.sort - 排序方式(必填)
|
|
851
852
|
*/
|
|
852
853
|
async function kePodLogList(options = {}) {
|
|
853
854
|
reloadConfig();
|
|
@@ -855,23 +856,29 @@ async function kePodLogList(options = {}) {
|
|
|
855
856
|
const domain = options.domain || getConfig("domain");
|
|
856
857
|
const accessToken = options.access_token || getConfig("access_token");
|
|
857
858
|
const tenant = options.tenant || getConfig("tenant");
|
|
858
|
-
const
|
|
859
|
-
const service = options.
|
|
860
|
-
const env = options.env;
|
|
859
|
+
const project = options.project || getConfig("project");
|
|
860
|
+
const service = options.application || getConfig("application");
|
|
861
|
+
const env = options.env || getConfig("env");
|
|
861
862
|
const startTime = options.startTime;
|
|
862
863
|
const endTime = options.endTime;
|
|
863
|
-
const size = options.size
|
|
864
|
-
const offset = options.offset
|
|
865
|
-
const sort = options.sort
|
|
864
|
+
const size = options.size;
|
|
865
|
+
const offset = options.offset;
|
|
866
|
+
const sort = options.sort;
|
|
867
|
+
|
|
868
|
+
// namespace 优先从参数获取,否则从 tenant-project 构建
|
|
869
|
+
const namespace = options.namespace || (tenant && project ? `${tenant}-${project}` : null);
|
|
866
870
|
|
|
867
871
|
if (!tenant) {
|
|
868
872
|
throw new Error("参数 tenant 未指定且配置文件中未设置");
|
|
869
873
|
}
|
|
870
|
-
if (!namespace) throw new Error("参数 namespace
|
|
871
|
-
if (!service) throw new Error("参数
|
|
872
|
-
if (!env) throw new Error("参数 env
|
|
874
|
+
if (!namespace) throw new Error("参数 namespace 未指定且无法从配置文件的 tenant-project 构建");
|
|
875
|
+
if (!service) throw new Error("参数 application 未指定且配置文件中未设置");
|
|
876
|
+
if (!env) throw new Error("参数 env 未指定且配置文件中未设置");
|
|
873
877
|
if (!startTime) throw new Error("参数 startTime 不能为空");
|
|
874
878
|
if (!endTime) throw new Error("参数 endTime 不能为空");
|
|
879
|
+
if (size === undefined || size === null) throw new Error("参数 size 不能为空");
|
|
880
|
+
if (offset === undefined || offset === null) throw new Error("参数 offset 不能为空");
|
|
881
|
+
if (!sort) throw new Error("参数 sort 不能为空");
|
|
875
882
|
|
|
876
883
|
const url = `armilla/v1/group/${tenant}/env/${env}/log/list`;
|
|
877
884
|
|
|
@@ -1192,19 +1199,19 @@ server.registerTool(
|
|
|
1192
1199
|
domain: z.string().optional().describe("KE 平台域名(如:https://ke.example.com),用于 API 请求。未指定时从 .mcp/bd-ke-mcp.json 配置文件获取"),
|
|
1193
1200
|
access_token: z.string().optional().describe("访问令牌(leo-user-token),用于 API 认证。未指定时从 .mcp/bd-ke-mcp.json 配置文件获取"),
|
|
1194
1201
|
tenant: z.string().optional().describe("租户名称,用于日志查询 API 路径。未指定时从 .mcp/bd-ke-mcp.json 配置文件获取"),
|
|
1195
|
-
namespace: z.string().describe("命名空间,格式为 tenant-project(如:myapp-production
|
|
1196
|
-
|
|
1197
|
-
env: z.string().describe("环境名称,指定要查询日志的环境(集群),可通过 ke_env_list
|
|
1198
|
-
startTime: z.
|
|
1199
|
-
endTime: z.
|
|
1200
|
-
size: z.number().
|
|
1201
|
-
offset: z.number().
|
|
1202
|
-
sort: z.string().
|
|
1202
|
+
namespace: z.string().optional().describe("命名空间,格式为 tenant-project(如:myapp-production),用于筛选日志来源。未指定时从配置文件的 tenant-project 自动构建"),
|
|
1203
|
+
application: z.string().optional().describe("应用名称,指定要查询日志的应用,可通过 ke_app_list 获取。未指定时从 .mcp/bd-ke-mcp.json 配置文件获取"),
|
|
1204
|
+
env: z.string().optional().describe("环境名称,指定要查询日志的环境(集群),可通过 ke_env_list 获取。未指定时从 .mcp/bd-ke-mcp.json 配置文件获取"),
|
|
1205
|
+
startTime: z.string().describe("查询开始时间,纳秒级时间戳字符串(如:\"1704067200000000000\" 表示 2024-01-01 00:00:00)"),
|
|
1206
|
+
endTime: z.string().describe("查询结束时间,纳秒级时间戳字符串(如:\"1704153600000000000\" 表示 2024-01-02 00:00:00)"),
|
|
1207
|
+
size: z.number().describe("返回的日志记录数量,建议不超过 1000"),
|
|
1208
|
+
offset: z.number().describe("分页偏移量,用于翻页查询,从 0 开始"),
|
|
1209
|
+
sort: z.string().describe("日志排序方式,desc 表示按时间降序(最新在前),asc 表示按时间升序(最早在前)")
|
|
1203
1210
|
}
|
|
1204
1211
|
},
|
|
1205
|
-
async ({ domain, access_token, tenant, namespace,
|
|
1212
|
+
async ({ domain, access_token, tenant, namespace, application, env, startTime, endTime, size, offset, sort }) => {
|
|
1206
1213
|
try {
|
|
1207
|
-
const result = await kePodLogList({ domain, access_token, tenant, namespace,
|
|
1214
|
+
const result = await kePodLogList({ domain, access_token, tenant, namespace, application, env, startTime, endTime, size, offset, sort });
|
|
1208
1215
|
return { content: [{ type: "text", text: result }] };
|
|
1209
1216
|
} catch (error) {
|
|
1210
1217
|
logger.error("ke_pod_log_list 失败", { error: error.message });
|