context7

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Context7 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:
  • libraryName
    : The library name (e.g., "react", "nextjs", "fastapi")
  • query
    : Search context to help find the right library
The response contains a
results
array with library objects. Use the
id
field from the first result.
首先搜索对应库以获取其ID:
GET https://context7.com/api/v2/libs/search?libraryName=<library>&query=<context>
参数:
  • libraryName
    :库的名称(例如:"react"、"nextjs"、"fastapi")
  • query
    :帮助定位对应库的搜索上下文
返回结果中包含
results
数组,数组元素为库对象,使用第一个结果中的
id
字段即可。

Step 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:
  • libraryId
    : The ID from step 1 (e.g., "/vercel/next.js")
  • query
    : Natural language question about the documentation
This returns ranked code snippets and documentation matching your query.
使用库ID来获取相关文档:
GET https://context7.com/api/v2/context?libraryId=<id>&query=<question>
参数:
  • libraryId
    :步骤1中获取的ID(例如:"/vercel/next.js")
  • query
    :关于文档的自然语言问题
该接口会返回与你的查询匹配的、已排序的代码片段和文档内容。

Example Usage

示例用法

When the user asks about a library:
  1. Search for the library: Fetch
    https://context7.com/api/v2/libs/search?libraryName=nextjs&query=routing
    Extract the library ID from the response (e.g., "/vercel/next.js")
  2. Fetch documentation: Fetch
    https://context7.com/api/v2/context?libraryId=/vercel/next.js&query=How to setup dynamic routes
  3. Present the results to the user with the relevant code examples and documentation.
当用户询问某个库的相关问题时:
  1. 搜索对应库: 请求
    https://context7.com/api/v2/libs/search?libraryName=nextjs&query=routing
    从返回结果中提取库ID(例如:"/vercel/next.js")
  2. 获取文档: 请求
    https://context7.com/api/v2/context?libraryId=/vercel/next.js&query=How to setup dynamic routes
  3. 向用户展示结果,包含相关的代码示例和文档内容。

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密钥即可使用,但有速率限制约束