context7

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Context7

Context7

Overview

概述

This skill enables retrieval of current documentation for software libraries and components by querying the Context7 API via curl. Use it instead of relying on potentially outdated training data.
此技能通过curl调用Context7 API,能够检索软件库和组件的最新文档。请使用它来替代可能过时的训练数据。

Workflow

工作流程

Step 1: Search for the Library

步骤1:搜索库

To find the Context7 library ID, query the search endpoint:
bash
curl -s "https://context7.com/api/v2/libs/search?libraryName=LIBRARY_NAME&query=TOPIC" | jq '.results[0]'
Parameters:
  • libraryName
    (required): The library name to search for (e.g., "react", "nextjs", "fastapi", "axios")
  • query
    (required): A description of the topic for relevance ranking
Response fields:
  • id
    : Library identifier for the context endpoint (e.g.,
    /websites/react_dev_reference
    )
  • title
    : Human-readable library name
  • description
    : Brief description of the library
  • totalSnippets
    : Number of documentation snippets available
要查找Context7库ID,请查询搜索端点:
bash
curl -s "https://context7.com/api/v2/libs/search?libraryName=LIBRARY_NAME&query=TOPIC" | jq '.results[0]'
参数:
  • libraryName
    (必填):要搜索的库名称(例如:"react"、"nextjs"、"fastapi"、"axios")
  • query
    (必填):主题描述,用于相关性排序
响应字段:
  • id
    :用于上下文端点的库标识符(例如:
    /websites/react_dev_reference
  • title
    :易读的库名称
  • description
    :库的简要描述
  • totalSnippets
    :可用的文档片段数量

Step 2: Fetch Documentation

步骤2:获取文档

To retrieve documentation, use the library ID from step 1:
bash
curl -s "https://context7.com/api/v2/context?libraryId=LIBRARY_ID&query=TOPIC&type=txt"
Parameters:
  • libraryId
    (required): The library ID from search results
  • query
    (required): The specific topic to retrieve documentation for
  • type
    (optional): Response format -
    json
    (default) or
    txt
    (plain text, more readable)
要检索文档,请使用步骤1中的库ID:
bash
curl -s "https://context7.com/api/v2/context?libraryId=LIBRARY_ID&query=TOPIC&type=txt"
参数:
  • libraryId
    (必填):搜索结果中的库ID
  • query
    (必填):要检索文档的特定主题
  • type
    (可选):响应格式 -
    json
    (默认)或
    txt
    (纯文本,更易读)

Examples

示例

React hooks documentation

React hooks 文档

bash
undefined
bash
undefined

Find React library ID

查找React库ID

Returns: "/websites/react_dev_reference"

返回: "/websites/react_dev_reference"

Fetch useState documentation

获取useState文档

Next.js routing documentation

Next.js 路由文档

bash
undefined
bash
undefined

Find Next.js library ID

查找Next.js库ID

Fetch app router documentation

获取App Router文档

FastAPI dependency injection

FastAPI 依赖注入

bash
undefined
bash
undefined

Find FastAPI library ID

查找FastAPI库ID

Fetch dependency injection documentation

获取依赖注入文档

Tips

提示

  • Use
    type=txt
    for more readable output
  • Use
    jq
    to filter and format JSON responses
  • Be specific with the
    query
    parameter to improve relevance ranking
  • If the first search result is not correct, check additional results in the array
  • URL-encode query parameters containing spaces (use
    +
    or
    %20
    )
  • No API key is required for basic usage (rate-limited)
  • 使用
    type=txt
    以获得更易读的输出
  • 使用
    jq
    过滤和格式化JSON响应
  • query
    参数要具体,以提高相关性排序
  • 如果第一个搜索结果不正确,请检查数组中的其他结果
  • 对包含空格的查询参数进行URL编码(使用
    +
    %20
  • 基础使用无需API密钥(有速率限制)