Skip to content

Commit 31b4fb8

Browse files
feat(cli): add docs skill and align CLI output with MCP format (#2176)
* feat(docs): add dedicated docs skill and restructure CLI documentation - Add new `docs` skill as a single-file skill for documentation retrieval - Align skill prompts with MCP tool descriptions (selection process, query guidance, 3-call limit) - Enrich CLI docs page with result fields, query tips, and version-specific IDs - Move CLI page to Overview section in docs nav - Make `query` required for `ctx7 library` across all skills and docs - Update trust score display label in skills.mdx * feat(cli): align library output format with MCP labels Use labeled fields and categorical Source Reputation labels (High/Medium/Low/Unknown) instead of numeric trust scores to match the MCP transport format. * refactor: move skills from .agents/skills to skills/ at repo root Source-control location for skills — users install them into .agents/, .claude/, etc. via the CLI. Also updates install instructions to use `npm install -g ctx7@latest` or `npx ctx7@latest`. * docs: use natural-language query examples across skills and CLI docs Replace keyword-style queries ("useEffect cleanup") with full question-style queries ("How to clean up useEffect with async operations") to better demonstrate how the query parameter works. * docs: fix trust score description to show numeric range
1 parent 4ac6e3e commit 31b4fb8

File tree

11 files changed

+304
-129
lines changed

11 files changed

+304
-129
lines changed

.agents/skills/ctx7-cli/references/docs.md

Lines changed: 0 additions & 88 deletions
This file was deleted.

.changeset/align-cli-mcp-labels.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ctx7": patch
3+
---
4+
5+
Align CLI library output format with MCP: use labeled fields (Title, Context7-compatible library ID, Description, Code Snippets, Source Reputation, Benchmark Score, Versions) and categorical reputation labels (High/Medium/Low/Unknown) instead of numeric trust scores

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ dist
176176
!plugins/cursor/context7/.cursor
177177
.opencode
178178
.claude
179-
.agents/*
180-
!.agents/skills/
179+
.agents
181180

182181
# Finder (MacOS) folder config
183182
.DS_Store

docs/clients/cli.mdx

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,58 +40,63 @@ Requires Node.js 18 or later.
4040

4141
## Query Library Documentation
4242

43-
Fetching docs is a two-step process: first resolve the library name to get its Context7 ID, then use that ID to query documentation. The ID is stable and scoped to a specific library — it's what Context7 uses to know exactly which library and version to pull docs from.
43+
Fetching docs is a two-step process: first resolve the library name to get its Context7 ID, then use that ID to query documentation.
4444

4545
### Step 1 — ctx7 library
4646

47-
Searches the Context7 index by name and returns matching libraries. Pass an optional `query` to rank results by relevance to your specific task — this helps when a library name is ambiguous or has multiple versions indexed.
47+
Searches the Context7 index by name and returns matching libraries. Pass a `query` describing what you're trying to do — this ranks results by relevance and helps when a library name is ambiguous or shared across multiple packages.
4848

4949
```bash
50-
ctx7 library react
51-
ctx7 library nextjs "app router setup"
52-
ctx7 library prisma "database relations"
50+
ctx7 library react "How to clean up useEffect with async operations"
51+
ctx7 library nextjs "How to set up app router with middleware"
52+
ctx7 library prisma "How to define one-to-many relations with cascade delete"
5353
```
5454

55-
Each result shows:
55+
Each result includes:
5656

5757
| Field | Description |
5858
|-------|-------------|
59-
| **ID** | The library ID to pass to `ctx7 docs` (e.g., `/facebook/react`) |
60-
| **Snippets** | Number of indexed documentation snippets |
61-
| **Stars** | GitHub stars — a signal of library popularity |
62-
| **Trust score** | Documentation quality indicator (0–10) |
63-
| **Versions** | Indexed versions, if version-specific docs exist |
59+
| **Library ID** | The identifier to pass to `ctx7 docs` (format: `/org/project`) |
60+
| **Code Snippets** | Number of indexed code examples — higher means more documentation coverage |
61+
| **Source Reputation** | Authority indicator: High, Medium, Low, or Unknown |
62+
| **Benchmark Score** | Quality score from 0 to 100 |
63+
| **Versions** | Version-specific IDs when available (format: `/org/project/version`) |
6464

65-
Pick the top result's ID, or a version-specific one if the user mentioned a version (e.g., `/vercel/next.js@canary`).
65+
When multiple results come back, the best match is usually the one with the closest name, highest snippet count, and strongest reputation. If you need docs for a specific version, pick the matching version ID from the list.
6666

6767
```bash
68-
# Output as JSON — useful for scripting or piping into other tools
69-
ctx7 library react --json | jq '.[0].id'
68+
# Fetch docs for a specific version
69+
ctx7 docs /vercel/next.js/v14.3.0-canary.87 "How to set up app router"
70+
71+
# Output as JSON for scripting
72+
ctx7 library react "How to use hooks for state management" --json | jq '.[0].id'
7073
```
7174

7275
### Step 2 — ctx7 docs
7376

74-
Pass the library ID and a natural-language question to fetch relevant code snippets and explanations from the indexed documentation.
77+
Takes a library ID and a natural-language question, and returns relevant code snippets and explanations from the indexed documentation.
7578

7679
```bash
77-
ctx7 docs /facebook/react "useEffect cleanup"
78-
ctx7 docs /vercel/next.js "middleware authentication"
79-
ctx7 docs /prisma/prisma "one-to-many relations"
80+
ctx7 docs /facebook/react "How to clean up useEffect with async operations"
81+
ctx7 docs /vercel/next.js "How to add middleware that redirects unauthenticated users"
82+
ctx7 docs /prisma/prisma "How to define one-to-many relations with cascade delete"
8083
```
8184

8285
<Note>
8386
Library IDs always start with `/`. Running `ctx7 docs react "hooks"` will fail — always use the full ID returned by `ctx7 library` in Step 1.
8487
</Note>
8588

89+
Queries work best when they're specific. Describe what you're trying to accomplish rather than using single keywords — `"How to set up authentication with JWT in Express.js"` returns much better results than `"auth"`.
90+
8691
The output contains two types of content: **code snippets** (titled, with language-tagged blocks) and **info snippets** (prose explanations with breadcrumb context). Both are formatted for readability in the terminal.
8792

8893
```bash
8994
# Output as structured JSON
90-
ctx7 docs /facebook/react "hooks" --json
95+
ctx7 docs /facebook/react "How to use hooks for state management" --json
9196

9297
# Pipe to other tools — output is clean when not in a TTY (no spinners or colors)
93-
ctx7 docs /facebook/react "hooks" | head -50
94-
ctx7 docs /vercel/next.js "routing" | grep -A 10 "middleware"
98+
ctx7 docs /facebook/react "How to use hooks for state management" | head -50
99+
ctx7 docs /vercel/next.js "How to add middleware for route protection" | grep -A 10 "middleware"
95100
```
96101

97102
---

docs/docs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"overview",
2525
"installation",
2626
"plans-pricing",
27+
"clients/cli",
2728
"adding-libraries",
2829
"api-guide",
2930
"skills",
@@ -62,8 +63,7 @@
6263
"clients/claude-code",
6364
"clients/cursor",
6465
"clients/opencode",
65-
"resources/all-clients",
66-
"clients/cli"
66+
"resources/all-clients"
6767
]
6868
},
6969
{

packages/cli/src/commands/docs.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import type { LibrarySearchResult, ContextResponse } from "../types.js";
1010

1111
const isTTY = process.stdout.isTTY;
1212

13+
function getReputationLabel(score: number | undefined): "High" | "Medium" | "Low" | "Unknown" {
14+
if (score === undefined || score < 0) return "Unknown";
15+
if (score >= 7) return "High";
16+
if (score >= 4) return "Medium";
17+
return "Low";
18+
}
19+
1320
function getAccessToken(): string | undefined {
1421
const tokens = loadTokens();
1522
if (!tokens || isTokenExpired(tokens)) return undefined;
@@ -18,31 +25,24 @@ function getAccessToken(): string | undefined {
1825

1926
function formatLibraryResult(lib: LibrarySearchResult, index: number): string {
2027
const lines: string[] = [];
21-
lines.push(`${pc.dim(`${index + 1}.`)} ${pc.bold(lib.title)} ${pc.cyan(lib.id)}`);
28+
lines.push(`${pc.dim(`${index + 1}.`)} ${pc.bold(`Title: ${lib.title}`)}`);
29+
lines.push(` ${pc.cyan(`Context7-compatible library ID: ${lib.id}`)}`);
2230

2331
if (lib.description) {
24-
lines.push(` ${pc.dim(lib.description)}`);
32+
lines.push(` ${pc.dim(`Description: ${lib.description}`)}`);
2533
}
2634

27-
const meta: string[] = [];
2835
if (lib.totalSnippets) {
29-
meta.push(`${lib.totalSnippets} snippets`);
30-
}
31-
if (lib.stars && lib.stars > 0) {
32-
meta.push(`${lib.stars.toLocaleString()} stars`);
36+
lines.push(` ${pc.dim(`Code Snippets: ${lib.totalSnippets}`)}`);
3337
}
3438
if (lib.trustScore !== undefined) {
35-
meta.push(`trust: ${lib.trustScore}/10`);
39+
lines.push(` ${pc.dim(`Source Reputation: ${getReputationLabel(lib.trustScore)}`)}`);
3640
}
3741
if (lib.benchmarkScore !== undefined && lib.benchmarkScore > 0) {
38-
meta.push(`benchmark: ${lib.benchmarkScore}`);
42+
lines.push(` ${pc.dim(`Benchmark Score: ${lib.benchmarkScore}`)}`);
3943
}
40-
if (meta.length > 0) {
41-
lines.push(` ${pc.dim(meta.join(" · "))}`);
42-
}
43-
4444
if (lib.versions && lib.versions.length > 0) {
45-
lines.push(` ${pc.dim(`versions: ${lib.versions.join(", ")}`)}`);
45+
lines.push(` ${pc.dim(`Versions: ${lib.versions.join(", ")}`)}`);
4646
}
4747

4848
return lines.join("\n");
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ description: Use the ctx7 CLI to fetch library documentation, manage AI coding s
77

88
The Context7 CLI does three things: fetches up-to-date library documentation, manages AI coding skills, and sets up Context7 MCP for your editor.
99

10-
Run with `npx ctx7` (no install needed) or install globally with `npm install -g ctx7`.
10+
Make sure the CLI is up to date before running commands:
11+
12+
```bash
13+
npm install -g ctx7@latest
14+
```
15+
16+
Or run directly without installing:
17+
18+
```bash
19+
npx ctx7@latest <command>
20+
```
1121

1222
## What this skill covers
1323

@@ -19,7 +29,7 @@ Run with `npx ctx7` (no install needed) or install globally with `npm install -g
1929

2030
```bash
2131
# Documentation
22-
ctx7 library <name> [query] # Step 1: resolve library ID
32+
ctx7 library <name> <query> # Step 1: resolve library ID
2333
ctx7 docs <libraryId> <query> # Step 2: fetch docs
2434

2535
# Skills

0 commit comments

Comments
 (0)