Fetch up-to-date documentation for a specific library
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.
The question or task you need help with. Be specific and include relevant details. Good: “How to set up authentication with JWT in Express.js” or “React useEffect cleanup function examples”. Bad: “auth” or “hooks”.
On success, the tool returns the documentation as plain text, formatted for easy consumption by the AI model:
Copy
Ask AI
# Server ComponentsServer Components let you write UI that can be rendered and optionally cached on the server.## Example\`\`\`tsxasync function ServerComponent() { const data = await fetchData(); return <div>{data}</div>;}\`\`\`---# Using Server Components with Client ComponentsYou can import Server Components into Client Components...
No documentation found for library "/invalid/library". This might have happened because you used an invalid Context7-compatible library ID. Use 'resolveLibraryId' to get a valid ID.
import { resolveLibraryId, queryDocs } from "@upstash/context7-tools-ai-sdk";import { generateText, stepCountIs } from "ai";import { openai } from "@ai-sdk/openai";const { text } = await generateText({ model: openai("gpt-5.2"), prompt: "Show me how to set up routing in Next.js App Router", tools: { resolveLibraryId: resolveLibraryId(), queryDocs: queryDocs(), }, stopWhen: stepCountIs(5),});// The model will:// 1. Call resolveLibraryId to get the library ID// 2. Call queryDocs({ libraryId: "/vercel/next.js", query: "routing in App Router" })// 3. Generate a response using the fetched documentation
For comprehensive documentation, the model can make multiple queries:
Copy
Ask AI
import { resolveLibraryId, queryDocs } from "@upstash/context7-tools-ai-sdk";import { generateText, stepCountIs } from "ai";import { anthropic } from "@ai-sdk/anthropic";const { text } = await generateText({ model: anthropic("claude-sonnet-4-20250514"), prompt: "Give me a comprehensive guide to Supabase authentication", tools: { resolveLibraryId: resolveLibraryId(), queryDocs: queryDocs(), }, stopWhen: stepCountIs(8), // Allow more steps for multiple queries});// The model may call queryDocs multiple times with different queries// to gather comprehensive documentation