context7

Claude Code skill for up-to-date library documentation via Context7 API

adoval4
開発者 adoval4
AI・機械学習 · 更新日: 8 months ago
0
スター
0
Forks
コミュニティ
BB
安全性:
普通
BBB
品質:

name: context7 description: Get up-to-date library documentation from Context7

Context7 Documentation Skill

Retrieve current, version-specific documentation for libraries and frameworks using the Context7 API.

Prerequisites

The following environment variables are automatically provided by the agent sandbox:

Get a free API key at: https://context7.com/dashboard

When to Use This Skill

Use whenever you need library or framework documentation:

Priority: Use Context7 BEFORE web search for library documentation to ensure version-specific accuracy.

API Endpoints

1. Search Library

Search for available libraries by name. Use this to find the correct library ID before fetching documentation.

Endpoint: GET https://context7.com/api/v2/libs/search

Query Parameters:

Example:

# Search for React library
curl "https://context7.com/api/v2/libs/search?libraryName=react&query=hooks" \
  -H "Authorization: Bearer ${CONTEXT7_API_KEY}"

# Unauthenticated (lower rate limits)
curl "https://context7.com/api/v2/libs/search?libraryName=react&query=hooks"

Response:

{
  "results": [
    {
      "id": "/facebook/react",
      "title": "React",
      "description": "A JavaScript library for building user interfaces",
      "totalSnippets": 1250,
      "trustScore": 95,
      "benchmarkScore": 88,
      "versions": ["v18.2.0", "v17.0.2"]
    }
  ]
}

IMPORTANT: The response is an object with a results array, NOT a plain array. Always access .results first (e.g., data["results"][0] in Python, .results[0] in jq).

Tips:

2. Get Context

Retrieve documentation context for a specific library. Returns relevant documentation snippets based on your query.

Endpoint: GET https://context7.com/api/v2/context

Query Parameters:

Example:

# Get React useEffect documentation (JSON format)
curl "https://context7.com/api/v2/context?libraryId=/facebook/react&query=useEffect" \
  -H "Authorization: Bearer ${CONTEXT7_API_KEY}"

# Get documentation in text format (better for LLM prompts)
curl "https://context7.com/api/v2/context?libraryId=/facebook/react&query=useEffect&type=txt" \
  -H "Authorization: Bearer ${CONTEXT7_API_KEY}"

# Unauthenticated (lower rate limits)
curl "https://context7.com/api/v2/context?libraryId=/facebook/react&query=useEffect&type=txt"

Response (JSON format):

[
  {
    "title": "Using the Effect Hook",
    "content": "The Effect Hook lets you perform side effects...",
    "source": "react.dev/reference/react/useEffect"
  }
]

Response (Text format): Returns plain text ready for LLM prompts.

Tips:

Complete Workflow Example

# Step 1: Search for the library
LIBRARY_SEARCH=$(curl -s "https://context7.com/api/v2/libs/search?libraryName=react&query=state%20management" \
  -H "Authorization: Bearer ${CONTEXT7_API_KEY}")

# Extract library ID (first result - response has a "results" array wrapper)
LIBRARY_ID=$(echo "$LIBRARY_SEARCH" | jq -r '.results[0].id')
echo "Found library: $LIBRARY_ID"

# Step 2: Get documentation context
DOCS=$(curl -s "https://context7.com/api/v2/context?libraryId=$LIBRARY_ID&query=How%20do%20I%20use%20useState&type=txt" \
  -H "Authorization: Bearer ${CONTEXT7_API_KEY}")

echo "$DOCS"

Error Handling

The Context7 API uses standard HTTP status codes:

Code Description Action
200 Success Process the response normally
202 Accepted - Library not finalized Wait and retry later
400 Bad Request - Invalid parameters Check query parameters
401 Unauthorized - Invalid API key Check CONTEXT7_API_KEY format
404 Not Found - Library doesn't exist Verify the library ID
429 Too Many Requests - Rate limit exceeded Wait and retry with backoff
500 Internal Server Error Retry with backoff

Rate Limits:

Best Practices

  1. Be specific with queries: "How to implement authentication with middleware" is better than "auth"
  2. Use text format: Add &type=txt for cleaner output that's easier to parse
  3. Pin versions: Use /library-name/vX.Y.Z for consistent results
  4. Fallback to web search: If Context7 doesn't have the library or info is incomplete
  5. Handle rate limits: Implement retry logic for 429 errors

Examples

Planning Agent

# Research Django REST Framework authentication
LIBRARY_ID=$(curl -s "https://context7.com/api/v2/libs/search?libraryName=django-rest-framework&query=authentication" \
  -H "Authorization: Bearer ${CONTEXT7_API_KEY}" | jq -r '.results[0].id')

curl -s "https://context7.com/api/v2/context?libraryId=$LIBRARY_ID&query=token%20authentication&type=txt" \
  -H "Authorization: Bearer ${CONTEXT7_API_KEY}"

Implementation Agent

# Verify Next.js 15 App Router API
curl -s "https://context7.com/api/v2/context?libraryId=/vercel/next.js/v15.1.8&query=app%20router%20layout&type=txt" \
  -H "Authorization: Bearer ${CONTEXT7_API_KEY}"

Team Query Agent

# Answer "How do I use React hooks?"
LIBRARY_ID="/facebook/react"
curl -s "https://context7.com/api/v2/context?libraryId=$LIBRARY_ID&query=hooks%20usage&type=txt" \
  -H "Authorization: Bearer ${CONTEXT7_API_KEY}"

Resources

🔓 サインインしてさらに解放
GitHub でサインイン