Skip to content

Commit adab0c0

Browse files
maxl0rdschnecle
authored andcommitted
Include request filters in report tool response
1 parent 41eca55 commit adab0c0

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/mcp/tools/crashlytics/reports.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { z } from "zod";
12
import { tool } from "../../tool";
23
import { mcpError, toContent } from "../../util";
34
import {
@@ -7,8 +8,23 @@ import {
78
ReportInput,
89
simplifyReport,
910
} from "../../../crashlytics/reports";
11+
import { EventFilter } from "../../../crashlytics/filters";
1012
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
1113
import { validateEventFilters } from "../../../crashlytics/filters";
14+
import { Report, ReportFilters } from "../../../crashlytics/types";
15+
import { dump, DumpOptions } from "js-yaml";
16+
17+
const DUMP_OPTIONS: DumpOptions = { lineWidth: 200 };
18+
19+
function toText(response: Report, filters: EventFilter): Record<string, string> {
20+
const result: Record<string, string> = {
21+
filters: dump(filters, DUMP_OPTIONS)
22+
};
23+
for (const [key, value] of Object.entries(response)) {
24+
result[key] = dump(value, DUMP_OPTIONS);
25+
}
26+
return result;
27+
}
1228

1329
// Generates the tool call fn for requesting a Crashlytics report
1430

@@ -28,10 +44,12 @@ function getReportContent(
2844
}
2945
validateEventFilters(filter); // throws here if invalid filters
3046
const reportResponse = simplifyReport(await getReport(report, appId, filter, pageSize));
31-
const emptyPrompt = (!reportResponse.groups || reportResponse.groups.length === 0) ?
32-
"\nThis report response contains no results." : "";
33-
reportResponse.usage = [reportResponse.usage || "", additionalPrompt, emptyPrompt].join(" ");
34-
return toContent(reportResponse);
47+
reportResponse.usage = (reportResponse.groups && reportResponse.groups.length)
48+
? (reportResponse.usage || "").concat(additionalPrompt)
49+
: "This report response contains no results.";
50+
return {
51+
content: [{ type: "text", text: dump(toText(reportResponse, filter), DUMP_OPTIONS) }],
52+
};
3553
};
3654
}
3755

0 commit comments

Comments
 (0)