The 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#
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 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:
Context7-compatible library ID (e.g., /reactjs/react.dev, /vercel/next.js)
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:
The model can request documentation for specific versions when the user asks about a particular version.
Related#
- resolveLibraryId - Search for libraries and get their IDs
- Context7Agent - Pre-built agent that handles the full workflow