Context7 - Library Documentation
Fetch up-to-date documentation for any library with intelligent chunking and reranking.
Workflow
Step 1: Resolve Library ID
First, resolve the library name to a Context7-compatible ID:
mcp__context7__resolve-library-id({ libraryName: "<package name>" })
Example: libraryName: "react" → returns /facebook/react
Step 2: Get Documentation
Fetch docs with topic focus and token budget:
mcp__context7__get-library-docs({
context7CompatibleLibraryID: "<library_id>",
topic: "<specific topic>",
tokens: 5000
})
Step 3: Rerank Results
After receiving documentation, apply this mental reranking:
- Score by relevance - Prioritize chunks containing query terms
- Consider recency - Newer API patterns over deprecated ones
- Focus on examples - Code snippets > prose descriptions
- Limit to top 5 - Present only the 5 most relevant chunks
Quick Reference
| Library Type | Example Query | Topic |
|---|---|---|
| React/Vue/Angular | "React hooks for state" | "hooks" or "useState" |
| FastAPI/Flask/Django | "FastAPI authentication" | "auth" or "security" |
| Pandas/NumPy | "pandas merge dataframes" | "merge" or "join" |
| SQLAlchemy/Prisma | "SQLAlchemy relationships" | "relationships" |
| Testing libs | "pytest fixtures" | "fixtures" |
Token Budget Guidelines
- Quick lookup: 2000-3000 tokens
- Deep dive: 5000-8000 tokens
- Comprehensive: 10000+ tokens
Reranking Script
For programmatic reranking, use the wrapper script:
# Process context7 output and rerank
python ~/.config/context7/context7_wrapper.py process \
--query "authentication middleware" \
--top 5 \
--input docs.md
Error Handling
If library not found:
- Try alternative names (e.g., "nextjs" vs "next.js")
- Check for organization prefix (e.g., "/vercel/next.js")
- Search for related libraries
Examples
React Hooks
1. resolve-library-id({ libraryName: "react" })
2. get-library-docs({
context7CompatibleLibraryID: "/facebook/react",
topic: "hooks",
tokens: 5000
})
FastAPI Auth
1. resolve-library-id({ libraryName: "fastapi" })
2. get-library-docs({
context7CompatibleLibraryID: "/tiangolo/fastapi",
topic: "security oauth2",
tokens: 5000
})
