context7
当用户提到 GitHub URL、GitHub 仓库链接、开源库、或询问特定框架/库的使用方法时,自动使用 context7 MCP 获取最新的文档和代码示例。处理 github.com 链接、npm 包、开源项目参考时触发。
When & Why to Use This Skill
The context7 skill is a specialized MCP (Model Context Protocol) integration that empowers Claude to fetch real-time documentation, API references, and code examples directly from public GitHub repositories and npm packages. It effectively bridges the gap between the AI's training cutoff and the latest software releases, ensuring developers receive accurate, up-to-date technical guidance and reducing the risk of using deprecated APIs.
Use Cases
- Real-time API Reference: Automatically pull the latest documentation for rapidly evolving frameworks like Next.js, LangChain, or Tailwind CSS to ensure code accuracy.
- Open-Source Code Analysis: Deep dive into specific GitHub repositories to understand internal implementation details, design patterns, and project structures.
- Version-Specific Troubleshooting: Retrieve precise code snippets and documentation for specific npm package versions to avoid compatibility issues and deprecated methods.
- Technical Research and Onboarding: Quickly master new libraries by accessing official 'getting started' guides and example projects directly within the chat context.
- Documentation Verification: Confirm the existence and usage of specific functions or hooks in open-source projects when the AI's internal knowledge is uncertain.
| name | context7 |
|---|---|
| description | 当用户提到 GitHub URL、GitHub 仓库链接、开源库、或询问特定框架/库的使用方法时,自动使用 context7 MCP 获取最新的文档和代码示例。处理 github.com 链接、npm 包、开源项目参考时触发。 |
触发场景
用户消息满足以下任一条件时触发:
包含 GitHub URL
- 消息中包含
github.com链接 - 示例:
https://github.com/user/repo
- 消息中包含
提到公开库/开源仓库
- 关键词:「公开库」「开源仓库」「GitHub 仓库」「开源项目」「GitHub 项目」
- 示例:「我想了解这个开源项目的实现」
AI 判断需要参考 GitHub 代码
- 当前任务涉及理解或使用某个库的最新版本
- 需要查看某个库的具体实现
- 需要了解某个框架的最新 API
不触发的场景
- 仅是普通讨论 GitHub 概念,不涉及具体代码
- 用户明确表示不需要查看源码
- 任务已经很明确,不需要额外的文档参考
执行流程
阶段 1: 自动检测 GitHub 需求
步骤 1.1: 识别触发条件
检查用户消息是否满足以下任一条件:
- 包含
github.comURL (如: https://github.com/user/repo) - 提到特定框架/库名称需要查看文档 (如: "Next.js 14 文档", "React hooks API")
- 询问开源项目实现方式
- 需要最新版本的 API 参考
步骤 1.2: 评估 context7 必要性
✅ 需要 context7:
- 涉及具体代码库的实现细节
- 需要特定版本的 API 文档
- 学习新框架或库
- 查看官方示例项目
❌ 不需要 context7:
- 通用编程概念讨论
- 已有足够上下文信息
- 简单问题不需要查源码
- 私有仓库 (context7 仅支持公开库)
阶段 2: 自动调用 context7 MCP
步骤 2.1: 透明告知用户
在调用 context7 前,简要告知用户:
💡 正在使用 context7 获取 [仓库名/框架名] 的最新文档...
步骤 2.2: 调用 context7 MCP
直接使用 context7 MCP 工具获取文档内容。无需等待用户明确许可。
步骤 2.3: 基于最新文档回答
使用 context7 返回的文档内容:
- 提供准确的 API 用法
- 引用最新的代码示例
- 说明版本特定的特性
阶段 3: 后续处理
步骤 3.1: 如果 context7 失败
如果 context7 调用失败 (如仓库不存在、网络问题):
- 告知用户 context7 不可用
- 基于现有知识回答
- 建议用户手动查看仓库
步骤 3.2: 引用来源
回答时明确说明信息来源:
根据 context7 获取的 [仓库名] 最新文档...
context7 功能说明
核心功能
context7 是一个 MCP (Model Context Protocol) 服务器,用于解决 LLM 依赖过时或通用库信息的问题。
它能做什么:
- 拉取 GitHub 仓库的最新文档
- 获取特定版本的代码示例
- 提供准确的 API 参考
- 避免生成不存在或已废弃的 API
使用场景
✅ 适合使用 context7 的场景:
- 学习新框架或库的使用方法
- 查看某个开源项目的具体实现
- 需要最新版本的 API 文档
- 想了解某个库的设计模式
- 需要准确的代码示例而非通用建议
❌ 不适合使用 context7 的场景:
- 讨论编程概念,不涉及具体库
- 已经很熟悉的库,不需要查文档
- 私有仓库(context7 仅支持公开库)
- 简单的代码问题,不需要参考源码
配置检查
如果用户决定使用 context7,在提示之前先检查配置:
检查 MCP 是否已配置
.mcp.json或.cursor/mcp.json中是否有 context7 配置- 如果没有,建议用户运行
/sync:mcp命令
配置文件示例
{ "mcpServers": { "context7": { "command": "npx", "args": ["-y", "@upstash/context7-mcp"], "env": {} } } }
提示风格
语气和态度
- 友好提示,不强制:让用户知道有这个选项,但不强迫使用
- 简明扼要:一两句话说明作用,不要长篇大论
- 提供示例:给出具体的使用示例,降低理解成本
示例提示语
简短版:
💡 提示:您可以在 prompt 中添加 "use context7" 来获取该仓库的最新文档和代码示例,避免过时信息。
详细版:
💡 检测到您需要参考 GitHub 仓库。context7 可以帮您拉取最新的文档和代码示例。
使用方法:在下一条消息中添加 "use context7",例如:
"use context7 来分析 https://github.com/user/repo 的实现"
是否需要使用?
相关文档
注意事项
不要过度触发
- 只在真正需要时提示
- 避免打断用户的正常工作流
尊重用户选择
- 如果用户明确拒绝,不要重复提示
- 记住用户的偏好(如果可能)
配置检查
- 提示使用前,确保 MCP 已配置
- 如果未配置,引导用户运行
/sync:mcp
隐私保护
- context7 仅支持公开仓库
- 不要尝试访问私有仓库