queryDocs tool fetches documentation for a library using its Context7-compatible library ID and a query. This tool is typically called after resolveLibraryId has identified the correct library.
Usage
Configuration
Parameters
Context7ToolsConfig
Configuration options for the tool.
Returns
Returns an AI SDKtool that can be used with generateText, streamText, or agents.
Tool Behavior
When the AI model calls this tool, it:- Takes a library ID and query from the model
- Fetches documentation from Context7’s API
- Returns the documentation content
Input Schema
The tool accepts the following inputs from the AI model:string
required
Context7-compatible library ID (e.g.,
/reactjs/react.dev, /vercel/next.js)string
required
The question or task you need help with, scoped to a single concept. Be specific and include relevant details, but keep each query to one topic — if the user’s question spans multiple distinct concepts, make a separate call per concept instead of combining them, unless the question is about how the concepts interact. Good: “How to set up authentication with JWT in Express.js” or “React useEffect cleanup function examples”. Bad (too vague): “auth” or “hooks”. Bad (too broad): “routing and auth and caching in Next.js”.
Output Format
On success, the tool returns the documentation as plain text, formatted for easy consumption by the AI model:On Failure
Examples
Basic Usage with Both Tools
With Custom Configuration
Direct Library ID (Skip resolveLibraryId)
If the user provides a library ID directly, the model can skip the resolution step:Multi-Step Documentation Lookup
For comprehensive documentation, the model can make multiple queries:Version-Specific Documentation
Library IDs can include version specifiers:Related
- resolveLibraryId - Search for libraries and get their IDs
- Context7Agent - Pre-built agent that handles the full workflow