Context7 - Up-to-date Docs for AI Agents
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
❌ Without Context7
LLMs rely on outdated or generic information about the libraries you use. You get:
- ❌ Code examples are outdated and based on year-old training data
- ❌ Hallucinated APIs that don't even exist
- ❌ Generic answers for old package versions
✅ With Context7
Context7 pulls up-to-date, version-specific documentation and code examples straight from the source — and gives them to your coding agent.
Context7 fetches up-to-date code examples and documentation right into your coding agent's context. No tab-switching, no hallucinated APIs that don't exist, no outdated code generation.
Works in two modes:
- **CLI + Skills** — installs a skill that guides your agent to fetch docs using ctx7 CLI commands (no MCP required)
- **MCP** — registers a Context7 MCP server so your agent can call documentation tools natively
Installation
> [!NOTE]
> **API Key Recommended**: Get a free API key at context7.com/dashboard for higher rate limits.
Set up Context7 for your coding agents with a single command. The ctx7 CLI requires Node.js 22.13 or newer.
Authenticates via OAuth, generates an API key, and installs the appropriate skill. You can choose between CLI + Skills or MCP mode. Use --cursor, --claude, or --opencode to target a specific agent.
To remove the generated setup later, run npx ctx7 remove. If you globally installed the CLI with npm install -g ctx7, remove that package separately with npm uninstall -g ctx7.
To configure manually, use the Context7 server URL https://mcp.context7.com/mcp with your MCP client and pass your API key via the Authorization: Bearer YOUR_API_KEY header. See the link below for client-specific setup instructions.
**Manual Installation / Other Clients →**
Important Tips
Use Library Id
If you already know exactly which library you want to use, add its Context7 ID to your prompt. That way, Context7 can skip the library-matching step and directly retrieve docs.
The slash syntax tells Context7 exactly which library to load docs for.
Specify a Version
To get documentation for a specific library version, just mention the version in your prompt:
Context7 will automatically match the appropriate version.
Add a Rule
If you installed via ctx7 setup, a skill is configured automatically that triggers Context7 for library-related questions. To set up a rule manually instead, add one to your coding agent:
- **Cursor**: Cursor Settings > Rules
- **Claude Code**: CLAUDE.md
- Or the equivalent in your coding agent
**Example rule:**
Available Tools
CLI Commands
- ctx7 library : Searches the Context7 index by library name and returns matching libraries with their IDs.
- ctx7 docs : Retrieves documentation for a library using a Context7-compatible library ID (e.g., /mongodb/docs, /vercel/next.js).
MCP Tools
- resolve-library-id: Resolves a general library name into a Context7-compatible library ID.
- query (required): The user's question or task (used to rank results by relevance)
- libraryName (required): The name of the library to search for
- query-docs: Retrieves documentation for a library using a Context7-compatible library ID.
- libraryId (required): Exact Context7-compatible library ID (e.g., /mongodb/docs, /vercel/next.js)