The resolveLibraryId tool searches Context7's library database and returns matching results with their Context7-compatible library IDs. This is typically the first step in a documentation lookup workflow.
Usage#
Configuration#
Parameters#
Returns#
Returns an AI SDK tool that can be used with generateText, streamText, or agents.
Tool Behavior#
When the AI model calls this tool, it:
- Takes a
queryandlibraryNameparameter from the model - Searches Context7's database for matching libraries
- Returns formatted results including:
- Library ID (e.g.,
/reactjs/react.dev) - Title and description
- Number of code snippets available
- Source reputation score
- Available versions
- Library ID (e.g.,
Input Schema#
The tool accepts the following input from the AI model:
The user's original question or task. This is used to rank library results by relevance to what the user is trying to accomplish.
Library name to search for (e.g., "react", "next.js", "vue")
Output Format#
On success, the tool returns the search results as plain text, formatted for easy consumption by the AI model:
On failure:
Examples#
Basic Usage#
With Custom API Key#
Inspecting Tool Calls#
Selection Guidance#
The tool's description instructs the AI model to select libraries based on:
- Name similarity - Exact matches are prioritized
- Description relevance - How well the description matches the query intent
- Documentation coverage - Libraries with more code snippets are preferred
- Source reputation - High/Medium reputation sources are more authoritative
- Benchmark score - Quality indicator (100 is the highest)
Related#
- queryDocs - Fetch documentation using the resolved library ID
- Context7Agent - Pre-built agent that handles the full workflow