$npx -y skills add mjunaidca/mjs-agent-skills --skill fetching-library-docsToken-efficient library API documentation fetcher using Context7 MCP with 77% token savings. Fetches code examples, API references, and usage patterns for published libraries (React, Next.js, Prisma, etc). Use when users ask "how do I use X library", need code examples, want API
| 1 | # Context7 Efficient Documentation Fetcher |
| 2 | |
| 3 | Fetch library documentation with automatic 77% token reduction via shell pipeline. |
| 4 | |
| 5 | ## Quick Start |
| 6 | |
| 7 | **Always use the token-efficient shell pipeline:** |
| 8 | |
| 9 | ```bash |
| 10 | # Automatic library resolution + filtering |
| 11 | bash scripts/fetch-docs.sh --library <library-name> --topic <topic> |
| 12 | |
| 13 | # Examples: |
| 14 | bash scripts/fetch-docs.sh --library react --topic useState |
| 15 | bash scripts/fetch-docs.sh --library nextjs --topic routing |
| 16 | bash scripts/fetch-docs.sh --library prisma --topic queries |
| 17 | ``` |
| 18 | |
| 19 | **Result:** Returns ~205 tokens instead of ~934 tokens (77% savings). |
| 20 | |
| 21 | ## Standard Workflow |
| 22 | |
| 23 | For any documentation request, follow this workflow: |
| 24 | |
| 25 | ### 1. Identify Library and Topic |
| 26 | |
| 27 | Extract from user query: |
| 28 | - **Library:** React, Next.js, Prisma, Express, etc. |
| 29 | - **Topic:** Specific feature (hooks, routing, queries, etc.) |
| 30 | |
| 31 | ### 2. Fetch with Shell Pipeline |
| 32 | |
| 33 | ```bash |
| 34 | bash scripts/fetch-docs.sh --library <library> --topic <topic> --verbose |
| 35 | ``` |
| 36 | |
| 37 | The `--verbose` flag shows token savings statistics. |
| 38 | |
| 39 | ### 3. Use Filtered Output |
| 40 | |
| 41 | The script automatically: |
| 42 | - Fetches full documentation (934 tokens, stays in subprocess) |
| 43 | - Filters to code examples + API signatures + key notes |
| 44 | - Returns only essential content (205 tokens to Claude) |
| 45 | |
| 46 | ## Parameters |
| 47 | |
| 48 | ### Basic Usage |
| 49 | |
| 50 | ```bash |
| 51 | bash scripts/fetch-docs.sh [OPTIONS] |
| 52 | ``` |
| 53 | |
| 54 | **Required (pick one):** |
| 55 | - `--library <name>` - Library name (e.g., "react", "nextjs") |
| 56 | - `--library-id <id>` - Direct Context7 ID (faster, skips resolution) |
| 57 | |
| 58 | **Optional:** |
| 59 | - `--topic <topic>` - Specific feature to focus on |
| 60 | - `--mode <code|info>` - code for examples (default), info for concepts |
| 61 | - `--page <1-10>` - Pagination for more results |
| 62 | - `--verbose` - Show token savings statistics |
| 63 | |
| 64 | ### Mode Selection |
| 65 | |
| 66 | **Code Mode (default):** Returns code examples + API signatures |
| 67 | ```bash |
| 68 | --mode code |
| 69 | ``` |
| 70 | |
| 71 | **Info Mode:** Returns conceptual explanations + fewer examples |
| 72 | ```bash |
| 73 | --mode info |
| 74 | ``` |
| 75 | |
| 76 | ## Common Library IDs |
| 77 | |
| 78 | Use `--library-id` for faster lookup (skips resolution): |
| 79 | |
| 80 | ```bash |
| 81 | React: /reactjs/react.dev |
| 82 | Next.js: /vercel/next.js |
| 83 | Express: /expressjs/express |
| 84 | Prisma: /prisma/docs |
| 85 | MongoDB: /mongodb/docs |
| 86 | Fastify: /fastify/fastify |
| 87 | NestJS: /nestjs/docs |
| 88 | Vue.js: /vuejs/docs |
| 89 | Svelte: /sveltejs/site |
| 90 | ``` |
| 91 | |
| 92 | ## Workflow Patterns |
| 93 | |
| 94 | ### Pattern 1: Quick Code Examples |
| 95 | |
| 96 | User asks: "Show me React useState examples" |
| 97 | |
| 98 | ```bash |
| 99 | bash scripts/fetch-docs.sh --library react --topic useState --verbose |
| 100 | ``` |
| 101 | |
| 102 | Returns: 5 code examples + API signatures + notes (~205 tokens) |
| 103 | |
| 104 | ### Pattern 2: Learning New Library |
| 105 | |
| 106 | User asks: "How do I get started with Prisma?" |
| 107 | |
| 108 | ```bash |
| 109 | # Step 1: Get overview |
| 110 | bash scripts/fetch-docs.sh --library prisma --topic "getting started" --mode info |
| 111 | |
| 112 | # Step 2: Get code examples |
| 113 | bash scripts/fetch-docs.sh --library prisma --topic queries --mode code |
| 114 | ``` |
| 115 | |
| 116 | ### Pattern 3: Specific Feature Lookup |
| 117 | |
| 118 | User asks: "How does Next.js routing work?" |
| 119 | |
| 120 | ```bash |
| 121 | bash scripts/fetch-docs.sh --library-id /vercel/next.js --topic routing |
| 122 | ``` |
| 123 | |
| 124 | Using `--library-id` is faster when you know the exact ID. |
| 125 | |
| 126 | ### Pattern 4: Deep Exploration |
| 127 | |
| 128 | User needs comprehensive information: |
| 129 | |
| 130 | ```bash |
| 131 | # Page 1: Basic examples |
| 132 | bash scripts/fetch-docs.sh --library react --topic hooks --page 1 |
| 133 | |
| 134 | # Page 2: Advanced patterns |
| 135 | bash scripts/fetch-docs.sh --library react --topic hooks --page 2 |
| 136 | ``` |
| 137 | |
| 138 | ## Token Efficiency |
| 139 | |
| 140 | **How it works:** |
| 141 | |
| 142 | 1. `fetch-docs.sh` calls `fetch-raw.sh` (which uses `mcp-client.py`) |
| 143 | 2. Full response (934 tokens) stays in subprocess memory |
| 144 | 3. Shell filters (awk/grep/sed) extract essentials (0 LLM tokens used) |
| 145 | 4. Returns filtered output (205 tokens) to Claude |
| 146 | |
| 147 | **Savings:** |
| 148 | - Direct MCP: 934 tokens per query |
| 149 | - This approach: 205 tokens per query |
| 150 | - **77% reduction** |
| 151 | |
| 152 | **Do NOT use `mcp-client.py` directly** - it bypasses filtering and wastes tokens. |
| 153 | |
| 154 | ## Advanced: Library Resolution |
| 155 | |
| 156 | If library name fails, try variations: |
| 157 | |
| 158 | ```bash |
| 159 | # Try different formats |
| 160 | --library "next.js" # with dot |
| 161 | --library "nextjs" # without dot |
| 162 | --library "next" # short form |
| 163 | |
| 164 | # Or search manually |
| 165 | bash scripts/fetch-docs.sh --library "your-library" --verbose |
| 166 | # Check output for suggested library IDs |
| 167 | ``` |
| 168 | |
| 169 | ## Verification |
| 170 | |
| 171 | Run: `python3 scripts/verify.py` |
| 172 | |
| 173 | Expected: `✓ fetch-docs.sh ready` |
| 174 | |
| 175 | ## If Verification Fails |
| 176 | |
| 177 | 1. Run diagnostic: `ls -la scripts/fetch-docs.sh` |
| 178 | 2. Check: Script exists and is executable |
| 179 | 3. Fix: `chmod +x scripts/fetch-docs.sh` |
| 180 | 4. **Stop and report** if still failing - do not proceed wi |