joaomj

context7

0
0
# Install this skill:
npx skills add joaomj/skills --skill "context7"

Install specific skill from multi-skill repository

# Description

The `context7` skill provides a mechanism for retrieving real-time documentation for software libraries, frameworks, and APIs. By querying the Context7 API, agents can provide up-to-date code examples and configuration steps, bypassing the limitations of static training data.

# SKILL.md


name: context7
description: The context7 skill provides a mechanism for retrieving real-time documentation for software libraries, frameworks, and APIs. By querying the Context7 API, agents can provide up-to-date code examples and configuration steps, bypassing the limitations of static training data.


Use Case Triggers

Activate this skill when the user interaction involves:

  • Setup and Configuration: Questions regarding environment initialization or middleware (e.g., "How do I configure Next.js middleware?").
  • Code Generation: Requests for specific implementation logic (e.g., "Write a Prisma query for nested relations").
  • API Reference: Inquiries about specific methods or properties (e.g., "What are the Supabase auth methods?").
  • Framework Specifics: Any query mentioning modern ecosystems like React, Vue, Svelte, Express, or Tailwind.

Workflow and API Usage

The retrieval process consists of two primary phases: identifying the correct library and fetching the specific documentation context.

1. Library Resolution

To find the correct libraryId, query the search endpoint. This step ensures that the agent targets the official or most relevant documentation repository.

Tool Call / Command:

curl -s "https://context7.com/api/v2/libs/search?libraryName=LIBRARY_NAME&query=TOPIC" | jq '.results[0]'

Selection Criteria:

  • libraryName: The core name of the library (e.g., "react", "fastapi").
  • query: The user's full question to improve relevance ranking.
  • Selection Logic: Prioritize exact name matches, higher benchmark scores, and version-specific IDs (e.g., preferring React 19 if specified).

Key Response Fields:

Field Description
id The unique identifier required for context fetching (e.g., /vercel/next.js).
title Human-readable library name.
totalSnippets The volume of documentation available for that entry.

2. Context Retrieval

Once the libraryId is secured, fetch the relevant documentation snippets using the specific user query.

Tool Call / Command:

curl -s "https://context7.com/api/v2/context?libraryId=LIBRARY_ID&query=TOPIC&type=txt"

Parameters:

  • libraryId: The identifier obtained from Step 1.
  • query: The specific technical topic (e.g., "useState", "app router").
  • type: Use txt for plain text readability or json for structured data.

Implementation Examples

React Hooks

# Search for ID
curl -s "https://context7.com/api/v2/libs/search?libraryName=react&query=hooks" | jq '.results[0].id'
# Returns: "/websites/react_dev_reference"

# Fetch Documentation
curl -s "https://context7.com/api/v2/context?libraryId=/websites/react_dev_reference&query=useState&type=txt"

Next.js Routing

# Search for ID
curl -s "https://context7.com/api/v2/libs/search?libraryName=nextjs&query=routing" | jq '.results[0].id'
# Returns: "/vercel/next.js"

# Fetch Documentation
curl -s "https://context7.com/api/v2/context?libraryId=/vercel/next.js&query=app+router&type=txt"

Best Practices and Guidelines

  • Precision: Always pass the user's full question as the query parameter to the API to improve the relevance of the vector search results.
  • Version Control: If a user mentions a version (e.g., "Next.js 15"), select the matching version-specific library ID during the resolution phase.
  • Authority: Prefer official or primary packages over community-maintained forks unless specified otherwise.
  • Readability: Use type=txt when the primary goal is to feed the documentation directly into a text-based response.
  • Encoding: Ensure query parameters containing spaces are URL-encoded (e.g., use + or %20).

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.