Fetch up-to-date library documentation via Context7 MCP
Common agent task: an agent needs current, version-specific documentation for a programming library (e.g. Next.js, React, Express) to answer user questions or generate code. Training data may be stale — Context7 provides live docs and code snippets ranked by relevance.
Two-step flow:
resolve-library-id— turn a human library name into the canonical Context7 IDget-library-docs(orquery-docs) — fetch relevant docs for a specific topic
No API key required. Runs via npx -y @upstash/context7-mcp over stdio.
Recipe: Fetch library docs via @upstash/context7-mcp
Server launch
npx -y @upstash/context7-mcp
# stdio transport, no API key, no env vars neededMCP config (claudedesktopconfig.json / settings.json)
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp"]
}
}
}Step 1: resolve-library-id
Turns a human-readable library name into the canonical Context7 ID.
Tool call:
{
"name": "resolve-library-id",
"arguments": {
"libraryName": "Next.js",
"query": "How to use the App Router with server components"
}
}Real response (executed 2026-06-10): Returns ranked results. Top hit:
- Library ID:
/vercel/next.js - Snippets: 5763
- Reputation: High
- Benchmark: 92.6
- Versions available: v16.2.2, v16.1.6, v15.1.11, v14.3.0-canary.87, v13.5.11, v12.3.7, v11.1.3, …
Also returns related libraries (next.js commerce, authkit-nextjs, learn-next.js) — useful for disambiguation.
Step 2: query-docs
Fetches relevant documentation chunks + code examples for a topic.
Tool call:
{
"name": "get-library-docs",
"arguments": {
"context7CompatibleLibraryID": "/vercel/next.js",
"topic": "How to use the App Router with server components",
"tokens": 500
}
}Real response (executed 2026-06-10): Returned 5 documentation chunks with source URLs, including:
- App Router SSR with fetch() and no-store — full TSX example of async Server Component with
cache: 'no-store' - App Router glossary — "built on top of React Server Components, file-system based routing"
- Server Component definition — "default component type in the App Router, rendering on the server"
- Production checklist — Server Components "do not contribute to client-side JavaScript bundle sizes"
Each chunk includes its GitHub source URL for traceability.
Key details
- Two tools exposed:
resolve-library-id,get-library-docs(aliased asquery-docsin some versions) - Token budget: the
tokensparam caps response size (default varies, 500–5000 is practical) - Version pinning: pass
/vercel/next.js/v16.2.2to get version-specific docs - No auth, no API key, no env vars — fully credential-free
- Cold start: ~3-5s on first npx invocation (package download), <1s thereafter
{ "server": "@upstash/context7-mcp", "launch": "npx -y @upstash/context7-mcp", "transport": "stdio", "tools_discovered": ["resolve-library-id", "get-library-docs"], "call_1": { "method": "tools/call", "tool": "resolve-library-id", "args": { "libraryName": "Next.js", "query": "How to use the App Router with server components" }, "result_summary": "Top hit: /vercel/next.js — 5763 snippets, High reputation, benchmark 92.6. 5 total results returned." }, "call_2": { "method": "tools/call", "tool": "get-library-docs", "args": { "context7CompatibleLibraryID": "/vercel/next.js", "topic": "How to use the App Router with server components", "tokens": 500 }, "result_summary": "5 doc chunks returned with TSX code examples and GitHub source URLs. Topics: SSR with fetch/no-store, App Router glossary, Server Component definition, production checklist." }, "executed_at": "2026-06-10T10:09-10:11Z", "credential_free": true }