Skip to content

Commit d872941

Browse files
authored
nit: Fix small bug in functions log MCP tool (#9247)
1. Improve error message to include more useful error message from Cloud Logging 2. Fix bug where asc/desc was incorrectly passed to cloud logging API call when it is absent in the tool arg.
1 parent 1cb6170 commit d872941

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix Functions MCP log tool to normalize sort order and surface Cloud Logging error details (#9247)

src/mcp/tools/functions/get_logs.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { tool } from "../../tool";
44
import { mcpError, toContent } from "../../util";
55
import { getApiFilter } from "../../../functions/functionslog";
66
import { listEntries } from "../../../gcp/cloudlogging";
7+
import { getErrMsg } from "../../../error";
78

89
const SEVERITY_LEVELS = [
910
"DEFAULT",
@@ -44,13 +45,14 @@ export const get_logs = tool(
4445
{
4546
name: "get_logs",
4647
description:
47-
"Retrieves a page of Cloud Functions log entries using Google Cloud Logging advanced filters.",
48+
"Use this to retrieve a page of Cloud Functions log entries using Google Cloud Logging advanced filters.",
4849
inputSchema: z.object({
4950
function_names: z
50-
.union([z.string(), z.array(z.string()).min(1)])
51+
.array(z.string())
52+
.min(1)
5153
.optional()
5254
.describe(
53-
"Optional list of deployed Cloud Function names to filter logs (string or array).",
55+
"Optional list of deployed Cloud Function IDs to filter logs (e.g. ['fnA','fnB']).",
5456
),
5557
page_size: z
5658
.number()
@@ -101,8 +103,8 @@ export const get_logs = tool(
101103
{ function_names, page_size, order, page_token, min_severity, start_time, end_time, filter },
102104
{ projectId },
103105
) => {
104-
const resolvedOrder = order;
105-
const resolvedPageSize = page_size;
106+
const resolvedOrder: "asc" | "desc" = order?.toLowerCase() === "asc" ? "asc" : "desc";
107+
const resolvedPageSize = page_size ?? 50;
106108

107109
const normalizedSelectors = normalizeFunctionSelectors(function_names);
108110
const filterParts: string[] = [getApiFilter(normalizedSelectors)];
@@ -176,9 +178,11 @@ export const get_logs = tool(
176178

177179
return toContent(response);
178180
} catch (err) {
179-
const message =
180-
err instanceof Error ? err.message : "Failed to retrieve Cloud Logging entries.";
181-
return mcpError(message);
181+
const errMsg = getErrMsg(
182+
(err as any)?.original || err,
183+
"Failed to retrieve Cloud Logging entries.",
184+
);
185+
return mcpError(errMsg);
182186
}
183187
},
184188
);

0 commit comments

Comments
 (0)