### Install with ctx7 CLI Source: https://github.com/saalse/context7-add/blob/main/docs/install.mdx Alternative installation using the ctx7 CLI. Requires Node.js and npx. ```bash npx ctx7 skills install /saalse/context7-add context7-add ``` -------------------------------- ### Install with Context7 CLI Source: https://github.com/saalse/context7-add/blob/main/README.md Installs the context7-add skill using the Context7 CLI. ```bash npx ctx7 skills install /saalse/context7-add context7-add ``` -------------------------------- ### Install with npx skills add Source: https://github.com/saalse/context7-add/blob/main/README.md Installs the context7-add skill using the npx skills CLI. ```bash npx skills add saalse/context7-add ``` -------------------------------- ### Install with skills CLI Source: https://github.com/saalse/context7-add/blob/main/docs/install.mdx Use the skills CLI to add the context7-add skill to your agent. Requires Node.js and npx. ```bash npx skills add saalse/context7-add ``` -------------------------------- ### main() argparse CLI setup Source: https://github.com/saalse/context7-add Defines the CLI entry point for c7.py. Uses RawDescriptionHelpFormatter so --help prints the module docstring verbatim. The subcommand is required and each parser maps to a cmd_* handler via fn, invoked by args.fn(args). ```python def main(): p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) sub = p.add_subparsers(dest="cmd", required=True) sub.add_parser("whoami").set_defaults(fn=cmd_whoami) s = sub.add_parser("check"); s.add_argument("inputs", nargs="+"); s.set_defaults(fn=cmd_check) s = sub.add_parser("allow"); s.add_argument("entries", nargs="+") s.add_argument("--remove", action="store_true"); s.add_argument("--apply", action="store_true") s.set_defaults(fn=cmd_allow) s = sub.add_parser("add"); s.add_argument("url") s.add_argument("--type", choices=list(ADD_ENDPOINT)); s.add_argument("--private", action="store_true") s.add_argument("--generate-docs", action="store_true"); s.add_argument("--base-url") s.add_argument("--git-token-env", help="name of an env var holding a git token (never pass the token itself)") s.add_argument("--apply", action="store_true"); s.set_defaults(fn=cmd_add) s = sub.add_parser("upload"); s.add_argument("file"); s.add_argument("--title"); s.add_argument("--description") s.add_argument("--apply", action="store_true"); s.set_defaults(fn=cmd_upload) s = sub.add_parser("refresh"); s.add_argument("library_id"); s.add_argument("--apply", action="store_true") s.set_defaults(fn=cmd_refresh) s = sub.add_parser("wait"); s.add_argument("library_id") s.add_argument("--timeout", type=int, default=900); s.add_argument("--interval", type=int, default=20) s.add_argument("--changed", action="store_true", help="after a refresh: wait until lastUpdateDate moves") s.set_defaults(fn=cmd_wait) sub.add_parser("log").set_defaults(fn=cmd_log) args = p.parse_args() args.fn(args) ``` -------------------------------- ### Example log output (JSONL) Source: https://github.com/saalse/context7-add Sample output of the log command, showing two entries: an allowlist_add and an add action. ```jsonl {"at": "2026-01-15T10:23:41+00:00", "action": "allowlist_add", "entries": ["/acme/widgets"], "countBefore": 5112, "countAfter": 5113} {"at": "2026-01-15T10:24:05+00:00", "action": "add", "source": "github", "url": "https://github.com/acme/widgets", "libraryId": "/acme/widgets", "version": null, "private": false} ``` -------------------------------- ### Example whoami JSON output Source: https://github.com/saalse/context7-add Example JSON report printed to stdout. Shows teamspaces, plan, policy mode, allowlist details, accessible library count, and source types. ```json { "teamspaces": [{"name": "acme", "role": "admin", "ownerPlan": "team"}], "plan": "team", "policyMode": "select", "allowList": "select.allowedLibraries", "allowListEntries": 42, "accessibleLibraryCount": 5123, "sourceTypes": {"website": true, "github": true, "gitlab": true} } ``` -------------------------------- ### c7.py command-line usage examples Source: https://github.com/saalse/context7-add/blob/main/skills/context7-add/SKILL.md Run from the skill's folder. Reads API key from $CONTEXT7_API_KEY or ~/.claude.json. All changes are dry runs unless --apply. Exit codes: 0 ok, 1 API/network, 2 bad input/file too large, 3 key/role/plan, 4 not found, 5 refused by policy, 6 rate limited, 7 unprocessable/not docs site, 8 wait timed out, 9 queue full, 130 add interrupted. ```bash python3 scripts/c7.py whoami # plan, role, policy mode, which list admits libraries ``` ```bash python3 scripts/c7.py check … # indexed? fresh? allowed? which entry covers it? ``` ```bash python3 scripts/c7.py allow /org/repo [--remove] [--apply] # dry run shows library count before/after ``` ```bash python3 scripts/c7.py add … [--type …] [--base-url URL] [--private] [--queue [--queue-timeout SEC]] [--apply] ``` ```bash python3 scripts/c7.py upload [--title …] [--description …] [--skip-size-check] [--apply] ``` ```bash python3 scripts/c7.py refresh /org/repo [--apply] # re-crawl / re-parse a stale library ``` ```bash python3 scripts/c7.py wait /org/repo [--changed] # until indexed; --changed: until a refresh lands ``` ```bash python3 scripts/c7.py log # what this skill changed before (registry.jsonl) ``` -------------------------------- ### registry.jsonl entry format Source: https://github.com/saalse/context7-add Example of a single JSON-lines entry in registry.jsonl, created by log(action, **fields). Shows the 'at' timestamp and action-specific fields. ```json {"at": "2026-01-15T10:23:41+00:00", "action": "allowlist_add", "entries": ["/acme/widgets"], "countBefore": 5112, "countAfter": 5113} ``` -------------------------------- ### Dry run JSON output Source: https://github.com/saalse/context7-add Example JSON output from a dry run, showing the projected library counts before and after the change. ```json { "dryRun": true, "list": "select.allowedLibraries", "operation": {"add": ["/acme/widgets"]}, "alreadyInDesiredState": [], "accessibleLibraryCountBefore": 5112, "accessibleLibraryCountAfter": 5113 } ``` -------------------------------- ### check Source: https://github.com/saalse/context7-add Reports, for each input, whether the source is indexed in Context7, in what state, whether it is fresh enough, and which existing allowlist entry already covers it. It probes library ids directly via GET /v2/context to distinguish 'not indexed' (404) from 'indexed but refused' (403 blocked_by_policy_or_plan). ```APIDOC ## check ### Description Reports, for each input, whether the source is indexed in Context7, in what state, whether it is fresh enough, and which existing allowlist entry already covers it. It probes library ids directly via GET /v2/context to distinguish 'not indexed' (404) from 'indexed but refused' (403 blocked_by_policy_or_plan). ### Method CLI ### Endpoint `python3 scripts/c7.py check ...` ### Parameters #### Inputs - **inputs** (list[str]) - Required - Any mixture of: repo URLs, `owner/repo`, library ids, `context7.com` library URLs, docs-site/llms.txt/OpenAPI URLs, GitHub user/org URLs, or names ### Response #### Success Response - **policyMode** (string) - The policy mode from libraryFilters. - **results** (list) - Per-input report objects. ``` -------------------------------- ### Example JSON report output Source: https://github.com/saalse/context7-add Sample output from the check command showing the report structure. The report includes policyMode, results with input, kind, libraryId, host, probeStatus, state, coveredBy, and optional fields like guessedIds, siteLlmsFiles, and search. Exit code 0 means a report was produced, not that libraries exist. ```json { "policyMode": "select", "results": [ { "input": "https://github.com/acme/widgets", "kind": "github", "libraryId": "/acme/widgets", "host": "github.com", "probeStatus": 403, "state": "blocked_by_policy_or_plan", "coveredBy": [] }, { "input": "https://docs.acme.dev/guide/", "kind": "website", "libraryId": null, "host": "docs.acme.dev", "guessedIds": [{"libraryId": "/websites/acme_guide", "state": "ready", "coveredBy": ["docs.acme.dev"]}], "siteLlmsFiles": ["https://docs.acme.dev/llms.txt"], "search": {"status": 200, "results": []} } ] } ``` -------------------------------- ### add command JSON output with notSubmitted Source: https://github.com/saalse/context7-add/blob/main/docs/commands.mdx When the queue is full, when Context7 rate-limits you (429), or when the key is refused (401), add stops: the remaining URLs would be refused too. With several URLs, the output lists what was not submitted, starting with the URL that hit the limit. ```json { "results": [ {"input": "https://github.com/acme/a", "status": 200, "libraryId": "/acme/a", "...": "..."}, {"input": "https://github.com/acme/b", "status": 400, "response": {"error": "user-has-active-task", "message": "You already have 5 libraries being processed or queued. ..."}, "meaning": "not submitted: Context7 allows 5 libraries processing or queued per user. ..."} ], "notSubmitted": ["https://github.com/acme/b", "https://docs.acme.dev/"], "next": "Context7's queue holds 5 libraries per user. Resubmit notSubmitted once some finish ..." } ``` -------------------------------- ### Add many sources with allow and add Source: https://github.com/saalse/context7-add/blob/main/docs/commands.mdx Context7 lets each user have at most 5 libraries processing or queued at a time. Pass every URL to one add call. In select mode, allow public repos first: their submission is gated by the policy. ```bash python3 scripts/c7.py allow /acme/a /acme/b --apply python3 scripts/c7.py add https://github.com/acme/a https://github.com/acme/b https://docs.acme.dev/ --apply ``` -------------------------------- ### POST /v2/add/repo/ Source: https://github.com/saalse/context7-add Adds a repository from a supported host (github, gitlab, bitbucket, or git) to Context7. The request body includes the repository URL and optional fields for private access, documentation generation, and a git token. ```APIDOC ## POST /v2/add/repo/ ### Description Adds a repository from a supported host (github, gitlab, bitbucket, or git) to Context7. The request body includes the repository URL and optional fields for private access, documentation generation, and a git token. ### Method POST ### Endpoint POST /v2/add/repo/ ### Parameters #### Path Parameters - **host** (string) - Required - The host type: `github`, `gitlab`, `bitbucket`, or `git`. #### Request Body - **docsRepoUrl** (string) - Required - The URL of the repository. - **private** (boolean) - Optional - Indicates if the repository is private. - **generateDocs** (boolean) - Optional - Whether to generate documentation. - **gitToken** (string) - Optional - Git token for authentication. ### Response #### Success Response (200) - **status** (integer) - `200` - **response** (object) - Raw API response - **expectedLibraryId** (string | null) - From classification - **libraryId** (string) - `response.libraryName` — the id to `allow` and `wait` on #### Error Response (403) - **status** (integer) - `403` - **meaning** (string) - `"refused: if error is access_denied the library id is outside the allowlist (allow it first); otherwise role/plan"` #### Error Response (409) - **status** (integer) - `409` - **libraryId** (string) - Id extracted from the error message by `re.search(r"(/[\w.@-]+(?:/[\w.@-]+)+)", message)`, lowercased, falling back to `expectedLibraryId` - **meaning** (string) - `"already exists in Context7: nothing was created; just make sure it is allowed"` ``` -------------------------------- ### GET https://api.github.com/users/{owner}/repos?per_page=100 Source: https://github.com/saalse/context7-add Fetches the repositories of a GitHub user. This is an external endpoint called by the client. It is unauthenticated and uses specific headers. ```APIDOC ## GET https://api.github.com/users/{owner}/repos?per_page=100 ### Description Fetches the repositories of a GitHub user. This is an external endpoint called by the client. It is unauthenticated and uses specific headers. ### Method GET ### Endpoint https://api.github.com/users/{owner}/repos?per_page=100 ### Parameters #### Path Parameters - **owner** (string) - Required - The GitHub username. #### Query Parameters - **per_page** (integer) - Optional - Number of results per page (default 100). ### Response #### Success Response (200) - **name** (string) - Repository name. - **fork** (boolean) - Whether it is a fork. - **archived** (boolean) - Whether it is archived. - **stargazers_count** (integer) - Number of stars. ``` -------------------------------- ### Run helper commands for whoami, check, allow, add, and wait Source: https://github.com/saalse/context7-add/blob/main/README.md Runs the c7.py helper script to check indexing status, allow libraries (dry run or apply), add a library, and wait for indexing. Results are JSON on stdout; errors go to stderr with distinct exit codes. ```bash C7=skills/context7-add/scripts/c7.py python3 $C7 whoami python3 $C7 check https://github.com/saalse/context7-add python3 $C7 allow /saalse/context7-add # dry run python3 $C7 allow /saalse/context7-add --apply python3 $C7 add https://github.com/saalse/context7-add --apply # already indexed: reports its id, creates nothing python3 $C7 wait /saalse/context7-add ``` -------------------------------- ### POST /v2/add/website Source: https://github.com/saalse/context7-add Adds a website to Context7 by providing its URL. Optionally, a base URL for the website can be specified. ```APIDOC ## POST /v2/add/website ### Description Adds a website to Context7 by providing its URL. Optionally, a base URL for the website can be specified. ### Method POST ### Endpoint POST /v2/add/website ### Parameters #### Request Body - **websiteUrl** (string) - Required - The URL of the website. - **websiteBaseUrl** (string) - Optional - The base URL of the website. ### Response #### Success Response (200) - **status** (integer) - `200` - **response** (object) - Raw API response - **expectedLibraryId** (string | null) - From classification - **libraryId** (string) - `response.libraryName` — the id to `allow` and `wait` on #### Error Response (403) - **status** (integer) - `403` - **meaning** (string) - `"refused: if error is access_denied the library id is outside the allowlist (allow it first); otherwise role/plan"` #### Error Response (409) - **status** (integer) - `409` - **libraryId** (string) - Id extracted from the error message by `re.search(r"(/[\w.@-]+(?:/[\w.@-]+)+)", message)`, lowercased, falling back to `expectedLibraryId` - **meaning** (string) - `"already exists in Context7: nothing was created; just make sure it is allowed"` ``` -------------------------------- ### c7.py upload command syntax Source: https://github.com/saalse/context7-add/blob/main/docs/upload.mdx Uploads a PDF, DOCX, or OpenAPI file to Context7. It is a dry run until --apply is passed. Options include --title, --description, --skip-size-check, and --apply. ```bash python3 scripts/c7.py upload [--title TITLE] [--description TEXT] [--skip-size-check] [--apply] ``` -------------------------------- ### add Source: https://github.com/saalse/context7-add/blob/main/docs/commands.mdx Submits one or more repo, website, llms.txt, or OpenAPI URLs; reports the existing ID if Context7 already has it. Supports queueing and various options. ```APIDOC ## add ### Description Submits one or more repo, website, llms.txt, or OpenAPI URLs; reports the existing ID if Context7 already has it. Supports queueing and various options. ### Method CLI ### Command `python3 scripts/c7.py add ... [--type T] [--base-url URL] [--private] [--git-token-env VAR] [--queue [--queue-timeout SEC]] [--apply]` ### Parameters #### Positional Arguments - `` (string) - Required - One or more URLs to submit. #### Options - `--type T` (string) - Optional - Type of the source (e.g., repo, website, llms.txt, openapi). Applies to a single URL only. - `--base-url URL` (string) - Optional - Base URL for the source. Applies to a single URL only. - `--private` (flag) - Optional - Mark the source as private. - `--git-token-env VAR` (string) - Optional - Environment variable containing a Git token for private repos. - `--queue` (flag) - Optional - Queue the submission; if the queue is full, wait and retry. - `--queue-timeout SEC` (integer) - Optional - Timeout in seconds for queue retries (default 1800). - `--apply` (flag) - Optional - Apply changes; without it, the command is a dry run. ### Output JSON on stdout; progress and errors on stderr. ### Request Example ```bash python3 scripts/c7.py add https://github.com/acme/a https://github.com/acme/b https://docs.acme.dev/ --apply ``` ### Response Example ```json { "results": [ {"input": "https://github.com/acme/a", "status": 200, "libraryId": "/acme/a", "...": "..."}, {"input": "https://github.com/acme/b", "status": 400, "response": {"error": "user-has-active-task", "message": "You already have 5 libraries being processed or queued. ..."}, "meaning": "not submitted: Context7 allows 5 libraries processing or queued per user. ..."} ], "notSubmitted": ["https://github.com/acme/b", "https://docs.acme.dev/"], "next": "Context7's queue holds 5 libraries per user. Resubmit notSubmitted once some finish ..." } ``` ``` -------------------------------- ### command add Source: https://github.com/saalse/context7-add Adds a source (repository, website, or llms.txt) to Context7. Supports dry-run by default and requires --apply to execute. ```APIDOC ## [CLI] command add ### Description Adds a source (repository, website, or llms.txt) to Context7. Supports dry-run by default and requires --apply to execute. ### Method CLI ### Endpoint command add ### Parameters #### Path Parameters - `url` (string) - Required - The source URL. For repos the classified `repoUrl` (normalized, `.git` stripped) is submitted instead of the raw input #### Options - `--type` (string) - Optional - One of the `ADD_ENDPOINT` keys: `github`, `gitlab`, `bitbucket`, `git`, `website`, `llmstxt`, `openapi`. Needed when classification is ambiguous - `--private` (flag) - Optional - Repositories only; adds `"private": true`. Private sources need a paid plan and are not gated by the public allowlist - `--generate-docs` (flag) - Optional - **Private repositories only**; adds `"generateDocs": true` (generate docs for the private repo) - `--base-url` (string) - Optional - **Websites only**; adds `"websiteBaseUrl"` — crawl the section at that URL - `--git-token-env` (string) - Optional - Name of an env var holding a git token for private repo access; the token itself is read into `"gitToken"` and **redacted as ``** in dry-run output - `--apply` (flag) - Optional - Off = dry run only ### Response #### Success Response No explicit success response documented. ### Error Handling Flag/source-type combination errors abort with exit `2` before any network call: - `--type` not in `ADD_ENDPOINT` - llms.txt URL whose filename is not exactly `llms.txt`, `llms-full.txt` or `llms-small.txt` (per-section `llms-.txt` is refused by Context7) - `--private` on a non-repo - `--generate-docs` outside private repos - `--base-url` on a non-website - `$VAR` named by `--git-token-env` is empty ``` -------------------------------- ### Docs section with crawl base (narrowest entry pattern) Source: https://github.com/saalse/context7-add Add a narrow website source by specifying a docs section and its crawl base URL with --base-url. This is the 'narrowest entry' pattern for a narrow website source. Apply the submission with --apply. ```bash python3 skills/context7-add/scripts/c7.py add https://docs.acme.dev/guide/ \ --base-url https://docs.acme.dev/guide/ --apply ``` -------------------------------- ### CLI usage for upload command Source: https://github.com/saalse/context7-add Shows the command-line invocation for uploading a PDF, DOCX, or OpenAPI file. Requires --apply to actually upload; otherwise it performs a dry run. Optional --title and --description set metadata. ```bash python3 scripts/c7.py upload [--title T] [--description D] [--apply] ``` -------------------------------- ### POST /v2/add/openapi Source: https://github.com/saalse/context7-add Adds an OpenAPI specification to Context7 by providing its URL. ```APIDOC ## POST /v2/add/openapi ### Description Adds an OpenAPI specification to Context7 by providing its URL. ### Method POST ### Endpoint POST /v2/add/openapi ### Parameters #### Request Body - **openApiUrl** (string) - Required - The URL of the OpenAPI specification. ### Response #### Success Response (200) - **status** (integer) - `200` - **response** (object) - Raw API response - **expectedLibraryId** (string | null) - From classification - **libraryId** (string) - `response.libraryName` — the id to `allow` and `wait` on #### Error Response (403) - **status** (integer) - `403` - **meaning** (string) - `"refused: if error is access_denied the library id is outside the allowlist (allow it first); otherwise role/plan"` #### Error Response (409) - **status** (integer) - `409` - **libraryId** (string) - Id extracted from the error message by `re.search(r"(/[\w.@-]+(?:/[\w.@-]+)+)", message)`, lowercased, falling back to `expectedLibraryId` - **meaning** (string) - `"already exists in Context7: nothing was created; just make sure it is allowed"` ``` -------------------------------- ### Basic public repo: dry run then apply Source: https://github.com/saalse/context7-add Run the add command for a public repository in dry-run mode first, then apply the submission. The first command shows the dry run; the second applies it. Exit code 0 indicates the dry run shown, submission accepted (200), or already exists (409). ```bash python3 skills/context7-add/scripts/c7.py add https://github.com/acme/widgets python3 skills/context7-add/scripts/c7.py add https://github.com/acme/widgets --apply ``` -------------------------------- ### POST /v2/add/llmstxt Source: https://github.com/saalse/context7-add Adds an llmstxt resource to Context7 by providing its URL. ```APIDOC ## POST /v2/add/llmstxt ### Description Adds an llmstxt resource to Context7 by providing its URL. ### Method POST ### Endpoint POST /v2/add/llmstxt ### Parameters #### Request Body - **llmstxtUrl** (string) - Required - The URL of the llmstxt resource. ### Response #### Success Response (200) - **status** (integer) - `200` - **response** (object) - Raw API response - **expectedLibraryId** (string | null) - From classification - **libraryId** (string) - `response.libraryName` — the id to `allow` and `wait` on #### Error Response (403) - **status** (integer) - `403` - **meaning** (string) - `"refused: if error is access_denied the library id is outside the allowlist (allow it first); otherwise role/plan"` #### Error Response (409) - **status** (integer) - `409` - **libraryId** (string) - Id extracted from the error message by `re.search(r"(/[\w.@-]+(?:/[\w.@-]+)+)", message)`, lowercased, falling back to `expectedLibraryId` - **meaning** (string) - `"already exists in Context7: nothing was created; just make sure it is allowed"` ``` -------------------------------- ### check Source: https://github.com/saalse/context7-add/blob/main/docs/commands.mdx Checks state, freshness, and coverage per input; also guesses website IDs, retrieves the site's llms.txt files, and lists a GitHub owner's repos. ```APIDOC ## check ### Description Checks state, freshness, and coverage per input; also guesses website IDs, retrieves the site's llms.txt files, and lists a GitHub owner's repos. ### Method CLI ### Command `python3 scripts/c7.py check ...` ### Parameters #### Positional Arguments - `` (string) - Required - One or more inputs to check. ### Output JSON on stdout; progress and errors on stderr. ``` -------------------------------- ### cmd_add implementation Source: https://github.com/saalse/context7-add Implements the `add` command for submitting URLs to Context7. It classifies the URL, validates the source type and filename for llms.txt, builds the request body, and performs a dry run unless `--apply` is set. Handles flags like `--private`, `--generate-docs`, `--base-url`, and `--git-token-env` with usage errors. ```python def cmd_add(args): c = classify(args.url) kind = args.type or c["kind"] if kind not in ADD_ENDPOINT: fail(EXIT_USAGE, f"Cannot tell the source type of {args.url!r} (got {kind!r}); pass --type " f"{'|'.join(ADD_ENDPOINT)}.") if kind == "llmstxt": fname = urllib.parse.urlparse(args.url).path.rstrip("/").split("/")[-1].lower() if fname not in ("llms.txt", "llms-full.txt", "llms-small.txt"): fail(EXIT_USAGE, f"Context7 only accepts files named llms.txt, llms-full.txt or llms-small.txt (got {fname!r}). " "For a per-section file, cover the missing pages with a narrow website source instead: " "add
--base-url
.") path, field = ADD_ENDPOINT[kind] body = {field: c.get("repoUrl") or args.url} is_repo = field == "docsRepoUrl" if args.private: if not is_repo: fail(EXIT_USAGE, "--private applies to repositories only.") body["private"] = True if args.generate_docs: if not (is_repo and args.private): fail(EXIT_USAGE, "--generate-docs applies to private repositories only.") body["generateDocs"] = True if args.base_url: if kind != "website": fail(EXIT_USAGE, "--base-url applies to websites only.") body["websiteBaseUrl"] = args.base_url token_note = None if args.git_token_env: tok = os.environ.get(args.git_token_env) if not tok: fail(EXIT_USAGE, f"${args.git_token_env} is empty.") body["gitToken"] = tok token_note = f"gitToken from ${args.git_token_env}" shown = {k: ("" if k == "gitToken" else v) for k, v in body.items()} if not args.apply: out({"dryRun": True, "would": f"POST {API}{path}", "body": shown, "expectedLibraryId": c["libraryId"], "note": token_note}) return status, data = call("POST", path, body=body) ... ``` -------------------------------- ### Private repo with env-held token and error handling Source: https://github.com/saalse/context7-add Add a private repository using a token from the GIT_TOKEN environment variable (never on the command line). Handles exit code 5 (policy refused, allow the id first) and exit code 7 (unprocessable, no usable docs). On success, parses the JSON output; status 409 means the library already exists and just needs to be allowed. ```python import os, subprocess, json os.environ.setdefault("GIT_TOKEN", "ghp_***") # never on the command line proc = subprocess.run( ["python3", "scripts/c7.py", "add", "https://github.com/acme/internal", "--private", "--git-token-env", "GIT_TOKEN", "--apply"], capture_output=True, text=True) if proc.returncode == 5: print("policy refused:", proc.stderr.strip()) # allow /acme/internal first elif proc.returncode == 7: print("unprocessable:", proc.stderr.strip()) # no usable docs else: result = json.loads(proc.stdout) if result["status"] == 409: lib = result["libraryId"] # already exists: just allow it else: lib = result["libraryId"] print("submit ok:", lib) ``` -------------------------------- ### Run offline unit tests Source: https://github.com/saalse/context7-add/blob/main/README.md Runs the offline test suite that stubs the Context7 API, requiring no key or network. ```bash python3 -m unittest discover -s tests -v ``` -------------------------------- ### search(name, query="documentation") Source: https://github.com/saalse/context7-add Searches for libraries by name using the Context7 search API. Returns search results with limited fields, or an error object on non-200 response. ```APIDOC ## `search(name, query="documentation")` ### Description Searches for libraries by name using the Context7 search API. Returns search results with limited fields, or an error object on non-200 response. ### Method GET ### Endpoint `/v2/libs/search?libraryName=&query=&fast=true` ### Parameters #### Query Parameters - **libraryName** (string) - Required - The library name to search for. - **query** (string) - Optional - Search query, defaults to `"documentation"`. - **fast** (boolean) - Required - Set to `true`. ### Response #### Success Response (200) Returns an object with keys: `status`, `searchFilterApplied`, `results`. The `results` array contains only the first 5 entries, each with keys: `id`, `title`, `state`, `totalSnippets`, `trustScore`, `lastUpdateDate`. #### Error Response Returns `{"status", "results": [], "error"}` on non-200 status. ### Notes - Search is policy-filtered: refused libraries are hidden, so a name search can never prove a library is unindexed. ``` -------------------------------- ### covering_entries(lib_id, host, allowed) Source: https://github.com/saalse/context7-add Returns the entries of an allowlist that already admit a library. It checks whether a library ID or docs host matches any allowlist entry, using the documented matching rules. ```APIDOC ## `covering_entries(lib_id, host, allowed)` ### Description Returns the entries of an allowlist that already admit a library. ### Parameters - `lib_id` (str | None) - Library id, e.g. `/acme/widgets` - `host` (str | None) - Docs-site host of the library, e.g. `docs.acme.dev` - `allowed` (list[str]) - Current allowlist / wild-card entries ### Matching Rules - Entry starting with `/`: covers if `lib_id == entry` or `lib_id.startswith(entry + "/")` — so `/acme` covers `/acme/widgets` but not `/acme2/x`. - Otherwise (domain): covers if `host == entry` or `host.endswith("." + entry)`. Note the asymmetry the skill documents: a **domain** entry matches a library's *docs site* host, not the host of a repo URL (`github.com` does not admit GitHub repos). ``` -------------------------------- ### allow Source: https://github.com/saalse/context7-add/blob/main/docs/commands.mdx Adds or removes allowlist or wild-card entries, with a dry-run library count unless --apply is passed. ```APIDOC ## allow ### Description Adds or removes allowlist or wild-card entries, with a dry-run library count unless --apply is passed. ### Method CLI ### Command `python3 scripts/c7.py allow ... [--remove] [--apply]` ### Parameters #### Positional Arguments - `` (string) - Required - One or more allowlist entries to add or remove. #### Options - `--remove` (flag) - Optional - Remove the entries instead of adding. - `--apply` (flag) - Optional - Apply changes; without it, the command is a dry run. ### Output JSON on stdout; progress and errors on stderr. ``` -------------------------------- ### Basic upload with c7.py Source: https://github.com/saalse/context7-add Uploads a PDF file with a title and applies the upload. Exit code 0 indicates success. ```bash python3 skills/context7-add/scripts/c7.py upload handbook.pdf --title "Acme Handbook" --apply ``` -------------------------------- ### probe(lib_id) Source: https://github.com/saalse/context7-add Asks Context7 to serve the library, telling whether it exists, is processing, blocked, or missing. It performs a single read request and maps the HTTP status to a state. ```APIDOC ## `probe(lib_id)` ### Description Ask Context7 to serve the library: tells exists / processing / blocked / missing. ### Parameters - `lib_id` (str) - Library id to probe. ### Behavior Calls `GET /v2/context?libraryId=&query=getting started overview&type=json` and maps the HTTP status to a `state`. ### Status Mapping | Status | `state` | |---|---| | 200 | `ready` | | 202 | `processing` | | 301 | `redirected` | | 403 | `blocked_by_policy_or_plan` | | 404 | `not_found`; if body `error == "no_snippets_found"` → `processing_or_empty` | | 422 | `unprocessable` | | other | `http_` | ### Returns Returns `{"probeStatus", "state"}` plus `error`/`message` (non-200 with a JSON body) and `redirectUrl` (when present). A fresh submit answers `processing_or_empty` until parsing finishes — `wait`, not a single probe, is the reliable check. ``` -------------------------------- ### Preview PDF upload with c7.py upload Source: https://github.com/saalse/context7-add/blob/main/docs/upload.mdx Dry run for uploading acme-handbook.pdf with title and description. It checks file type, existence, and size, sends nothing, and needs no API key. ```bash python3 scripts/c7.py upload acme-handbook.pdf --title "Acme Handbook" --description "Internal engineering handbook" ``` ```json { "dryRun": true, "would": "POST https://context7.com/api/v2/add/pdf-upload", "file": "acme-handbook.pdf", "bytes": 1200000, "fields": { "projectTitle": "Acme Handbook", "description": "Internal engineering handbook" }, "note": "Uploaded files are private to the teamspace (source type uploaded_files), not subject to the public allowlist. The library id is built from the file name (for a PDF: /pdf/--), not from --title: rename the file first if its name says nothing." } ``` -------------------------------- ### add command Source: https://github.com/saalse/context7-add Adds a repository or website to Context7. Supports dry run and apply modes, private repositories, and custom crawl base URLs. Exit codes indicate success or specific failure conditions. ```APIDOC ## add command ### Description Adds a repository or website to Context7. Supports dry run and apply modes, private repositories, and custom crawl base URLs. Exit codes indicate success or specific failure conditions. ### Usage ```bash python3 skills/context7-add/scripts/c7.py add [options] ``` ### Parameters - `` (string) - Required - URL of the repository or website to add. - `--apply` (flag) - Optional - Actually submit the addition; without it, a dry run is shown. - `--base-url` (string) - Optional - Base URL for crawling a website source. - `--private` (flag) - Optional - Indicates a private repository. - `--git-token-env` (string) - Optional - Name of environment variable holding the Git token. ### Exit Codes | Code | Condition | |---|---| | 0 | Dry run shown, submission accepted (200), or already exists (409) | | 2 | Type/flag combination error, bad llms.txt name, empty git-token env var | | 3 | Auth (401, or 403 that is not `access_denied`) | | 5 | 403 `access_denied` — submit gated by the policy; allow the id first and retry | | 6 | 429 rate limited | | 7 | 422 — the source is unprocessable (no or too few docs) | | 1 / 4 | Other failures / resource not found | ### Examples Basic public repo, dry run then apply: ```bash python3 skills/context7-add/scripts/c7.py add https://github.com/acme/widgets python3 skills/context7-add/scripts/c7.py add https://github.com/acme/widgets --apply ``` Docs section with a crawl base (a narrow website source, the "narrowest entry" pattern): ```bash python3 skills/context7-add/scripts/c7.py add https://docs.acme.dev/guide/ \ --base-url https://docs.acme.dev/guide/ --apply ``` Private repo with an env-held token, plus error handling: ```python import os, subprocess, json os.environ.setdefault("GIT_TOKEN", "ghp_***") # never on the command line proc = subprocess.run( ["python3", "scripts/c7.py", "add", "https://github.com/acme/internal", "--private", "--git-token-env", "GIT_TOKEN", "--apply"], capture_output=True, text=True) if proc.returncode == 5: print("policy refused:", proc.stderr.strip()) # allow /acme/internal first elif proc.returncode == 7: print("unprocessable:", proc.stderr.strip()) # no usable docs else: result = json.loads(proc.stdout) if result["status"] == 409: lib = result["libraryId"] # already exists: just allow it else: lib = result["libraryId"] print("submit ok:", lib) ``` ``` -------------------------------- ### Removal with error handling in Python Source: https://github.com/saalse/context7-add Run the allow command with --remove and --apply, capturing output and handling non-zero exit codes. Exit code 5 indicates a 403 access_denied error due to insufficient role. ```python import subprocess, json proc = subprocess.run(["python3", "scripts/c7.py", "allow", "/acme/widgets", "--remove", "--apply"], capture_output=True, text=True) if proc.returncode != 0: # exit 5: 403 access_denied — the key's role cannot change policies print("refused:", proc.stderr.strip()) else: result = json.loads(proc.stdout) print("count:", result["accessibleLibraryCountBefore"], "->", result["accessibleLibraryCountAfter"]) ``` -------------------------------- ### whoami Source: https://github.com/saalse/context7-add/blob/main/docs/commands.mdx Displays the current plan, role, policy mode, and which list admits libraries. ```APIDOC ## whoami ### Description Displays the current plan, role, policy mode, and which list admits libraries. ### Method CLI ### Command `python3 scripts/c7.py whoami` ### Output JSON on stdout; progress and errors on stderr. ``` -------------------------------- ### whoami Source: https://github.com/saalse/context7-add Prints the teamspace's plan, the caller's role, the policy mode, and which allowlist admits libraries. It is the skill's orientation step: it determines whether the caller may change policies at all (only owner/admin roles can) and which list (select.allowedLibraries or quality.exceptedLibraries) is in force. ```APIDOC ## [CLI] whoami ### Description Prints the teamspace's plan, the caller's role, the policy mode, and which allowlist admits libraries. It is the skill's orientation step: it determines whether the caller may change policies at all (only owner/admin roles can) and which list (select.allowedLibraries or quality.exceptedLibraries) is in force. ### Method CLI ### Endpoint `python3 scripts/c7.py whoami` ### Parameters None. The command performs three read-only API calls (`GET /v2/teamspaces`, `GET /v2/usage`, `GET /v2/policies`) and prints one JSON object to stdout. ### Response #### Success Response (exit code 0) - **teamspaces** (array) - Per teamspace `{name, role, ownerPlan}`; the raw response if `GET /v2/teamspaces` failed - **plan** (string | null) - Plan name from `GET /v2/usage`; `null` if that call failed - **policyMode** (string | null) - `"select"`, `"quality"`, or `null` (no filter) - **allowList** (string | null) - `"select.allowedLibraries"` or `"quality.exceptedLibraries"` when a filter is active, else `null` - **allowListEntries** (integer) - Size of that list (`0` when no filter) - **accessibleLibraryCount** (integer) - From the policy, how many public libraries the teamspace can reach - **sourceTypes** (object) - `{type: bool}` — whether each source type (e.g. `website`, `github`) is enabled by the policy ### Exit Codes | Code | Condition | |---|---| | 0 | Report produced (fields may still show `null` on partial API failures) | | 3 | No API key found, or `GET /v2/policies` answered 401 | | 1 | `GET /v2/policies` failed with a status that maps to `EXIT_API` | | 4 / 5 / 7 / 6 | `GET /v2/policies` answered 404 / 403 `access_denied` / 422 / 429 (mapped by `http_exit_code`) | ### Request Example ```bash python3 skills/context7-add/scripts/c7.py whoami ``` ### Response Example ```json { "teamspaces": [{"name": "acme", "role": "admin", "ownerPlan": "team"}], "plan": "team", "policyMode": "select", "allowList": "select.allowedLibraries", "allowListEntries": 42, "accessibleLibraryCount": 5123, "sourceTypes": {"website": true, "github": true, "gitlab": true} } ``` ``` -------------------------------- ### Wait for a freshly submitted library Source: https://github.com/saalse/context7-add Run the add command with --apply, then wait for the library to become ready. The wait command polls until a terminal state; a fresh submit answers processing_or_empty until parsing finishes, which is not terminal. ```bash python3 skills/context7-add/scripts/c7.py add https://github.com/acme/widgets --apply python3 skills/context7-add/scripts/c7.py wait /acme/widgets # minutes ```