packages/tools-ai-sdk/README.md
@upstash/context7-tools-ai-sdk provides Vercel AI SDK compatible tools and agents that give your AI applications access to up to date library documentation through Context7.
Use this package to:
generateText or streamTextContext7AgentThe package provides two main tools:
resolveLibrary - Searches Context7's database to find the correct library IDgetLibraryDocs - Fetches documentation for a specific library with optional topic filteringnpm install @upstash/context7-tools-ai-sdk @upstash/context7-sdk ai zod
Get your API key from Context7
generateTextimport { resolveLibrary, getLibraryDocs } from "@upstash/context7-tools-ai-sdk";
import { generateText, stepCountIs } from "ai";
import { openai } from "@ai-sdk/openai";
const { text } = await generateText({
model: openai("gpt-4o"),
prompt: "How do I use React Server Components?",
tools: {
resolveLibrary: resolveLibrary(),
getLibraryDocs: getLibraryDocs(),
},
stopWhen: stepCountIs(5),
});
console.log(text);
The package provides a pre-configured agent that handles the multi-step workflow automatically:
import { Context7Agent } from "@upstash/context7-tools-ai-sdk";
import { anthropic } from "@ai-sdk/anthropic";
const agent = new Context7Agent({
model: anthropic("claude-sonnet-4-20250514"),
});
const { text } = await agent.generate({
prompt: "How do I set up routing in Next.js?",
});
console.log(text);
Set your API key via environment variable:
CONTEXT7_API_KEY=ctx7sk-...
Then use tools and agents without explicit configuration:
const tool = resolveLibrary(); // Uses CONTEXT7_API_KEY automatically
See the documentation for details.
pnpm test
pnpm build