documentation-lookup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDocumentation Lookup (Context7)
文档查询(Context7)
When the user asks about libraries, frameworks, or APIs, fetch current documentation via the Context7 MCP (tools and ) instead of relying on training data.
resolve-library-idquery-docs当用户询问库、框架或API相关问题时,通过Context7 MCP(工具和)获取最新文档,而非依赖训练数据。
resolve-library-idquery-docsCore Concepts
核心概念
- Context7: MCP server that exposes live documentation; use it instead of training data for libraries and APIs.
- resolve-library-id: Returns Context7-compatible library IDs (e.g. ) from a library name and query.
/vercel/next.js - query-docs: Fetches documentation and code snippets for a given library ID and question. Always call resolve-library-id first to get a valid library ID.
- Context7:提供实时文档的MCP服务器;针对库和API相关问题,使用它替代训练数据。
- resolve-library-id:根据库名称和查询内容返回兼容Context7的库ID(例如)。
/vercel/next.js - query-docs:根据给定的库ID和问题获取文档及代码片段。必须先调用resolve-library-id获取有效的库ID,再调用此工具。
When to use
使用场景
Activate when the user:
- Asks setup or configuration questions (e.g. "How do I configure Next.js middleware?")
- Requests code that depends on a library ("Write a Prisma query for...")
- Needs API or reference information ("What are the Supabase auth methods?")
- Mentions specific frameworks or libraries (React, Vue, Svelte, Express, Tailwind, Prisma, Supabase, etc.)
Use this skill whenever the request depends on accurate, up-to-date behavior of a library, framework, or API. Applies across harnesses that have the Context7 MCP configured (e.g. Claude Code, Cursor, Codex).
在以下场景触发该功能:
- 用户提出设置或配置问题(例如:“如何配置Next.js中间件?”)
- 用户请求依赖特定库的代码(“编写一个Prisma查询以...”)
- 用户需要API或参考信息(“Supabase有哪些认证方法?”)
- 用户提及特定框架或库(React、Vue、Svelte、Express、Tailwind、Prisma、Supabase等)
当请求依赖库、框架或API的准确、最新行为时,即可使用该功能。适用于所有配置了Context7 MCP的环境(如Claude Code、Cursor、Codex)。
How it works
工作流程
Step 1: Resolve the Library ID
步骤1:解析库ID
Call the resolve-library-id MCP tool with:
- libraryName: The library or product name taken from the user's question (e.g. ,
Next.js,Prisma).Supabase - query: The user's full question. This improves relevance ranking of results.
You must obtain a Context7-compatible library ID (format or ) before querying docs. Do not call query-docs without a valid library ID from this step.
/org/project/org/project/version调用resolve-library-id MCP工具,传入以下参数:
- libraryName:从用户问题中提取的库或产品名称(例如、
Next.js、Prisma)。Supabase - query:用户的完整问题。这有助于提升结果的相关性排序。
在查询文档前,必须先获取兼容Context7的库ID(格式为或)。未通过此步骤获取有效库ID时,请勿调用query-docs。
/组织/项目/组织/项目/版本Step 2: Select the Best Match
步骤2:选择最佳匹配结果
From the resolution results, choose one result using:
- Name match: Prefer exact or closest match to what the user asked for.
- Benchmark score: Higher scores indicate better documentation quality (100 is highest).
- Source reputation: Prefer High or Medium reputation when available.
- Version: If the user specified a version (e.g. "React 19", "Next.js 15"), prefer a version-specific library ID if listed (e.g. ).
/org/project/v1.2.0
从解析结果中,依据以下规则选择最优结果:
- 名称匹配:优先选择与用户请求完全匹配或最接近的结果。
- 基准分数:分数越高表示文档质量越好(满分100)。
- 来源可信度:优先选择可信度为高或中的来源(若有标注)。
- 版本匹配:若用户指定了版本(例如“React 19”、“Next.js 15”),优先选择对应版本的库ID(例如)。
/组织/项目/v1.2.0
Step 3: Fetch the Documentation
步骤3:获取文档
Call the query-docs MCP tool with:
- libraryId: The selected Context7 library ID from Step 2 (e.g. ).
/vercel/next.js - query: The user's specific question or task. Be specific to get relevant snippets.
Limit: do not call query-docs (or resolve-library-id) more than 3 times per question. If the answer is unclear after 3 calls, state the uncertainty and use the best information you have rather than guessing.
调用query-docs MCP工具,传入以下参数:
- libraryId:步骤2中选择的Context7库ID(例如)。
/vercel/next.js - query:用户的具体问题或任务。越具体越容易获取相关的代码片段。
限制:每个问题中调用query-docs(或resolve-library-id)的次数不超过3次。若3次调用后仍无法得到清晰答案,请说明不确定性,并使用已获取的最佳信息作答,避免猜测。
Step 4: Use the Documentation
步骤4:使用文档内容作答
- Answer the user's question using the fetched, current information.
- Include relevant code examples from the docs when helpful.
- Cite the library or version when it matters (e.g. "In Next.js 15...").
- 利用获取到的最新信息回答用户问题。
- 若有帮助,可包含文档中的相关代码示例。
- 当版本相关时,注明库或版本信息(例如:“在Next.js 15中...”)。
Examples
示例
Example: Next.js middleware
示例:Next.js中间件配置
- Call resolve-library-id with ,
libraryName: "Next.js".query: "How do I set up Next.js middleware?" - From results, pick the best match (e.g. ) by name and benchmark score.
/vercel/next.js - Call query-docs with ,
libraryId: "/vercel/next.js".query: "How do I set up Next.js middleware?" - Use the returned snippets and text to answer; include a minimal example from the docs if relevant.
middleware.ts
- 调用resolve-library-id,参数为,
libraryName: "Next.js"。query: "如何设置Next.js中间件?" - 根据名称和基准分数,从结果中选择最佳匹配项(例如)。
/vercel/next.js - 调用query-docs,参数为,
libraryId: "/vercel/next.js"。query: "如何设置Next.js中间件?" - 使用返回的代码片段和文本内容作答;若相关,可包含文档中的最简示例。
middleware.ts
Example: Prisma query
示例:Prisma查询
- Call resolve-library-id with ,
libraryName: "Prisma".query: "How do I query with relations?" - Select the official Prisma library ID (e.g. ).
/prisma/prisma - Call query-docs with that and the query.
libraryId - Return the Prisma Client pattern (e.g. or
include) with a short code snippet from the docs.select
- 调用resolve-library-id,参数为,
libraryName: "Prisma"。query: "如何查询关联数据?" - 选择官方Prisma库ID(例如)。
/prisma/prisma - 使用该和查询内容调用query-docs。
libraryId - 返回Prisma Client的使用模式(例如或
include),并附上文档中的简短代码片段。select
Example: Supabase auth methods
示例:Supabase认证方法
- Call resolve-library-id with ,
libraryName: "Supabase".query: "What are the auth methods?" - Pick the Supabase docs library ID.
- Call query-docs; summarize the auth methods and show minimal examples from the fetched docs.
- 调用resolve-library-id,参数为,
libraryName: "Supabase"。query: "有哪些认证方法?" - 选择Supabase文档对应的库ID。
- 调用query-docs;总结认证方法,并展示从获取的文档中提取的最简示例。
Best Practices
最佳实践
- Be specific: Use the user's full question as the query where possible for better relevance.
- Version awareness: When users mention versions, use version-specific library IDs from the resolve step when available.
- Prefer official sources: When multiple matches exist, prefer official or primary packages over community forks.
- No sensitive data: Redact API keys, passwords, tokens, and other secrets from any query sent to Context7. Treat the user's question as potentially containing secrets before passing it to resolve-library-id or query-docs.
- 精准查询:尽可能使用用户的完整问题作为查询参数,以提升结果相关性。
- 版本感知:当用户提及版本时,若解析步骤中存在对应版本的库ID,请优先使用。
- 优先官方来源:当存在多个匹配结果时,优先选择官方或核心包,而非社区分支。
- 敏感数据防护:在将查询内容发送至Context7前,需编辑掉API密钥、密码、令牌等敏感信息。在调用resolve-library-id或query-docs前,需先检查用户问题中是否包含敏感信息。",