MCP server providing access to Context7 API for up-to-date code documentation retrieval.
- Documentation Search - Search across thousands of libraries and frameworks
- Code Examples - Get working code examples for specific use cases
- API Reference - Detailed API documentation for functions and classes
- Code Explanation - Understand code with line-by-line explanations
- Troubleshooting - Get help with error messages and bugs
- Best Practices - Learn recommended patterns and anti-patterns
- Migration Guides - Upgrade between versions or switch libraries
- Library Comparison - Compare different libraries for your use case
- Changelog Access - View release notes and breaking changes
- Clone this repository
- Install dependencies:
pip install -r requirements.txt
- Set up your environment variables:
cp .env.example .env
# Edit .env and add your Context7 API key
- Go to https://context7.com/api
- Sign up or sign in
- Generate an API key
- Copy the key and add it to your
.env
file
{
"mcpServers": {
"context7": {
"command": "fastmcp",
"args": ["run", "server.py"],
"env": {
"CONTEXT7_API_KEY": "your_api_key_here"
}
}
}
}
Search for documentation across supported libraries.
Parameters:
query
(required): Search querylanguage
: Filter by language (javascript, python, go, etc.)framework
: Filter by framework (react, django, nextjs, etc.)limit
: Max results (default: 10, max: 50)
Example:
{
"query": "how to use useState in React",
"framework": "react",
"limit": 5
}
Get documentation for a specific library.
Parameters:
library
(required): Library nameversion
: Specific version (default: latest)topic
: Specific topic or module
Example:
{
"library": "react",
"version": "18.2.0",
"topic": "hooks"
}
Get code examples for a specific use case.
Parameters:
library
(required): Library nameuse_case
(required): What you're trying to accomplishlanguage
: Programming language
Example:
{
"library": "express",
"use_case": "JWT authentication middleware"
}
Get explanation of code with documentation references.
Parameters:
code
(required): Code snippet to explainlanguage
: Programming language (auto-detected)context
: Additional context
Example:
{
"code": "const [count, setCount] = useState(0);",
"language": "javascript",
"context": "React component"
}
Get detailed API reference for a function or class.
Parameters:
library
(required): Library nameapi_name
(required): API/function/class nameversion
: Library version (default: latest)
Example:
{
"library": "react",
"api_name": "useState",
"version": "18.2.0"
}
Compare multiple libraries for a use case.
Parameters:
libraries
(required): List of library namesuse_case
(required): What you're buildinglanguage
: Programming language
Example:
{
"libraries": ["react", "vue", "svelte"],
"use_case": "building a todo app"
}
Get migration guide between libraries or versions.
Parameters:
from_library
(required): Current libraryto_library
(required): Target libraryfrom_version
: Current versionto_version
: Target version
Example:
{
"from_library": "react",
"to_library": "react",
"from_version": "17.0.0",
"to_version": "18.0.0"
}
Get best practices for a library.
Parameters:
library
(required): Library nametopic
: Specific topic (performance, security, testing, etc.)
Example:
{
"library": "react",
"topic": "performance"
}
Get help with error messages.
Parameters:
error_message
(required): The error you're seeinglibrary
: Library where error occurredcode_context
: Code causing the error
Example:
{
"error_message": "Cannot read property 'map' of undefined",
"library": "react",
"code_context": "data.map(item => <div>{item}</div>)"
}
List all supported libraries.
Parameters:
language
: Filter by languagecategory
: Filter by category
Example:
{
"language": "python",
"category": "data-science"
}
Get changelog and release notes.
Parameters:
library
(required): Library namefrom_version
: Starting versionto_version
: Ending version (default: latest)
Example:
{
"library": "react",
"from_version": "17.0.0",
"to_version": "18.2.0"
}
{
"tool": "search_documentation",
"query": "authentication with JWT",
"language": "javascript"
}
{
"tool": "get_code_examples",
"library": "pandas",
"use_case": "filter dataframe by multiple conditions"
}
{
"tool": "explain_code",
"code": "useEffect(() => { fetchData(); }, [id]);",
"language": "javascript"
}
{
"tool": "compare_libraries",
"libraries": ["express", "fastify", "koa"],
"use_case": "REST API server"
}
{
"tool": "troubleshoot_error",
"error_message": "Module not found: Can't resolve 'react'",
"library": "react"
}
{
"tool": "get_migration_guide",
"from_library": "webpack",
"to_library": "vite"
}
Context7 supports documentation for:
- JavaScript/TypeScript
- Python
- Go
- Rust
- Java
- C#
- PHP
- Ruby
- Swift
- Kotlin
- Web: React, Vue, Angular, Svelte, Next.js, Nuxt
- Backend: Express, Django, FastAPI, Spring Boot, Rails
- Mobile: React Native, Flutter, SwiftUI
- Data Science: Pandas, NumPy, Scikit-learn, TensorFlow
- DevOps: Docker, Kubernetes, Terraform, Ansible
- Quick documentation lookup while coding
- Find working code examples
- Understand unfamiliar code
- Troubleshoot errors faster
- Learn best practices
- Provide accurate, up-to-date documentation
- Generate code with proper library usage
- Help debug issues with context
- Recommend appropriate libraries
- Assist with migrations and upgrades
The server handles:
- Invalid API keys
- Rate limiting
- Network timeouts
- Invalid library names
- Malformed queries
Context7 API rate limits depend on your plan:
- Free tier: 100 requests/day
- Pro tier: 10,000 requests/day
- Enterprise: Custom limits
Check your usage at: https://context7.com/dashboard
- Be Specific: Include library names and versions when possible
- Use Filters: Narrow searches with language/framework filters
- Cache Results: Store frequently accessed documentation
- Combine Tools: Use search + get_api_reference for comprehensive info
- Error Context: Provide code context for better troubleshooting
- Never commit API keys to version control
- Use environment variables
- Rotate keys regularly
- Monitor usage in dashboard
- Set up usage alerts
- Verify key in
.env
file - Check key is active at context7.com
- Ensure no extra spaces
- Check current usage in dashboard
- Upgrade plan if needed
- Implement caching
- Check library name spelling
- Use list_supported_libraries to verify
- Some libraries may not be indexed yet
MIT License - feel free to use in your projects!