MCPcopy Index your code
hub / github.com/upstash/context7 / resolveLibrary

Function resolveLibrary

packages/cli/src/utils/api.ts:283–310  ·  view source on GitHub ↗
(
  libraryName: string,
  query?: string,
  accessToken?: string
)

Source from the content-addressed store, hash-verified

281}
282
283export async function resolveLibrary(
284 libraryName: string,
285 query?: string,
286 accessToken?: string
287): Promise<LibrarySearchResponse> {
288 const params = new URLSearchParams({ libraryName });
289 if (query) {
290 params.set("query", query);
291 }
292
293 const response = await fetch(`${baseUrl}/api/v2/libs/search?${params}`, {
294 headers: getAuthHeaders(accessToken),
295 });
296
297 if (!response.ok) {
298 const errorData = (await response.json().catch(() => ({}))) as {
299 error?: string;
300 message?: string;
301 };
302 return {
303 results: [],
304 error: errorData.error || `HTTP error ${response.status}`,
305 message: errorData.message,
306 };
307 }
308
309 return (await response.json()) as LibrarySearchResponse;
310}
311
312export interface GetContextOptions {
313 type?: "json" | "txt";

Callers 1

resolveCommandFunction · 0.85

Calls 1

getAuthHeadersFunction · 0.85

Tested by

no test coverage detected