Communitygithub.com

文档查询 (Context7)

使用 Context7 MCP 获取最新的库和框架文档,而非训练数据。适用于设置问题、API 参考、代码示例,或当用户提到特定框架(如 React、Next.js、Prisma)时。

文档查询 (Context7) 是什么?

该技能通过 Context7 MCP 服务器提供的 `resolve-library-id` 和 `query-docs` 两个工具,使 AI 代理能够实时获取库、框架和 API 的最新文档,而无需依赖可能过时的训练数据。它适用于需要准确、最新行为信息的场景,例如设置配置、编写依赖库的代码、查找 API 参考等。支持平台包括 Claude Code、Cursor、Codex 等已配置 Context7 MCP 的 AI 编码助手。工作流程分为三步:首先使用 `resolve-library-id` 根据库名称和用户问题解析出 Context7 兼容的库 ID,然后从返回结果中根据名称匹配、基准分数、来源声誉和版本信息选择最佳 ID,最后用 `query-docs` 获取特定问题的文档片段和代码示例。建议在单次对话中最多调用 3 次,并注意在发送查询前移除敏感信息。

兼容平台✓Claude Code✓Codex CLI✓Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/documentation-lookup

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

文档查询 (Context7) 是做什么的?

当用户询问有关库、框架或 API 的问题时,通过 Context7 MCP(工具 resolve-library-id 和 query-docs)获取最新文档,而不是依赖训练数据。

核心概念

  • Context7:一个提供实时文档的 MCP 服务器;对于库和 API 相关问题,应优先使用它而非训练数据。
  • resolve-library-id:根据库名称和查询返回 Context7 兼容的库 ID(例如 /vercel/next.js)。
  • query-docs:根据给定的库 ID 和问题获取文档和代码片段。务必先调用 resolve-library-id 获取有效的库 ID。

何时使用

当用户出现以下情况时激活该技能:

  • 提出设置或配置问题(例如“如何配置 Next.js 中间件?”)
  • 请求依赖于某个库的代码(“写一个 Prisma 查询实现……”)
  • 需要 API 或参考信息(“Supabase 有哪些身份验证方法?”)
  • 提到特定的框架或库(React、Vue、Svelte、Express、Tailwind、Prisma、Supabase 等)

只要请求依赖于库、框架或 API 的准确、最新行为,就应使用该技能。适用于已配置 Context7 MCP 的各类 AI 编码助手(例如 Claude Code、Cursor、Codex)。

工作原理

步骤 1:解析库 ID

调用 resolve-library-id MCP 工具,并传入:

  • libraryName:从用户问题中提取的库或产品名称(例如 Next.js、Prisma、Supabase)。
  • query:用户的完整问题。这有助于提高结果的相关性排名。

在查询文档之前,必须先获得一个 Context7 兼容的库 ID(格式为 /org/project 或 /org/project/version)。没有有效的库 ID,不要调用 query-docs。

步骤 2:选择最佳匹配

从解析结果中选择一个结果,依据:

  • 名称匹配:优先选择与用户请求完全匹配或最接近的名称。
  • 基准分数:分数越高表示文档质量越好(100 为最高)。
  • 来源声誉:优先选择声誉高或中的来源。
  • 版本:如果用户指定了版本(例如“React 19”、“Next.js 15”),若列表中存在对应版本的库 ID(例如 /org/project/v1.2.0),则优先选择。

步骤 3:获取文档

调用 query-docs MCP 工具,并传入:

  • libraryId:从步骤 2 中选择的 Context7 库 ID(例如 /vercel/next.js)。
  • query:用户的具体问题或任务。请保持具体,以获得相关片段。

限制:每个问题对 query-docs(或 resolve-library-id)的调用次数不得超过 3 次。如果 3 次调用后答案仍不明确,请说明不确定性,并使用已有的最佳信息,而不是猜测。

步骤 4:使用文档

  • 使用获取到的最新信息回答用户的问题。
  • 在有益时包含文档中的相关代码示例。
  • 在必要时注明库或版本(例如“在 Next.js 15 中……”)。

示例

示例:Next.js 中间件

  1. 调用 resolve-library-id,传入 libraryName: "Next.js",query: "如何设置 Next.js 中间件?"。
  2. 从结果中根据名称和基准分数选择最佳匹配(例如 /vercel/next.js)。
  3. 调用 query-docs,传入 libraryId: "/vercel/next.js",query: "如何设置 Next.js 中间件?"。
  4. 使用返回的片段和文本回答;如有必要,从文档中包含一个最小的 middleware.ts 示例。

示例:Prisma 查询

  1. 调用 resolve-library-id,传入 libraryName: "Prisma",query: "如何查询关联关系?"。
  2. 选择官方的 Prisma 库 ID(例如 /prisma/prisma)。
  3. 使用该 libraryId 和查询调用 query-docs。
  4. 返回 Prisma Client 模式(例如 include 或 select)以及来自文档的简短代码片段。

示例:Supabase 身份验证方法

  1. 调用 resolve-library-id,传入 libraryName: "Supabase",query: "有哪些身份验证方法?"。
  2. 选择 Supabase 文档库 ID。
  3. 调用 query-docs;总结身份验证方法,并从获取的文档中展示最小示例。

最佳实践

  • 具体化:尽可能使用用户的完整问题作为查询,以获得更好的相关性。
  • 版本感知:当用户提到版本时,如果解析步骤中提供,优先使用版本特定的库 ID。
  • 偏好官方来源:当有多个匹配时,优先选择官方或主要包,而非社区分支。
  • 不包含敏感数据:在发送给 Context7 的任何查询中,移除 API 密钥、密码、令牌和其他秘密。在将用户问题传递给 resolve-library-id 或 query-docs 之前,应将其视为可能包含敏感信息。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相关技能