context7
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContext7 Documentation Fetcher
Context7 文档获取工具
This skill fetches up-to-date documentation and code examples from libraries using the Context7 API.
此技能通过Context7 API获取各库的最新文档和代码示例。
Standard Workflow
标准工作流程
Context7 requires a two-step process:
Context7需要遵循两步流程:
Step 1: Search for the Library ID
步骤1:搜索库ID
First, search for the library to get its ID:
GET https://context7.com/api/v2/libs/search?libraryName=<library>&query=<context>Parameters:
- : The library name (e.g., "react", "nextjs", "fastapi")
libraryName - : Search context to help find the right library
query
The response contains a array with library objects. Use the field from the first result.
resultsid首先搜索对应库以获取其ID:
GET https://context7.com/api/v2/libs/search?libraryName=<library>&query=<context>参数:
- :库的名称(例如:"react"、"nextjs"、"fastapi")
libraryName - :帮助定位对应库的搜索上下文
query
返回结果中包含数组,数组元素为库对象,使用第一个结果中的字段即可。
resultsidStep 2: Get Documentation Context
步骤2:获取文档上下文
Use the library ID to fetch relevant documentation:
GET https://context7.com/api/v2/context?libraryId=<id>&query=<question>Parameters:
- : The ID from step 1 (e.g., "/vercel/next.js")
libraryId - : Natural language question about the documentation
query
This returns ranked code snippets and documentation matching your query.
使用库ID来获取相关文档:
GET https://context7.com/api/v2/context?libraryId=<id>&query=<question>参数:
- :步骤1中获取的ID(例如:"/vercel/next.js")
libraryId - :关于文档的自然语言问题
query
该接口会返回与你的查询匹配的、已排序的代码片段和文档内容。
Example Usage
示例用法
When the user asks about a library:
-
Search for the library: FetchExtract the library ID from the response (e.g., "/vercel/next.js")
https://context7.com/api/v2/libs/search?libraryName=nextjs&query=routing -
Fetch documentation: Fetch
https://context7.com/api/v2/context?libraryId=/vercel/next.js&query=How to setup dynamic routes -
Present the results to the user with the relevant code examples and documentation.
当用户询问某个库的相关问题时:
-
搜索对应库: 请求从返回结果中提取库ID(例如:"/vercel/next.js")
https://context7.com/api/v2/libs/search?libraryName=nextjs&query=routing -
获取文档: 请求
https://context7.com/api/v2/context?libraryId=/vercel/next.js&query=How to setup dynamic routes -
向用户展示结果,包含相关的代码示例和文档内容。
Tips for Best Results
最佳实践提示
- Use specific, detailed queries rather than vague terms
- Include relevant context in the query (e.g., "useState hook with TypeScript" instead of just "state")
- The API works without an API key but has restricted rate limits
- 使用具体、详细的查询词,不要使用模糊表述
- 在查询中包含相关上下文(例如:"useState hook with TypeScript"而非仅"state")
- 该API无需API密钥即可使用,但有速率限制约束