Skip to main content
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

Context7ToolsConfig
Configuration options for the tool.

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:
  1. Takes a query and libraryName parameter from the model
  2. Searches Context7’s database for matching libraries
  3. Returns formatted results including:
    • Library ID (e.g., /reactjs/react.dev)
    • Title and description
    • Number of code snippets available
    • Source reputation score
    • Available versions

Input Schema

The tool accepts the following input from the AI model:
string
required
The user’s original question or task. This is used to rank library results by relevance to what the user is trying to accomplish.
string
required
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:
  1. Name similarity - Exact matches are prioritized
  2. Description relevance - How well the description matches the query intent
  3. Documentation coverage - Libraries with more code snippets are preferred
  4. Source reputation - High/Medium reputation sources are more authoritative
  5. Benchmark score - Quality indicator (100 is the highest)
  • queryDocs - Fetch documentation using the resolved library ID
  • Context7Agent - Pre-built agent that handles the full workflow