Skip to content

Commit 99e2282

Browse files
fix lockfile (cloudflare#258)
* fix lockfile * add changeset * formatting changes * Fix formatting on behalf of bread --------- Co-authored-by: Maximo Guk <[email protected]>
1 parent 6d29be8 commit 99e2282

File tree

3 files changed

+118
-32
lines changed

3 files changed

+118
-32
lines changed

.changeset/rare-paws-tan.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
'cloudflare-ai-gateway-mcp-server': patch
3+
'auditlogs': patch
4+
'cloudflare-autorag-mcp-server': patch
5+
'cloudflare-browser-mcp-server': patch
6+
'cloudflare-casb-mcp-server': patch
7+
'demo-day': patch
8+
'dex-analysis': patch
9+
'dns-analytics': patch
10+
'docs-ai-search': patch
11+
'docs-autorag': patch
12+
'docs-vectorize': patch
13+
'graphql-mcp-server': patch
14+
'logpush': patch
15+
'cloudflare-radar-mcp-server': patch
16+
'containers-mcp': patch
17+
'workers-bindings': patch
18+
'workers-builds': patch
19+
'workers-observability': patch
20+
'@repo/eslint-config': patch
21+
'@repo/eval-tools': patch
22+
'@repo/mcp-common': patch
23+
'@repo/mcp-observability': patch
24+
'@repo/tools': patch
25+
'@repo/typescript-config': patch
26+
---
27+
28+
Move docs MCP server to use AI Search

packages/mcp-common/src/tools/docs-ai-search.tools.ts

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,30 @@ interface RequiredEnv {
1010
const 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

115120
async 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(/index\.mdx?$/, '')
141-
.replace(/\.mdx?$/, '')
144+
filename.replace(/index\.mdx?$/, '').replace(/\.mdx?$/, '')
142145
)
143146
}
144147

@@ -147,16 +150,14 @@ function extractTitle(filename: string): string {
147150
// Example: "workers/configuration/index.md" -> "Configuration"
148151
const parts = filename.replace(/\.mdx?$/, '').split('/')
149152
const lastPart = parts[parts.length - 1]
150-
153+
151154
if (lastPart === 'index') {
152155
// Use the parent directory name if filename is index
153156
return parts[parts.length - 2] || 'Documentation'
154157
}
155-
158+
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
/**
@@ -167,20 +168,20 @@ function extractTitle(filename: string): string {
167168
async function doWithRetries<T>(action: () => Promise<T>) {
168169
const NUM_RETRIES = 5
169170
const INIT_RETRY_MS = 100
170-
171+
171172
for (let i = 0; i <= NUM_RETRIES; i++) {
172173
try {
173174
return await action()
174175
} catch (e) {
175176
// Check if error is retryable (system errors, not user errors)
176177
const isRetryable = isRetryableError(e)
177-
178+
178179
console.error(`AI Search attempt ${i + 1} failed:`, e)
179-
180+
180181
if (!isRetryable || i === NUM_RETRIES) {
181182
throw e
182183
}
183-
184+
184185
// Exponential backoff with jitter
185186
const delay = Math.random() * INIT_RETRY_MS * Math.pow(2, i)
186187
await scheduler.wait(delay)
@@ -200,7 +201,7 @@ function isRetryableError(error: unknown): boolean {
200201
// Retry server errors (5xx) and rate limits (429), not client errors (4xx)
201202
return status >= 500 || status === 429
202203
}
203-
204+
204205
// Handle network errors, timeouts, etc.
205206
if (error instanceof Error) {
206207
const errorMessage = error.message.toLowerCase()
@@ -211,7 +212,7 @@ function isRetryableError(error: unknown): boolean {
211212
errorMessage.includes('fetch')
212213
)
213214
}
214-
215+
215216
// Default to retryable for unknown errors (conservative approach)
216217
return true
217-
}
218+
}

pnpm-lock.yaml

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)