1+ import { z } from "zod" ;
12import { tool } from "../../tool" ;
23import { mcpError , toContent } from "../../util" ;
34import {
@@ -7,8 +8,23 @@ import {
78 ReportInput ,
89 simplifyReport ,
910} from "../../../crashlytics/reports" ;
11+ import { EventFilter } from "../../../crashlytics/filters" ;
1012import { CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
1113import { 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