Skip to main content

Overview

Context7 can retrieve documentation for specific versions of libraries. This ensures you get accurate, version-appropriate code examples and API references.

Why Specify Versions?

Libraries change over time. An API that works in version 2 might not exist or work differently in version 3. Specifying versions helps you:
  • Get documentation matching your project’s dependencies
  • Avoid breaking changes from newer versions
  • Understand migration paths between versions
  • Work with legacy codebases accurately
Without version specification, Context7 typically returns documentation for the latest stable version.

How to Specify Versions

Simply mention the version number in your prompt. Context7’s natural language processing automatically detects version references.

Basic Version Syntax

How do I set up Next.js 14 middleware? use context7
Context7 automatically matches the appropriate version documentation.

Natural Language Versions

You can also use natural language to refer to versions:
How do I use server actions in the latest Next.js? use context7
Show me authentication for Supabase v2. use context7
What changed in React 18? use context7

Version Format Examples

Context7 recognizes various version formats:
Next.js 14
React 18.2
Vue 3.4.21
Next.js v14
Supabase v2.38
MongoDB v7.0
How do I use middleware in Next.js version 14?
Show me hooks from React 18
use library /vercel/next.js version 14
use library /facebook/react v18

Combining Versions with Library IDs

For maximum precision, combine version specification with library IDs:
Implement authentication with Supabase v2.38. 
use library /supabase/supabase for API and docs.
This ensures:
  • Correct library (no ambiguity)
  • Correct version (exact match)
  • Faster response (skips library search)

Version Availability

Not all versions may be available in Context7’s index. Here’s what to expect:

Latest Versions

Current and recent major versions are typically well-covered.

Older Versions

Some older versions may have limited or no documentation.

Beta/RC Versions

Pre-release versions may not be indexed.

Deprecated Versions

Very old or deprecated versions might not be available.
If a specific version isn’t available, Context7 will return the closest available version or the latest version.

Checking Your Project’s Versions

Before requesting documentation, check which versions your project uses:
# Check package.json
cat package.json | grep "next\|react\|vue"

# Check installed version
npm list next
npm list react

Practical Examples

Example 1: Next.js Middleware

1

Check your Next.js version

npm list next
# Output: [email protected]
2

Request version-specific docs

Create a Next.js 14 middleware that checks for authentication.
use context7
3

Get accurate results

Context7 returns middleware examples specific to Next.js 14’s App Router, not the older Pages Router.

Example 2: React Hooks Migration

What's the difference between React 17 and React 18 hooks? use context7
This helps you understand what changed between versions.

Example 3: Supabase Authentication

Show me how to set up email authentication with Supabase 2.x. 
use library /supabase/supabase for API and docs.
Ensures you get v2 authentication patterns, not v1.

Version Ranges

While Context7 doesn’t support exact semver ranges, you can describe version ranges in natural language:
Show me features available in Next.js 13 and later. use context7
What authentication methods work with Supabase v2 or higher? use context7

SDK Usage with Versions

When using the Context7 SDK, include version information in your query:
import { Context7 } from "@upstash/context7-sdk";

const client = new Context7({
  apiKey: process.env.CONTEXT7_API_KEY,
});

// Include version in the query
const docs = await client.getContext(
  "How do I use middleware in Next.js 14?",
  "/vercel/next.js"
);

// Or be more explicit
const docs = await client.getContext(
  "middleware authentication patterns for version 14",
  "/vercel/next.js"
);

Troubleshooting Version Requests

Problem: Requested Next.js 14 docs but got Next.js 13 examples.Solutions:
  1. Be more explicit: “Next.js version 14” instead of “Next.js 14”
  2. Mention version multiple times in your prompt
  3. Use library ID with version: use library /vercel/next.js v14
  4. Check if the specific version is indexed on context7.com
Problem: The version you requested doesn’t exist in Context7.Solutions:
  1. Check if you have the version number correct
  2. Try a nearby version (e.g., 14.0 instead of 14.1)
  3. Use the latest version if your version is very old
  4. Submit the library version to Context7
Problem: Not sure which version Context7 used in its response.Solutions:
  1. Ask explicitly: “Which version of Next.js are these examples from?”
  2. Check the documentation URLs in the response
  3. Look for version-specific features in code examples
Problem: Getting examples from multiple versions mixed together.Solutions:
  1. Use library ID to reduce ambiguity
  2. Ask for specific version in each prompt
  3. Add a rule that specifies your project’s versions:
    This project uses Next.js 14 and React 18. Always fetch docs for these versions.
    

Version-Specific Rules

You can add version information to your project rules:
.cursorrules
# Project Stack Versions
- Next.js 14.1
- React 18.2
- Supabase 2.38
- TypeScript 5.3

When using Context7 MCP, always request documentation for these specific versions.
This ensures consistency across all Context7 invocations.

Best Practices

1

Know your versions

Keep track of the library versions your project uses.
2

Be specific

Include version numbers in prompts when it matters:
  • Migration questions
  • Breaking change concerns
  • Legacy codebase work
3

Use latest for new projects

For greenfield projects, you can usually omit version numbers to get the latest docs.
4

Document in rules

Add your project’s versions to your rules file for consistency.

Next Steps

Best Practices

Learn more ways to optimize your Context7 usage.

Adding Libraries

Submit a library or version to Context7.

Build docs developers (and LLMs) love