Skip to content

Commit 8f6e57e

Browse files
author
CodeBuddy Attribution Bot
committed
fix(attribution): MCP 云函数日志查询工具参数设计与错误提示不清晰 (issue_mo8z1wxq_k14q0z)
1 parent e2ca73f commit 8f6e57e

4 files changed

Lines changed: 145 additions & 29 deletions

File tree

config/.claude/skills/cloud-functions/SKILL.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,28 @@ The `scf_bootstrap` binary path must match the runtime — see the full mapping
245245

246246
### Logs
247247

248-
- `queryFunctions(action="listFunctionLogs")`
249-
- `queryFunctions(action="getFunctionLogDetail")`
250-
- If these are unavailable, read `./references/operations-and-config.md` before any `callCloudApi` fallback
248+
**查询云函数日志**:使用 `queryFunctions` 工具
249+
250+
- `queryFunctions(action="listFunctionLogs", functionName="xxx")` — 查询特定函数的执行日志
251+
- `queryFunctions(action="getFunctionLogDetail", requestId="xxx")` — 查看单条日志详情
252+
253+
**区分 `queryLogs` 工具**
254+
- `queryFunctions` 用于查询特定云函数的执行日志,需要提供 `functionName`
255+
- `queryLogs` 用于搜索 CLS 日志服务(跨服务日志聚合),使用 CLS 查询语法
256+
257+
**示例**
258+
```javascript
259+
// 查询云函数 my-function 的最近日志
260+
queryFunctions(action="listFunctionLogs", functionName="my-function", limit=10)
261+
262+
// 查看特定请求的日志详情
263+
queryFunctions(action="getFunctionLogDetail", requestId="abc-123")
264+
265+
// 使用 CLS 搜索所有服务的错误日志(跨服务)
266+
queryLogs(action="searchLogs", queryString="ERROR", service="tcb")
267+
```
268+
269+
If these are unavailable, read `./references/operations-and-config.md` before any `callCloudApi` fallback
251270

252271
### Gateway exposure
253272

@@ -260,3 +279,4 @@ The `scf_bootstrap` binary path must match the runtime — see the full mapping
260279
- `cloudrun-development` -> container services, long-lived runtimes, Agent hosting
261280
- `http-api` -> raw CloudBase HTTP API invocation patterns
262281
- `cloudbase-platform` -> general CloudBase platform decisions
282+
- `ops-inspector` -> AIOps-style inspection and log search across services

config/source/skills/cloud-functions/SKILL.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,28 @@ The `scf_bootstrap` binary path must match the runtime — see the full mapping
245245

246246
### Logs
247247

248-
- `queryFunctions(action="listFunctionLogs")`
249-
- `queryFunctions(action="getFunctionLogDetail")`
250-
- If these are unavailable, read `./references/operations-and-config.md` before any `callCloudApi` fallback
248+
**查询云函数日志**:使用 `queryFunctions` 工具
249+
250+
- `queryFunctions(action="listFunctionLogs", functionName="xxx")` — 查询特定函数的执行日志
251+
- `queryFunctions(action="getFunctionLogDetail", requestId="xxx")` — 查看单条日志详情
252+
253+
**区分 `queryLogs` 工具**
254+
- `queryFunctions` 用于查询特定云函数的执行日志,需要提供 `functionName`
255+
- `queryLogs` 用于搜索 CLS 日志服务(跨服务日志聚合),使用 CLS 查询语法
256+
257+
**示例**
258+
```javascript
259+
// 查询云函数 my-function 的最近日志
260+
queryFunctions(action="listFunctionLogs", functionName="my-function", limit=10)
261+
262+
// 查看特定请求的日志详情
263+
queryFunctions(action="getFunctionLogDetail", requestId="abc-123")
264+
265+
// 使用 CLS 搜索所有服务的错误日志(跨服务)
266+
queryLogs(action="searchLogs", queryString="ERROR", service="tcb")
267+
```
268+
269+
If these are unavailable, read `./references/operations-and-config.md` before any `callCloudApi` fallback
251270

252271
### Gateway exposure
253272

@@ -260,3 +279,4 @@ The `scf_bootstrap` binary path must match the runtime — see the full mapping
260279
- `cloudrun-development` -> container services, long-lived runtimes, Agent hosting
261280
- `http-api` -> raw CloudBase HTTP API invocation patterns
262281
- `cloudbase-platform` -> general CloudBase platform decisions
282+
- `ops-inspector` -> AIOps-style inspection and log search across services

mcp/src/tools/functions.ts

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,23 +1412,53 @@ export function registerFunctionTools(server: ExtendedMcpServer) {
14121412
{
14131413
title: "查询云函数域资源",
14141414
description:
1415-
"函数域统一只读入口。通过更自解释的 action 查询函数列表、函数详情、日志、层、触发器和代码下载地址。",
1415+
"函数域统一只读入口。通过更自解释的 action 查询函数列表、函数详情、日志、层、触发器和代码下载地址。" +
1416+
"\n\n**查询云函数日志**:使用 `action=\"listFunctionLogs\"`,需要提供 `functionName` 参数。" +
1417+
"\n- 示例:`queryFunctions(action=\"listFunctionLogs\", functionName=\"my-function\")`" +
1418+
"\n- 如需查看日志详情:`queryFunctions(action=\"getFunctionLogDetail\", requestId=\"xxx\")`" +
1419+
"\n\n**区分 `queryLogs` 工具**:" +
1420+
"\n- 本工具用于查询特定云函数的执行日志" +
1421+
"\n- `queryLogs` 工具用于搜索 CLS 日志服务(跨服务日志聚合)",
14161422
inputSchema: {
14171423
action: z
14181424
.enum(QUERY_FUNCTION_ACTIONS)
1419-
.describe("只读操作类型,例如 listFunctions、getFunctionDetail、listFunctionLogs"),
1420-
functionName: z.string().optional().describe("函数名称。函数相关 action 必填"),
1421-
limit: z.number().optional().describe("分页数量。列表类 action 可选"),
1422-
offset: z.number().optional().describe("分页偏移。列表类 action 可选"),
1423-
codeSecret: z.string().optional().describe("代码保护密钥"),
1424-
startTime: z.string().optional().describe("日志查询开始时间"),
1425-
endTime: z.string().optional().describe("日志查询结束时间"),
1426-
requestId: z.string().optional().describe("日志 requestId。获取日志详情时必填"),
1427-
qualifier: z.string().optional().describe("函数版本,日志查询时可选"),
1428-
runtime: z.string().optional().describe("层查询的运行时筛选"),
1425+
.describe(
1426+
"只读操作类型:" +
1427+
"\n- `listFunctions`: 列出所有云函数" +
1428+
"\n- `getFunctionDetail`: 获取函数详情(需要 functionName)" +
1429+
"\n- `listFunctionLogs`: 查询函数执行日志(需要 functionName)" +
1430+
"\n- `getFunctionLogDetail`: 获取日志详情(需要 requestId)" +
1431+
"\n- `listFunctionLayers`: 列出函数绑定的层" +
1432+
"\n- `listLayers`: 列出所有层" +
1433+
"\n- `listLayerVersions`: 列出层的版本" +
1434+
"\n- `getLayerVersionDetail`: 获取层版本详情" +
1435+
"\n- `listFunctionTriggers`: 列出函数触发器" +
1436+
"\n- `getFunctionDownloadUrl`: 获取函数代码下载地址"
1437+
),
1438+
functionName: z
1439+
.string()
1440+
.optional()
1441+
.describe("函数名称。`getFunctionDetail`、`listFunctionLogs`、`listFunctionLayers`、`listFunctionTriggers` 等操作必填"),
1442+
limit: z.number().optional().describe("分页数量。列表类 action 可选,默认值由后端决定"),
1443+
offset: z.number().optional().describe("分页偏移。列表类 action 可选,默认 0"),
1444+
codeSecret: z.string().optional().describe("代码保护密钥,用于解密函数代码"),
1445+
startTime: z
1446+
.string()
1447+
.optional()
1448+
.describe("日志查询开始时间,格式:`YYYY-MM-DD HH:mm:ss`。`listFunctionLogs` 和 `getFunctionLogDetail` 可选"),
1449+
endTime: z
1450+
.string()
1451+
.optional()
1452+
.describe("日志查询结束时间,格式:`YYYY-MM-DD HH:mm:ss`。`listFunctionLogs` 和 `getFunctionLogDetail` 可选"),
1453+
requestId: z
1454+
.string()
1455+
.optional()
1456+
.describe("日志请求 ID。`getFunctionLogDetail` 操作必填,可从 `listFunctionLogs` 结果中获取"),
1457+
qualifier: z.string().optional().describe("函数版本别名,如 $LATEST、$DEFAULT。日志查询时可选"),
1458+
runtime: z.string().optional().describe("层查询的运行时筛选,如 Nodejs18.15"),
14291459
searchKey: z.string().optional().describe("层名称搜索关键字"),
1430-
layerName: z.string().optional().describe("层名称。层相关 action 必填"),
1431-
layerVersion: z.number().optional().describe("层版本号。获取层版本详情时必填"),
1460+
layerName: z.string().optional().describe("层名称。`listLayerVersions`、`getLayerVersionDetail` 操作必填"),
1461+
layerVersion: z.number().optional().describe("层版本号。`getLayerVersionDetail` 操作必填"),
14321462
},
14331463
annotations: {
14341464
readOnlyHint: true,

mcp/src/tools/logs.ts

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,55 @@ export function registerLogTools(server: ExtendedMcpServer) {
3737
"queryLogs",
3838
{
3939
title: "查询日志服务",
40-
description: "日志域统一只读入口。支持检查日志服务状态并搜索 CLS 日志。",
40+
description:
41+
"日志域统一只读入口。支持检查日志服务状态并搜索 CLS 日志。" +
42+
"\n\n**重要区分**:" +
43+
"\n- 查询云函数日志:使用 `queryFunctions(action=\"listFunctionLogs\", functionName=\"xxx\")`" +
44+
"\n- 查询 CLS 日志(跨服务日志聚合):使用本工具 `queryLogs(action=\"searchLogs\")`" +
45+
"\n\n**适用场景**:" +
46+
"\n- 检查 CLS 日志服务是否开通:`action=\"checkLogService\"`" +
47+
"\n- 跨服务日志搜索(如搜索所有 ERROR 日志):`action=\"searchLogs\"`" +
48+
"\n- 按 CLS 语法检索特定服务的日志:`action=\"searchLogs\", service=\"tcb|tcbr\"`",
4149
inputSchema: {
42-
action: z.enum(QUERY_LOG_ACTIONS),
43-
queryString: z.string().optional(),
44-
service: z.enum(["tcb", "tcbr"]).optional(),
45-
startTime: z.string().optional(),
46-
endTime: z.string().optional(),
47-
limit: z.number().optional(),
48-
context: z.string().optional(),
49-
sort: z.enum(["asc", "desc"]).optional(),
50+
action: z
51+
.enum(QUERY_LOG_ACTIONS)
52+
.describe(
53+
"操作类型:" +
54+
"\n- `checkLogService`: 检查 CLS 日志服务是否开通" +
55+
"\n- `searchLogs`: 搜索 CLS 日志(需要提供 queryString)"
56+
),
57+
queryString: z
58+
.string()
59+
.optional()
60+
.describe(
61+
"CLS 查询语句。**action=\"searchLogs\" 时必填**。" +
62+
"\n\n**常用查询语法**:" +
63+
"\n- `ERROR`: 搜索包含 ERROR 的日志" +
64+
"\n- `functionName:myFunc AND level:ERROR`: 搜索函数 myFunc 的错误日志" +
65+
"\n- `timeout OR 超时`: 搜索超时相关日志" +
66+
"\n- `coldStart OR 冷启动`: 搜索冷启动日志" +
67+
"\n- `statusCode:>499`: 搜索 5xx 错误" +
68+
"\n\n**注意**:查询云函数日志时,优先使用 `queryFunctions(action=\"listFunctionLogs\")`"
69+
),
70+
service: z
71+
.enum(["tcb", "tcbr"])
72+
.optional()
73+
.describe(
74+
"日志来源服务:" +
75+
"\n- `tcb`: 云函数、数据库、存储等基础服务日志" +
76+
"\n- `tcbr`: CloudRun 容器服务日志"
77+
),
78+
startTime: z
79+
.string()
80+
.optional()
81+
.describe("查询开始时间,格式:`YYYY-MM-DD HH:mm:ss`,如 `2024-01-01 00:00:00`"),
82+
endTime: z
83+
.string()
84+
.optional()
85+
.describe("查询结束时间,格式:`YYYY-MM-DD HH:mm:ss`,如 `2024-01-01 23:59:59`"),
86+
limit: z.number().optional().describe("返回日志条数限制,默认 20"),
87+
context: z.string().optional().describe("翻页上下文,用于继续上一次查询"),
88+
sort: z.enum(["asc", "desc"]).optional().describe("按时间排序:`asc` 升序,`desc` 降序"),
5089
},
5190
annotations: {
5291
readOnlyHint: true,
@@ -89,7 +128,14 @@ export function registerLogTools(server: ExtendedMcpServer) {
89128
}
90129

91130
if (!queryString) {
92-
throw new Error("action=searchLogs 时必须提供 queryString");
131+
throw new Error(
132+
"action=\"searchLogs\" 时必须提供 queryString 参数。" +
133+
"\n\n常用查询示例:" +
134+
"\n- `ERROR`: 搜索所有错误日志" +
135+
"\n- `functionName:xxx AND level:ERROR`: 搜索特定函数的错误日志" +
136+
"\n- `timeout`: 搜索超时日志" +
137+
"\n\n如果需要查询特定云函数的执行日志,建议使用 `queryFunctions(action=\"listFunctionLogs\", functionName=\"xxx\")`"
138+
);
93139
}
94140
const result = await cloudbase.log.searchClsLog({
95141
queryString,

0 commit comments

Comments
 (0)