mirror of
https://github.com/upstash/context7.git
synced 2026-02-07 07:36:41 +00:00
* feat: context7 vercel ai sdk tools package * ci: remove master target condition on test action * ci: manual actions trigger for test * ci: always run all tests * update tests and imports * ci: typecheck command * fix: tests * docs: add readme * update folder structure and tool descriptions * tests: fix test env vars * ci: bump pnpm version * update ai sdk step count api * Add stopWhen to docstring examples * update tests * update prompt name * update context7 agent name * update tool description var to description * make context7agent config optional * ci: add changeset * make context7-sdk peer deps * update pnpm-lock.yaml * update package name to @upstash/context7-tools-ai-sdk * remove check workflow * update pnpm lock * make the agent a class instead of function * replace all name instances * add agent generate test * simplify agent config * fix refs
Upstash Context7 AI SDK
@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:
- Add documentation lookup tools to your AI SDK workflows with
generateTextorstreamText - Create documentation aware agents using the pre-configured
Context7Agent - Build RAG pipelines that retrieve accurate, version specific code examples
The 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 filtering
Quick Start
Install
npm install @upstash/context7-tools-ai-sdk @upstash/context7-sdk ai zod
Get API Key
Get your API key from Context7
Usage
Using Tools with generateText
import { 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);
Using the Context7 Agent
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);
Configuration
Environment Variables
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
Docs
See the documentation for details.
Contributing
Running tests
pnpm test
Building
pnpm build