Files
scopone/.github/skills/context7-lookup/SKILL.md
2026-04-10 22:35:01 +02:00

150 lines
4.9 KiB
Markdown

---
name: context7-lookup
description: Retrieve up-to-date, version-specific documentation for libraries and frameworks using Context7 MCP server. Eliminates hallucinated APIs and outdated code examples.
---
# Context7 Documentation Lookup
Fetches current documentation for 68,000+ libraries to prevent hallucinated APIs and outdated code examples.
## When to Use
Auto-invoke when encountering:
- Import/require/use statements for external packages (any language)
- Error messages mentioning library names
- User specifies library: "use {library}", "implement with {framework}"
- Planning with third-party dependencies
- Dependency files present (package.json, requirements.txt, Cargo.toml, pom.xml, Gemfile, go.mod, composer.json, *.csproj, etc.)
## Protocol
**Step 1: Detect Version** (if library known)
```bash
grep_search(query="{library}", includePattern="**/package.json") # Node.js
grep_search(query="{library}", includePattern="**/requirements.txt") # Python
grep_search(query="{library}", includePattern="**/Cargo.toml") # Rust
grep_search(query="{library}", includePattern="**/pom.xml") # Java
grep_search(query="{library}", includePattern="**/Gemfile") # Ruby
grep_search(query="{library}", includePattern="**/go.mod") # Go
grep_search(query="{library}", includePattern="**/composer.json") # PHP
```
**Step 2: Resolve Library ID**
```
mcp_context7_resolve-library-id(
libraryName: "{library}",
query: "{specific_use_case}"
)
→ Returns: /owner/repo or /domain
```
**Step 3: Fetch Documentation**
```
mcp_context7_query-docs(
libraryId: "{resolved_id}",
query: "{library} {version} {specific_api_or_pattern}"
)
→ Returns: Documentation snippets with code examples
```
**Step 4: Apply & Cache**
- Use verified API signatures in implementation
- Update FINDINGS.md with: library, version, Context7 ID, date, key patterns
## Version Detection
| Ecosystem | Files | Extract From |
|-----------|-------|--------------|
| Node.js | package.json, *lock.yaml | `dependencies` / `devDependencies` |
| Python | requirements.txt, Pipfile, pyproject.toml | Version specifiers (==, >=, ~=) |
| Java | pom.xml, build.gradle* | `<version>` / version strings |
| Rust | Cargo.toml | `[dependencies]` |
| Ruby | Gemfile* | Gem versions |
| Go | go.mod | Module versions |
| PHP | composer.json | `require` |
| C#/.NET | *.csproj, packages.config | PackageReference |
| Swift | Package.swift, Podfile | Dependencies |
## Library Extraction from Imports
| Language | Import | Extract |
|----------|--------|---------|
| JS/TS | `import X from 'lodash'` | `lodash` |
| Python | `import django.core` | `django` |
| Java | `import org.springframework.*` | `spring` or `spring-boot` |
| Rust | `use tokio::runtime` | `tokio` |
| Go | `import "github.com/gin-gonic/gin"` | `gin` |
| Ruby | `require 'rails'` | `rails` |
| PHP | `use Symfony\Component` | `symfony` |
| C# | `using Microsoft.AspNetCore` | `AspNetCore` |
**Query Strategy:**
1. User-specified version → use as-is
2. Detected from files → include in query
3. No version found → use latest
4. Always format: "{library} {version} {specific_feature}"
## Best Practices
**✅ Specific queries:**
- "Django 5.0 class-based views authentication"
- "Tokio 1.35 async runtime spawning tasks"
- "Spring Boot 3.2 @RestController validation"
**❌ Vague queries:**
- "authentication"
- "async programming"
**Skip resolve if ID known:**
```
query-docs("/django/django", "Django 5.0 ORM filtering") # Direct
```
**Common ID patterns:**
- GitHub: `/{owner}/{repo}` (e.g., `/vercel/next.js`)
- Docs: `/{domain}` (e.g., `/tailwindcss.com/docs`)
## Error Handling
| Error | Action |
|-------|--------|
| 404 Not Found | Try alternative names, ask user |
| 429 Rate Limited | Wait 60s, retry (set CONTEXT7_API_KEY for higher limits) |
| Multiple matches | Present top 3, ask clarification |
| Empty results | Broader query or fallback to web search |
## Example (Multi-Language)
```python
# Python: Django REST API
Task: "Add REST views with Django"
1. grep_search("django", "requirements.txt") "django==5.0.2"
2. resolve-library-id("django", "REST API views") /django/django
3. query-docs("/django/django", "Django 5.0 class-based views REST") docs
4. Implement with verified APIs
```
```rust
// Rust: Tokio Async
Task: "Async HTTP with Tokio"
1. grep_search("tokio", "Cargo.toml") 'tokio = "1.35"'
2. query-docs("/tokio-rs/tokio", "tokio 1.35 async HTTP runtime") docs
3. Use: Runtime::new() NOT: Runtime::init()
```
```java
// Java: Spring Boot
Reviewer detecting Spring Boot 3.2 from pom.xml
1. query-docs("/spring-projects/spring-boot", "Spring Boot 3.2 @RequestMapping")
2. Flag: Use @GetMapping instead of @RequestMapping in v3.2
```
## MCP Tools
**resolve-library-id** → Search library by name, returns ID
**query-docs** → Fetch docs by ID, returns snippets
---
Use liberally to prevent hallucinated APIs. Cache results in FINDINGS.md.