context7
Look up live, accurate documentation for any library via the context7-mcp server. Prevents hallucinated APIs by fetching real, indexed documentation at query time.
When to Use
Use this skill any time you need accurate, current details about a library — method signatures, config schemas, integration examples, version-specific behaviour. context7 indexes 5000+ libraries including OpenClaw, LangChain, Next.js, Supabase, FastAPI, and more.
Do not rely on training data alone for library-specific questions; use this skill instead.
How context7-mcp Works
context7-mcp is a Model Context Protocol (MCP) server that queries context7.com for indexed documentation. It exposes two tools:
- -
resolve-library-id — resolve a library name to its context7 library ID - INLINECODE1 — fetch documentation snippets for a specific library + query
The server runs via npx -y @upstash/context7-mcp with no auth required.
Workflow
Step 1: Resolve the library ID
Call resolve-library-id with the library name and your task as the query. Pick the result with the highest Benchmark Score and Source Reputation: High or Medium that matches your intent.
CODEBLOCK0
Use the returned library ID (format: /org/project) in step 2.
Step 2: Fetch documentation
Call query-docs with the library ID and a specific, task-focused query. Narrow queries return better results than broad ones.
CODEBLOCK1
Step 3: Apply the result
Use the returned code snippets and prose directly. They come with source URLs — cite them when precision matters.
Tips
- - Narrow queries beat broad ones. "How to authenticate with JWT in Express" beats "authentication".
- Try multiple queries if the first result is shallow — rephrase around what you actually need to do.
- Use the source URL in results to fetch more context with
web_fetch if a snippet is incomplete. - Call
resolve-library-id once per library per session — cache the ID rather than resolving it repeatedly. - Don't call either tool more than 3 times per question — if 3 calls haven't found it, use the best result you have.
OpenClaw MCP Integration
If context7-mcp is configured as an OpenClaw MCP server, the tools (resolve-library-id, query-docs) appear natively in your tool surface without running a subprocess. Apply the same workflow — the tool names and arguments are identical.
To check if it's configured: run /mcp show and look for context7.
To configure it (operator slash command):
CODEBLOCK2
Manual Testing
To verify context7-mcp works on your system:
CODEBLOCK3
Expected output includes resolve-library-id and query-docs.
context7
通过 context7-mcp 服务器实时查找任何库的准确文档。通过在查询时获取真实、已索引的文档,防止出现虚构的 API。
使用时机
当你需要关于某个库的准确、最新详细信息时使用此技能——包括方法签名、配置模式、集成示例、版本特定行为。context7 索引了 5000+ 个库,包括 OpenClaw、LangChain、Next.js、Supabase、FastAPI 等。
不要仅依赖训练数据来回答与库相关的问题;请改用此技能。
context7-mcp 的工作原理
context7-mcp 是一个模型上下文协议(MCP)服务器,用于查询 context7.com 的索引文档。它提供两个工具:
- - resolve-library-id — 将库名称解析为其 context7 库 ID
- query-docs — 获取特定库 + 查询的文档片段
该服务器通过 npx -y @upstash/context7-mcp 运行,无需身份验证。
工作流程
第 1 步:解析库 ID
使用库名称和你的任务作为查询调用 resolve-library-id。选择具有最高基准分数且来源信誉:高或中且符合你意图的结果。
resolve-library-id(
libraryName: openclawai,
query: 如何配置 mcp.servers
)
在第 2 步中使用返回的库 ID(格式:/组织/项目)。
第 2 步:获取文档
使用库 ID 和具体的、针对任务的查询调用 query-docs。窄查询比宽查询能获得更好的结果。
query-docs(
libraryId: /websites/openclaw_ai,
query: mcp.servers 配置 添加 本地 stdio 进程
)
第 3 步:应用结果
直接使用返回的代码片段和文本。它们附带来源 URL——在需要精确性时引用它们。
提示
- - 窄查询优于宽查询。如何在 Express 中使用 JWT 进行身份验证优于身份验证。
- 如果第一个结果不够深入,尝试多个查询——围绕你实际需要做的事情重新表述。
- 使用结果中的来源 URL,如果片段不完整,可以通过 web_fetch 获取更多上下文。
- 每个会话每个库只调用一次 resolve-library-id——缓存 ID 而不是重复解析。
- 每个问题不要调用任一工具超过 3 次——如果 3 次调用仍未找到,使用你拥有的最佳结果。
OpenClaw MCP 集成
如果 context7-mcp 被配置为 OpenClaw MCP 服务器,则工具(resolve-library-id、query-docs)会原生出现在你的工具界面中,无需运行子进程。应用相同的工作流程——工具名称和参数完全相同。
要检查是否已配置:运行 /mcp show 并查找 context7。
要配置它(操作员斜杠命令):
/mcp set context7={\command\:\npx\,\args\:[\-y\,\@upstash/context7-mcp\]}
手动测试
要验证 context7-mcp 在你的系统上是否正常工作:
bash
echo {jsonrpc:2.0,id:1,method:initialize,params:{protocolVersion:2024-11-05,capabilities:{},clientInfo:{name:test,version:1}}}
{jsonrpc:2.0,id:2,method:tools/list,params:{}} \
| npx -y @upstash/context7-mcp 2>/dev/null | grep name
预期输出包括 resolve-library-id 和 query-docs。