import { Context7 } from "@upstash/context7-sdk";const client = new Context7();const libraries = await client.searchLibrary( "I need to build a UI", "react");console.log(`Found ${libraries.length} libraries`);libraries.forEach((library) => { console.log(`${library.name}: ${library.description}`);});
import { Context7 } from "@upstash/context7-sdk";const client = new Context7();const libraries = await client.searchLibrary( "I want to build a web app", "next");const sorted = libraries.sort((a, b) => b.benchmarkScore - a.benchmarkScore);const best = sorted[0];console.log(`Best match: ${best.name} (score: ${best.benchmarkScore})`);console.log(`Available snippets: ${best.totalSnippets}`);
import { Context7 } from "@upstash/context7-sdk";const client = new Context7();const libraries = await client.searchLibrary( "I need to build a UI", "react");console.log(`Found ${libraries.length} libraries`);libraries.forEach((library) => { console.log(`${library.name}: ${library.description}`);});
import { Context7 } from "@upstash/context7-sdk";const client = new Context7();const libraries = await client.searchLibrary( "I want to build a web app", "next");const sorted = libraries.sort((a, b) => b.benchmarkScore - a.benchmarkScore);const best = sorted[0];console.log(`Best match: ${best.name} (score: ${best.benchmarkScore})`);console.log(`Available snippets: ${best.totalSnippets}`);
Search across available libraries. Returns an array of matching libraries with metadata useful for selection.
Arguments
string
required
The user’s question or task (used for relevance ranking)
string
required
The library name to search for
SearchLibraryOptions
Show properties
'json' | 'txt'
Format of the response. Defaults to json.
AbortSignal
Abort signal for cancelling this request.
number | false
Per-request timeout in milliseconds. Use false to disable the client timeout.
CacheSetting
Native fetch cache mode. Use false to omit the cache option.
Response
Returns Library[] - an array of library objects.
object
Show properties
string
required
Unique identifier for the library (e.g., /reactjs/react.dev)
string
required
Display name of the library
string
required
Brief description of the library
number
required
Total number of documentation snippets available
number
required
Source reputation score, from 0 to 10
number
required
Quality indicator, from 0 to 100 (100 is the highest)
string[]
Available versions
Examples
import { Context7 } from "@upstash/context7-sdk";const client = new Context7();const libraries = await client.searchLibrary( "I need to build a UI", "react");console.log(`Found ${libraries.length} libraries`);libraries.forEach((library) => { console.log(`${library.name}: ${library.description}`);});
import { Context7 } from "@upstash/context7-sdk";const client = new Context7();const libraries = await client.searchLibrary( "I want to build a web app", "next");const sorted = libraries.sort((a, b) => b.benchmarkScore - a.benchmarkScore);const best = sorted[0];console.log(`Best match: ${best.name} (score: ${best.benchmarkScore})`);console.log(`Available snippets: ${best.totalSnippets}`);
const libraries = await client.searchLibrary("I want to use lodash", "lodash");const library = libraries[0];if (library.versions) { console.log(`Available versions: ${library.versions.join(", ")}`);}
Full Workflow
import { Context7 } from "@upstash/context7-sdk";const client = new Context7();const libraries = await client.searchLibrary( "I want to build a React app", "react");const library = libraries[0];console.log(`Using: ${library.name} (${library.id})`);const context = await client.getContext( "How do I create a component?", library.id);console.log(context);