MCPcopy
hub / github.com/facebook/react / queryAlgolia

Function queryAlgolia

compiler/packages/react-mcp-server/src/utils/algolia.ts:45–119  ·  view source on GitHub ↗
(
  message: string | Array<string>,
)

Source from the content-addressed store, hash-verified

43}
44
45export async function queryAlgolia(
46 message: string | Array<string>,
47): Promise<Array<string>> {
48 const {results} = await ALGOLIA_CLIENT.search<DocSearchHit>({
49 requests: [
50 {
51 query: Array.isArray(message) ? message.join('\n') : message,
52 indexName: ALGOLIA_CONFIG.indexName,
53 attributesToRetrieve: [
54 'hierarchy.lvl0',
55 'hierarchy.lvl1',
56 'hierarchy.lvl2',
57 'hierarchy.lvl3',
58 'hierarchy.lvl4',
59 'hierarchy.lvl5',
60 'hierarchy.lvl6',
61 'content',
62 'url',
63 ],
64 attributesToSnippet: [
65 `hierarchy.lvl1:10`,
66 `hierarchy.lvl2:10`,
67 `hierarchy.lvl3:10`,
68 `hierarchy.lvl4:10`,
69 `hierarchy.lvl5:10`,
70 `hierarchy.lvl6:10`,
71 `content:10`,
72 ],
73 snippetEllipsisText: '…',
74 hitsPerPage: 30,
75 attributesToHighlight: [
76 'hierarchy.lvl0',
77 'hierarchy.lvl1',
78 'hierarchy.lvl2',
79 'hierarchy.lvl3',
80 'hierarchy.lvl4',
81 'hierarchy.lvl5',
82 'hierarchy.lvl6',
83 'content',
84 ],
85 },
86 ],
87 });
88 const firstResult = results[0] as SearchResponse<DocSearchHit>;
89 const {hits} = firstResult;
90 const deduped = new Map();
91 for (const hit of hits) {
92 // drop hashes to dedupe properly
93 const u = new URL(hit.url);
94 if (deduped.has(u.pathname)) {
95 continue;
96 }
97 deduped.set(u.pathname, hit);
98 }
99 const pages: Array<string | null> = await Promise.all(
100 Array.from(deduped.values()).map(hit => {
101 return fetch(hit.url, {
102 headers: {

Callers 1

index.tsFile · 0.90

Calls 8

fetchFunction · 0.85
joinMethod · 0.80
setMethod · 0.80
hasMethod · 0.65
mapMethod · 0.65
valuesMethod · 0.65
thenMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected