context7
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContext7
Context7
Workflow
工作流程
- Identify the library/framework involved (and the language/ecosystem).
- Determine the installed version from the repo when possible.
- Resolve the Context7 library ID.
- Query Context7 docs for the user's exact question (narrow, API-surface specific).
- Answer using doc-backed facts and note any version-specific caveats.
- 确定涉及的库/框架(以及对应的语言/生态系统)。
- 尽可能从仓库中确定已安装的版本。
- 解析Context7库ID。
- 查询Context7文档以解答用户的具体问题(聚焦于特定API层面)。
- 基于文档中的事实进行回答,并标注任何版本相关的注意事项。
Version Detection (Repo-Local)
版本检测(仓库本地)
- JavaScript/Node: check ,
package.json,package-lock.json,pnpm-lock.yaml.yarn.lock - Python: check ,
pyproject.toml,requirements*.txt,poetry.lock.Pipfile.lock - Go: check .
go.mod - Rust: check /
Cargo.toml.Cargo.lock - Ruby: check .
Gemfile.lock - .NET: check /
*.csproj.packages.lock.json
If the version cannot be determined, assume the user means the latest docs and phrase the answer as such.
- JavaScript/Node:检查、
package.json、package-lock.json、pnpm-lock.yaml。yarn.lock - Python:检查、
pyproject.toml、requirements*.txt、poetry.lock。Pipfile.lock - Go:检查。
go.mod - Rust:检查/
Cargo.toml。Cargo.lock - Ruby:检查。
Gemfile.lock - .NET:检查/
*.csproj。packages.lock.json
如果无法确定版本,则默认用户指的是最新文档,并在回答中说明这一点。
Tool Usage (MCP)
工具使用(MCP)
- Always call first to get the exact library ID.
resolve-library-id - Then call with a specific, narrow query.
query-docs - Do not call Context7 tools more than 3 times per user question.
- 始终先调用以获取准确的库ID。
resolve-library-id - 然后使用具体、聚焦的查询调用。
query-docs - 针对每个用户问题,调用Context7工具的次数不超过3次。
Example Query Pattern
示例查询模式
- Resolve (call ):
resolve-library-id
yaml
libraryName: "<package/framework name>"
query: "<what the user is trying to do + API names + error strings>"- Query docs (call ):
query-docs
yaml
libraryId: "</org/project[/version]>"
query: "<precise question with config keys / function names / expected behavior>"- 解析(调用):
resolve-library-id
yaml
libraryName: "<包/框架名称>"
query: "<用户的需求 + API名称 + 错误字符串>"- 查询文档(调用):
query-docs
yaml
libraryId: "</组织/项目[/版本]>"
query: "<包含配置键/函数名称/预期行为的精准问题>"Response Rules
回答规则
- Prefer official docs and primary references returned by Context7.
- If docs are ambiguous or missing, ask a targeted follow-up question or state uncertainty.
- If the user's installed version differs materially from the docs, call it out and suggest the relevant migration/upgrade notes.
- 优先使用Context7返回的官方文档和主要参考资料。
- 如果文档模糊或缺失,提出针对性的跟进问题或说明不确定性。
- 如果用户已安装的版本与文档存在显著差异,需指出这一点,并建议查看相关的迁移/升级说明。
References
参考资料
references/context7.md
references/context7.md
Extended Guidance
扩展指导
Use this section for higher-fidelity Context7 usage when the question is ambiguous, version-sensitive,
or likely to change.
当问题模糊、对版本敏感或内容可能发生变化时,使用本节内容来更精准地使用Context7。
Decision Rules (When to Query)
查询决策规则
- Query Context7 if the user names a library, framework, or API surface.
- Query Context7 if the library version is unknown but likely to matter.
- Query Context7 before suggesting configuration flags or function signatures.
- Do not guess on breaking changes; confirm against docs.
- 如果用户提到了某个库、框架或API层面,就查询Context7。
- 如果库版本未知但可能影响结果,就查询Context7。
- 在建议配置标志或函数签名之前,先查询Context7。
- 不要猜测破坏性变更;需对照文档确认。
Version Resolution Tips
版本解析技巧
- Prefer lockfiles over manifests (lockfiles reflect the resolved version).
- If multiple versions exist (monorepo), use the one in the target package.
- If a toolchain is involved (Next.js, Django), check for related config files too.
- 优先使用锁定文件而非清单文件(锁定文件反映的是已解析的版本)。
- 如果存在多个版本(单体仓库),使用目标包中的版本。
- 如果涉及工具链(Next.js、Django),也要检查相关的配置文件。
Query Construction Examples
查询构造示例
text
Query: "How do I configure CORS in FastAPI?"
Better: "FastAPI CORS middleware example with allowed origins and credentials"text
Query: "React state update in a loop"
Better: "React setState functional update in loop, avoid stale state"text
Query: "Prisma transaction"
Better: "Prisma $transaction interactive example with timeout and rollback behavior"text
原查询:"How do I configure CORS in FastAPI?"
优化后:"FastAPI CORS middleware example with allowed origins and credentials"text
原查询:"React state update in a loop"
优化后:"React setState functional update in loop, avoid stale state"text
原查询:"Prisma transaction"
优化后:"Prisma $transaction interactive example with timeout and rollback behavior"Failure Modes and Fixes
失败场景及修复方法
- Library not found:
- Try the official repo name (e.g., ).
vercel/next.js - Try the package name on the registry (e.g., ).
@nestjs/core
- Try the official repo name (e.g.,
- Docs too broad:
- Narrow with function names, config keys, error messages.
- Docs conflict with local version:
- Call out the mismatch and suggest checking migration guides.
- 库未找到:
- 尝试使用官方仓库名称(例如)。
vercel/next.js - 尝试使用注册表上的包名称(例如)。
@nestjs/core
- 尝试使用官方仓库名称(例如
- 文档范围过广:
- 通过函数名称、配置键、错误信息缩小查询范围。
- 文档与本地版本冲突:
- 指出版本不匹配,并建议查看迁移指南。
Response Quality Checklist
回答质量检查清单
- Cite the specific API/config key from docs.
- Note version-specific caveats if the project version is known.
- Provide a minimal working example or code snippet if useful.
- If uncertain, ask a single targeted question rather than guessing.
- 引用文档中的特定API/配置键。
- 如果已知项目版本,标注版本相关的注意事项。
- 如果有用,提供最小可行示例或代码片段。
- 如果不确定,提出一个针对性的问题而非猜测。
Reference Index
参考索引
rg -n "Required Tool Sequence|Resolve the library ID" references/context7.mdrg -n "Version Awareness|installed version" references/context7.mdrg -n "Query Tips|Include the relevant API surface" references/context7.mdrg -n "Failure Modes|cannot be resolved" references/context7.md
rg -n "Required Tool Sequence|Resolve the library ID" references/context7.mdrg -n "Version Awareness|installed version" references/context7.mdrg -n "Query Tips|Include the relevant API surface" references/context7.mdrg -n "Failure Modes|cannot be resolved" references/context7.md
Version Detection Commands (Examples)
版本检测命令示例
bash
rg -n "\"dependencies\"|\"devDependencies\"" package.json
rg -n "go\\s+\\d+\\.\\d+" go.mod
rg -n "django|fastapi|flask" requirements*.txtbash
rg -n "\"dependencies\"|\"devDependencies\"" package.json
rg -n "go\\s+\\d+\\.\\d+" go.mod
rg -n "django|fastapi|flask" requirements*.txtQuery Refinement Steps
查询优化步骤
- Start with the exact API or error string.
- Add the config keys or flags involved.
- Narrow to the specific environment (browser/node/server).
- Re-query if results are too general.
- 从准确的API或错误字符串开始。
- 添加涉及的配置键或标志。
- 缩小到特定环境(浏览器/Node/服务器)。
- 如果结果过于笼统,重新查询。
Output Consistency Checklist
输出一致性检查清单
- Note the library version you used (or that it was unknown).
- Include at least one verified example or usage pattern.
- Call out any breaking changes or deprecations.
- 标注你使用的库版本(或说明版本未知)。
- 至少包含一个经过验证的示例或使用模式。
- 指出任何破坏性变更或弃用内容。
Reference Index (Expanded)
扩展参考索引
rg -n "Resolve the library ID|query docs" references/context7.mdrg -n "Version Awareness|installed" references/context7.mdrg -n "Failure Modes|ambiguous" references/context7.md
rg -n "Resolve the library ID|query docs" references/context7.mdrg -n "Version Awareness|installed" references/context7.mdrg -n "Failure Modes|ambiguous" references/context7.md
Quick Questions (When Stuck)
疑难问题快速排查
- What is the minimal change that solves the issue?
- What is the rollback plan?
- What is the highest-risk assumption?
- What is the simplest validation step?
- What is the known-good baseline?
- What evidence would change the decision?
- What is the user-visible impact?
- What is the operational impact?
- What is the most likely failure mode?
- What is the fastest safe experiment?
- 解决问题的最小变更是什么?
- 回滚方案是什么?
- 风险最高的假设是什么?
- 最简单的验证步骤是什么?
- 已知的可靠基线是什么?
- 哪些证据会改变决策?
- 对用户可见的影响是什么?
- 对运维的影响是什么?
- 最可能的失败场景是什么?
- 最快的安全实验是什么?
Reference Index (Extra)
额外参考索引
rg -n "Checklist|checklist" references/context7.mdrg -n "Example|examples" references/context7.mdrg -n "Workflow|process" references/context7.mdrg -n "Pitfall|anti-pattern" references/context7.mdrg -n "Testing|validation" references/context7.mdrg -n "Security|risk" references/context7.mdrg -n "Configuration|config" references/context7.mdrg -n "Deployment|operations" references/context7.mdrg -n "Troubleshoot|debug" references/context7.mdrg -n "Performance|latency" references/context7.mdrg -n "Reliability|availability" references/context7.mdrg -n "Monitoring|metrics" references/context7.mdrg -n "Error|failure" references/context7.mdrg -n "Decision|tradeoff" references/context7.mdrg -n "Migration|upgrade" references/context7.md
rg -n "Checklist|checklist" references/context7.mdrg -n "Example|examples" references/context7.mdrg -n "Workflow|process" references/context7.mdrg -n "Pitfall|anti-pattern" references/context7.mdrg -n "Testing|validation" references/context7.mdrg -n "Security|risk" references/context7.mdrg -n "Configuration|config" references/context7.mdrg -n "Deployment|operations" references/context7.mdrg -n "Troubleshoot|debug" references/context7.mdrg -n "Performance|latency" references/context7.mdrg -n "Reliability|availability" references/context7.mdrg -n "Monitoring|metrics" references/context7.mdrg -n "Error|failure" references/context7.mdrg -n "Decision|tradeoff" references/context7.mdrg -n "Migration|upgrade" references/context7.md