@@ -10,25 +10,30 @@ interface RequiredEnv {
1010const AiSearchResponseSchema = z . object ( {
1111 object : z . string ( ) ,
1212 search_query : z . string ( ) ,
13- data : z . array ( z . object ( {
14- file_id : z . string ( ) ,
15- filename : z . string ( ) ,
16- score : z . number ( ) ,
17- attributes : z . object ( {
18- modified_date : z . number ( ) . optional ( ) ,
19- folder : z . string ( ) . optional ( ) ,
20- } ) . catchall ( z . any ( ) ) ,
21- content : z . array ( z . object ( {
22- id : z . string ( ) ,
23- type : z . string ( ) ,
24- text : z . string ( ) ,
25- } ) ) ,
26- } ) ) ,
13+ data : z . array (
14+ z . object ( {
15+ file_id : z . string ( ) ,
16+ filename : z . string ( ) ,
17+ score : z . number ( ) ,
18+ attributes : z
19+ . object ( {
20+ modified_date : z . number ( ) . optional ( ) ,
21+ folder : z . string ( ) . optional ( ) ,
22+ } )
23+ . catchall ( z . any ( ) ) ,
24+ content : z . array (
25+ z . object ( {
26+ id : z . string ( ) ,
27+ type : z . string ( ) ,
28+ text : z . string ( ) ,
29+ } )
30+ ) ,
31+ } )
32+ ) ,
2733 has_more : z . boolean ( ) ,
2834 next_page : z . string ( ) . nullable ( ) ,
2935} )
3036
31-
3237/**
3338 * Registers the docs search tool with the MCP server using AI Search
3439 * @param server The MCP server instance
@@ -114,7 +119,7 @@ ${result.text}
114119
115120async function queryAiSearch ( ai : Ai , query : string ) {
116121 const rawResponse = await doWithRetries ( ( ) =>
117- ai . autorag ( " docs-mcp-rag" ) . search ( {
122+ ai . autorag ( ' docs-mcp-rag' ) . search ( {
118123 query,
119124 } )
120125 )
@@ -127,7 +132,7 @@ async function queryAiSearch(ai: Ai, query: string) {
127132 id : item . file_id ,
128133 url : sourceToUrl ( item . filename ) ,
129134 title : extractTitle ( item . filename ) ,
130- text : item . content . map ( c => c . text ) . join ( '\n' ) ,
135+ text : item . content . map ( ( c ) => c . text ) . join ( '\n' ) ,
131136 } ) )
132137}
133138
@@ -136,9 +141,7 @@ function sourceToUrl(filename: string): string {
136141 // Example: "workers/configuration/index.md" -> "https://developers.cloudflare.com/workers/configuration/"
137142 return (
138143 'https://developers.cloudflare.com/' +
139- filename
140- . replace ( / i n d e x \. m d x ? $ / , '' )
141- . replace ( / \. m d x ? $ / , '' )
144+ filename . replace ( / i n d e x \. m d x ? $ / , '' ) . replace ( / \. m d x ? $ / , '' )
142145 )
143146}
144147
@@ -154,9 +157,7 @@ function extractTitle(filename: string): string {
154157 }
155158
156159 // Convert kebab-case or snake_case to title case
157- return lastPart
158- . replace ( / [ - _ ] / g, ' ' )
159- . replace ( / \b \w / g, l => l . toUpperCase ( ) )
160+ return lastPart . replace ( / [ - _ ] / g, ' ' ) . replace ( / \b \w / g, ( l ) => l . toUpperCase ( ) )
160161}
161162
162163/**
@@ -214,4 +215,4 @@ function isRetryableError(error: unknown): boolean {
214215
215216 // Default to retryable for unknown errors (conservative approach)
216217 return true
217- }
218+ }
0 commit comments