视觉画布设计
canvas-design
基于设计原则创作静态视觉作品,用于海报与品牌图形。
context7【文档与办公】Context7 fetches current, version-specific documentation and code examples for software libraries and hands them to an AI coding agent, so generated code matches the library version in use instead of stale training data. Use when someone says "use context7", "get the latest docs for this library", "look up the current API", "the agent keeps using a d…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Context7 is a hosted index of library documentation built from public repositories and documentation sites. An agent reaches it in two ways: the ctx7 command-line tool, or an MCP server (hosted at https://mcp.context7.com/mcp, or run locally from the @upstash/context7-mcp package). A lookup always has two steps: resolve a library name to a Context7 library ID, then ask a question against that ID. The answer is a set of code snippets and short explanations, each with a link to the source file it came from.
One command configures an agent. It signs in through a device-code flow (a link and a short code, so it also works over SSH), creates an API key, and writes the configuration.
# Interactive: choose MCP or CLI + Skills, then the agent
npx ctx7 setup
# CLI + Skills mode: installs a docs skill that calls the ctx7 CLI
npx ctx7 setup --cli --claude
npx ctx7 setup --cli --codex
# MCP mode: registers the MCP server in the agent's config
npx ctx7 setup --mcp --cursor
# Current project only (the default is global), no confirmation prompts
npx ctx7 setup --mcp --claude --project --yes
# Optional: install the CLI globally to drop the npx prefix
npm install -g ctx7
setup accepts an agent flag: --claude, --cursor, --codex, --gemini, --copilot, --vscode, --opencode, --antigravity or --devin. In MCP mode it registers the hosted server; add --stdio to run the server as a local process instead.
To reuse an existing key instead of signing in, create one at https://context7.com/dashboard, export it as CONTEXT7_API_KEY, and pass it:
npx ctx7 setup --mcp --claude --api-key "$CONTEXT7_API_KEY"
Undo with npx ctx7 remove (add --claude, --cursor, --mcp or --cli to narrow it).
# Step 1: find the library ID. The query ranks the candidates.
ctx7 library next.js "redirect unauthenticated users to the login page"
# Step 2: ask the question against the ID
ctx7 docs /vercel/next.js "redirect unauthenticated users to the login page"
# A specific version, taken from the Versions column of step 1
ctx7 docs /vercel/next.js/v15.1.8 "redirect unauthenticated users to the login page"
# JSON for scripts (the first row is the top-ranked match, not necessarily the official repository)
ctx7 library next.js "redirect unauthenticated users to the login page" --json | jq '.[0].id'
ctx7 docs /vercel/next.js "redirect unauthenticated users to the login page" --json
Each row of ctx7 library shows the Library ID, the number of indexed code snippets, a source reputation (High, Medium, Low, Unknown), a benchmark score from 0 to 100, and the available version IDs. When several rows match, take the one whose name is closest, with the most snippets and the best reputation. Official repositories usually appear as /owner/repo; documentation sites appear as /websites/name.
Write the query as a full question about the task. "How to verify a JWT in Express middleware" returns better snippets than "auth".
# Claude Code, hosted server (no local Node.js process)
claude mcp add --scope user --transport http \
--header "Authorization: Bearer $CONTEXT7_API_KEY" \
context7 https://mcp.context7.com/mcp
# Claude Code, local stdio server
claude mcp add --scope user context7 -- npx -y @upstash/context7-mcp --api-key "$CONTEXT7_API_KEY"
# OpenAI Codex
codex mcp add context7 -- npx -y @upstash/context7-mcp --api-key "$CONTEXT7_API_KEY"
Cursor (~/.cursor/mcp.json, or .cursor/mcp.json in a project) and most other clients take a JSON entry. The hosted server works without a key at a low rate limit:
{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp"
}
}
}
For the higher limit, either add a headers object with Authorization set to Bearer plus the key (user-level file only, never a committed one), or change the URL to https://mcp.context7.com/mcp/oauth and sign in through the client. Gemini CLI uses the key httpUrl instead of url in ~/.gemini/settings.json.
| Tool | Arguments (all required) | Returns |
|---|---|---|
resolve-library-id | libraryName, query | Matching libraries with their IDs |
query-docs | libraryId, query | Snippets and explanations for the question |
{
"name": "resolve-library-id",
"arguments": {
"libraryName": "supabase",
"query": "sign up a user with email and password"
}
}
{
"name": "query-docs",
"arguments": {
"libraryId": "/supabase/supabase",
"query": "sign up a user with email and password"
}
}
Skip resolve-library-id when the ID is already known.
How do I enable row-level security on a Supabase table? use context7
Implement password sign-in. use library /supabase/supabase for API and docs.
How do I set up Next.js 14 middleware? use context7
Naming a version in the prompt makes Context7 match that version. To trigger lookups without typing "use context7", add a standing rule to CLAUDE.md, Cursor rules, or the agent's equivalent:
When a task needs library or API documentation, setup steps, or code that calls
a third-party package, look it up with Context7 first instead of answering from memory.
ctx7 setup installs an equivalent skill or rule automatically.
For scripts and services that are not MCP clients. The search endpoint returns JSON; /api/v2/context returns plain text unless type=json is passed.
curl -G "https://context7.com/api/v2/libs/search" \
-H "Authorization: Bearer $CONTEXT7_API_KEY" \
--data-urlencode "libraryName=next.js" \
--data-urlencode "query=redirect unauthenticated users"
curl -G "https://context7.com/api/v2/context" \
-H "Authorization: Bearer $CONTEXT7_API_KEY" \
--data-urlencode "libraryId=/vercel/next.js" \
--data-urlencode "query=redirect unauthenticated users" \
--data-urlencode "type=json"
The JSON body has codeSnippets (each with codeTitle, codeDescription, and codeList of language and code) and infoSnippets. GET /api/v3/search takes only a query, plus optional library and language hints, and picks the libraries itself.
| Status | Meaning | Action |
|---|---|---|
| 202 | Library still being indexed | Retry later |
| 301 | Library moved | Use the ID in redirectUrl |
| 401 | Bad key | Keys start with ctx7sk |
| 404 | Unknown library ID | Run the search step again |
| 429 | Rate limit | Wait for the Retry-After header |
ctx7 login # browser sign-in; --no-browser prints the URL instead
ctx7 whoami
ctx7 logout
export CTX7_TELEMETRY_DISABLED=1 # turn off anonymous CLI usage data
ctx7 library and ctx7 docs work without signing in. CONTEXT7_API_KEY in the environment replaces interactive login in CI.
Request: "We upgraded to the latest Next.js. Add a guard that sends signed-out users from /dashboard to /login. use context7"
ctx7 library next.js "redirect unauthenticated users to the login page"
ctx7 docs /vercel/next.js "redirect unauthenticated users to the login page"
Result (shortened): the first command lists /vercel/next.js (about 4,600 snippets, versions such as v15.1.8 and v14.3.0-canary.87) above /websites/nextjs and several third-party auth packages. The second returns snippets with their sources:
### Perform optimistic authentication checks in proxy
Source: https://github.com/vercel/next.js/blob/canary/docs/01-app/02-guides/authentication.mdx
export default async function proxy(req: NextRequest) {
const path = req.nextUrl.pathname
const isProtectedRoute = protectedRoutes.includes(path)
const cookie = (await cookies()).get('session')?.value
const session = await decrypt(cookie)
if (isProtectedRoute && !session?.userId) {
return NextResponse.redirect(new URL('/login', req.nextUrl))
}
return NextResponse.next()
}
The current documentation uses a proxy file and export where older versions used middleware. The agent writes proxy.ts instead of the convention it remembered, and cites the source link in its answer.
Request: "Write the email and password sign-up function for our Supabase project."
The agent calls resolve-library-id with libraryName: "supabase", receives /supabase/supabase, /websites/supabase, /supabase/auth and /supabase/ssr, picks /supabase/supabase, then calls query-docs.
Result: the top snippet is titled "Sign up user with email and password in JavaScript", comes from apps/docs/content/guides/auth/passwords.mdx in the Supabase repository, and shows supabase.auth.signUp() taking email, password and an optional options.emailRedirectTo. The agent writes the function from that snippet, reading project settings from the environment (the URL and publishable key are listed in the Supabase dashboard under the project's API settings):
import { createClient } from '@supabase/supabase-js'
const supabase = createClient(
process.env.SUPABASE_URL!,
process.env.SUPABASE_PUBLISHABLE_KEY!,
)
export async function signUpWithPassword(email: string, password: string) {
const { data, error } = await supabase.auth.signUp({
email,
password,
options: { emailRedirectTo: `${process.env.APP_URL}/welcome` },
})
if (error) throw error
return data
}
ctx7 docs react "hooks" fails with Invalid library ID: "react": an ID always starts with /. Run ctx7 library or resolve-library-id first unless the ID is known.package.json, pyproject.toml or the lockfile, and pass /owner/repo/version (or /owner/repo@version in the REST API). Without a version the newest indexed documentation is returned, which may be ahead of the installed package.CONTEXT7_API_KEY or a user-level config file. Do not commit it in .mcp.json, .cursor/mcp.json or CI logs; revoke leaked keys in the dashboard.429 response carries Retry-After; back off instead of retrying in a loop, and cache answers for repeated questions.@upstash/context7-mcp@latest. For ERR_MODULE_NOT_FOUND, run the package with bunx instead of npx, or switch to the hosted URL, which needs no local Node.js. curl https://mcp.context7.com/ping checks connectivity.