-
Notifications
You must be signed in to change notification settings - Fork 48.8k
[mcp] Convert docs resource to tool #33009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ export function printHierarchy( | |
|
||
export async function queryAlgolia( | ||
message: string | Array<string>, | ||
): Promise<Hit<DocSearchHit>[]> { | ||
): Promise<Array<string>> { | ||
const {results} = await ALGOLIA_CLIENT.search<DocSearchHit>({ | ||
requests: [ | ||
{ | ||
|
@@ -87,5 +87,33 @@ export async function queryAlgolia( | |
}); | ||
const firstResult = results[0] as SearchResponse<DocSearchHit>; | ||
const {hits} = firstResult; | ||
return hits; | ||
const deduped = new Map(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How did you figure out to remove duplicated paths? Was the tool spouting out duplicated things? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used the MCP inspector, I noticed it would sometimes return multiple instances of the same url but with a different hash eg |
||
for (const hit of hits) { | ||
// drop hashes to dedupe properly | ||
const u = new URL(hit.url); | ||
if (deduped.has(u.pathname)) { | ||
continue; | ||
} | ||
deduped.set(u.pathname, hit); | ||
} | ||
const pages: Array<string | null> = await Promise.all( | ||
Array.from(deduped.values()).map(hit => { | ||
return fetch(hit.url, { | ||
headers: { | ||
'User-Agent': | ||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36', | ||
}, | ||
}).then(res => { | ||
if (res.ok === true) { | ||
return res.text(); | ||
} else { | ||
console.error( | ||
`Could not fetch docs: ${res.status} ${res.statusText}`, | ||
); | ||
return null; | ||
} | ||
}); | ||
}), | ||
); | ||
return pages.filter(page => page !== null); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the LLM coming up with the query here? Like the URL? Or is it defined somewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah the LLM comes up with the query based on a prompt. the user could type something like "look up the latest docs on viewtransitions" and it would call the tool with this query