looking-up-docs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDocumentation Lookup with Context7
借助Context7查找文档
Context7 provides up-to-date, version-specific documentation and code examples directly from source libraries.
Context7可直接从源库提供最新的、特定版本的文档和代码示例。
Why Context7
为什么选择Context7
- Current APIs: No hallucinated or outdated patterns
- Version-specific: Gets docs for exact library versions
- Code examples: Real, working code from actual documentation
- 实时API: 不会出现幻觉内容或过时用法
- 特定版本适配: 获取对应库精确版本的文档
- 真实代码示例: 来自官方文档的可运行代码
Workflow
工作流程
- Resolve library ID: with
mcp__context7__resolve-library-idlibraryName - Get documentation: with
mcp__context7__query-docsandcontext7CompatibleLibraryIDtopic
- 解析库ID:调用并传入
mcp__context7__resolve-library-id参数libraryName - 获取文档:调用并传入
mcp__context7__query-docs和context7CompatibleLibraryID参数topic
Modes
模式
| Mode | Use For |
|---|---|
| API references, code examples (default) |
| Conceptual guides, architecture, tutorials |
| 模式 | 适用场景 |
|---|---|
| API参考、代码示例(默认模式) |
| 概念指南、架构说明、教程 |
Examples
示例
undefinedundefinedReact hooks
React hooks
resolve-library-id: "react"
get-library-docs: context7CompatibleLibraryID="/facebook/react", topic="hooks", mode="code"
resolve-library-id: "react"
get-library-docs: context7CompatibleLibraryID="/facebook/react", topic="hooks", mode="code"
Next.js middleware
Next.js middleware
resolve-library-id: "next.js"
get-library-docs: context7CompatibleLibraryID="/vercel/next.js", topic="middleware"
resolve-library-id: "next.js"
get-library-docs: context7CompatibleLibraryID="/vercel/next.js", topic="middleware"
Go net/http
Go net/http
resolve-library-id: "go net/http"
get-library-docs: context7CompatibleLibraryID="/golang/go", topic="http server"
resolve-library-id: "go net/http"
get-library-docs: context7CompatibleLibraryID="/golang/go", topic="http server"
Kubernetes API
Kubernetes API
resolve-library-id: "kubernetes"
get-library-docs: context7CompatibleLibraryID="/kubernetes/kubernetes", topic="deployment"
undefinedresolve-library-id: "kubernetes"
get-library-docs: context7CompatibleLibraryID="/kubernetes/kubernetes", topic="deployment"
undefinedTips for Better Results
获取更优结果的技巧
Be specific with queries:
- BAD: → returns everything hook-related
topic="hooks" - GOOD: → precise results
topic="useEffect cleanup function"
Filter strategies:
- Use with function/method names:
topictopic="json.Unmarshal" - Include version when relevant:
libraryName="react 18" - Combine with feature context:
topic="middleware error handling"
When results are too broad:
- Narrow the parameter
topic - Try to focus on examples
mode="code" - Paginate: ,
page=2for additional resultspage=3 - Re-resolve library ID with more specific name
Quality check:
- Verify code examples match your library version
- Cross-reference with official docs if uncertain
查询请具体化:
- ❌ 不佳示例:→ 返回所有与hooks相关的内容
topic="hooks" - ✅ 优质示例:→ 返回精准结果
topic="useEffect cleanup function"
过滤策略:
- 结合函数/方法名使用:
topictopic="json.Unmarshal" - 相关时指定版本:
libraryName="react 18" - 搭配功能上下文:
topic="middleware error handling"
结果范围过宽时:
- 缩小参数的范围
topic - 尝试聚焦代码示例
mode="code" - 分页查询:使用,
page=2获取更多结果page=3 - 用更具体的名称重新解析库ID
质量校验:
- 验证代码示例是否匹配你的库版本
- 不确定时交叉参考官方文档
Fallback: Empty or Missing Results
回退方案:无结果或结果缺失时
When Context7 returns no results or doesn't have the library:
当Context7无返回结果或未收录目标库时:
Decision Tree
决策树
Context7 query returns empty?
├── Try broader query (e.g., "hooks" instead of "useCallback")
├── Still empty?
│ ├── Re-resolve library ID with alternative name
│ │ (e.g., "nextjs" → "next.js", "golang" → "go")
│ └── Still empty?
│ ├── Library not indexed → Use fallbacks below
│ └── Very niche library → WebSearch for official docsContext7查询无结果?
├── 尝试更宽泛的查询(例如:用"hooks"替代"useCallback")
├── 仍无结果?
│ ├── 用替代名称重新解析库ID
│ │ (例如:"nextjs" → "next.js", "golang" → "go")
│ └── 仍无结果?
│ ├── 库未被收录 → 使用下方回退方案
│ └── 小众库 → 网页搜索官方文档Fallback Strategies
回退策略
-
Alternative library ID: Try variations
# If "fastapi" fails, try: resolve-library-id: "starlette" # FastAPI's underlying framework resolve-library-id: "pydantic" # Often used with FastAPI -
WebSearch for official docs:
WebSearch: "<library> official documentation <feature>" WebFetch: Official docs URL → extract relevant info -
Source code exploration (for open-source):
# Clone and explore git clone --depth=1 <repo> Grep: "function <name>" --type=<lang> -
Perplexity for recent/niche libraries:
mcp__perplexity-ask__perplexity_ask: "How to use <feature> in <library> 2024"
-
尝试替代库ID:使用变体名称
# 如果"fastapi"失败,尝试: resolve-library-id: "starlette" # FastAPI的底层框架 resolve-library-id: "pydantic" # 常与FastAPI搭配使用 -
网页搜索官方文档:
WebSearch: "<库名> 官方文档 <功能点>" WebFetch: 官方文档URL → 提取相关信息 -
探索源代码(针对开源库):
# 克隆并探索 git clone --depth=1 <仓库地址> Grep: "function <函数名>" --type=<语言> -
针对新/小众库使用Perplexity:
mcp__perplexity-ask__perplexity_ask: "2024年如何在<库名>中使用<功能点>"
Libraries Commonly Not in Context7
Context7通常未收录的库类型
| Library | Fallback |
|---|---|
| Internal/proprietary | Source code + README |
| Very new (<6 months) | WebSearch + official docs |
| Niche/specialized | Perplexity or GitHub issues |
| Language stdlib | Use language docs directly |
| 库类型 | 回退方案 |
|---|---|
| 内部/专有库 | 源代码 + README |
| 极新库(发布不足6个月) | 网页搜索 + 官方文档 |
| 小众/专业库 | Perplexity或GitHub Issues |
| 语言标准库 | 直接使用语言官方文档 |
Example Fallback Flow
回退流程示例
undefinedundefinedInitial attempt fails
初始尝试失败
resolve-library-id: "htmx"
→ No results
resolve-library-id: "htmx"
→ 无结果
Fallback 1: WebSearch
回退方案1:网页搜索
WebSearch: "htmx documentation hx-swap"
→ Found: https://htmx.org/docs/
WebSearch: "htmx documentation hx-swap"
→ 找到:https://htmx.org/docs/
Fallback 2: Fetch docs
回退方案2:获取文档内容
WebFetch: url="https://htmx.org/docs/", prompt="Explain hx-swap attribute"
→ Returns relevant documentation
undefinedWebFetch: url="https://htmx.org/docs/", prompt="解释hx-swap属性"
→ 返回相关文档内容
undefinedWhen to Skip Context7 Entirely
完全跳过Context7的场景
- Asking about breaking changes between versions → WebSearch release notes
- Debugging specific error messages → WebSearch + StackOverflow
- Comparing libraries → Perplexity for analysis
- Very recent features → WebSearch for latest docs
- 查询版本间的破坏性变更 → 网页搜索发布说明
- 调试特定错误信息 → 网页搜索 + StackOverflow
- 对比不同库 → 使用Perplexity进行分析
- 极新功能 → 网页搜索最新文档