Skip to main content

Scrape framework/package documentation and generate an AGENTS.md knowledge file.

Project description

kgrab logo

Scrape any framework's documentation and generate an AGENTS.md knowledge file for AI agents.

PyPI GitHub Stars License


What is kgrab?

kgrab crawls the full documentation of any framework or package and generates a structured AGENTS.md file — a knowledge base that makes AI agents aware of all the features, APIs, and patterns of a library.

It works as a CLI tool, a pip package, and an MCP server (Model Context Protocol) so AI assistants like Claude, Gemini, or Cursor can call it as a tool.


Quick Start

pip install kgrab

CLI usage

# Scrape docs and generate AGENTS.md (default max 500 pages)
doc-scrape https://docs.agno.com/introduction

# Compact mode (70% smaller output)
doc-scrape https://docs.agno.com/introduction --compact

# Full scrape (ignores the 500 max pages limit)
doc-scrape https://docs.agno.com/introduction --full

# Scrape an SPA (Single Page Application) using Cloudflare Browser Rendering
export CF_ACCOUNT_ID="your_account_id"
export CF_API_TOKEN="your_api_token"
doc-scrape https://python.langchain.com/docs/introduction/ --compact --cloudflare

MCP server usage

Add to your MCP client config (Claude Desktop, Gemini CLI, Cursor, etc.):

{
  "mcpServers": {
    "kgrab": {
      "command": "doc-scrape-mcp",
      "env": {
        "CF_ACCOUNT_ID": "optional_cloudflare_account_id",
        "CF_API_TOKEN": "optional_cloudflare_api_token"
      }
    }
  }
}

The MCP server exposes two tools: scrape_documentation and scrape_documentation_to_text. Both accept Cloudflare credentials optionally to scrape JS-heavy websites.


CLI Options

Flag Default Description
url (required) Entry-point URL of the documentation
-o / --output AGENTS.md Output file path
-n / --name auto-detect Human-friendly package name
--max-pages 500 Maximum pages to scrape
--full off Scrape all reachable pages (ignores --max-pages)
--delay 0.25 Seconds between HTTP requests (local scraper only)
-c / --compact off Compress output: truncate prose, cap code, remove thin pages
--cloudflare off Explicitly enable Cloudflare Browser Rendering API
--cf-account $CF_ACCOUNT_ID Cloudflare Account ID for SPA crawling
--cf-token $CF_API_TOKEN Cloudflare API Token for SPA crawling
-v / --verbose off Enable debug logging

Compact Mode

Large documentation sites can produce huge AGENTS.md files (200K+ tokens). Use --compact to aggressively reduce size:

What it does Effect
Removes thin/empty pages Drops index and redirect pages
Deduplicates by title Keeps first occurrence only
Strips boilerplate Removes copyright, "Was this helpful?" etc.
Truncates prose 2 sentences per section
Caps code blocks 10 lines max, first block per section only
Cleans titles Strips redundant site-name suffixes

Example: Agno docs (500 pages) goes from ~247K tokens → ~75K tokens (70% reduction).


Cloudflare SPA Crawling

By default, kgrab uses standard HTTP requests to fetch pages. This is extremely fast but fails on Pure Single Page Apps (SPAs) like React-heavy sites (e.g., Langchain's python docs) that require JavaScript execution to render content.

To solve this, kgrab seamlessly integrates with the Cloudflare Browser Rendering Crawl API.

If you provide the --cloudflare flag (and have set --cf-account/--cf-token or the corresponding CF_ACCOUNT_ID/CF_API_TOKEN environment variables), kgrab will automatically:

  1. Dispatch an asynchronous headless browser crawl job to Cloudflare.
  2. Cloudflare will recursively evaluate JavaScript, follow links, and scrape content.
  3. kgrab polls the job and fetches the rendered Markdown once complete.

This guarantees perfect compatibility with all modern documentation frameworks, including SPAs.


Tested Frameworks & Layouts

kgrab handles HTML layouts generated by diverse tooling (Docusaurus, VitePress, Sphinx, custom, etc.). Here is a smoke test across 10 sites using --compact:

Framework Pages* Sections Est. Tokens Size Status
FastAPI 15 327 ~2.4k 9.4 KB
Flask 15 115 ~14.8k 57.9 KB
React 15 207 ~13.8k 54.2 KB
Vue.js 15 160 ~15.4k 60.4 KB
Next.js 15 53 ~3.2k 12.5 KB
Pydantic 15 283 ~17.3k 67.8 KB
Tailwind 15 159 ~7.0k 27.7 KB
Stripe 15 168 ~11.6k 45.5 KB
Hono 15 116 ~7.4k 29.0 KB

* Capped at 15 pages for testing speed. Run with --full to scrape all pages.


How It Works

  1. Crawl — starting from the given URL, kgrab follows internal navigation links (sidebar, next/prev, etc.) and collects all reachable documentation pages under the same domain scope.
  2. Extract — for each page it extracts headings, body text, and code examples while discarding chrome (nav, footer, scripts).
  3. Generate — the collected content is assembled into a structured AGENTS.md with a table of contents, per-page sections, and inline code blocks.

Development

git clone https://github.com/Bonhollow/kgrab.git
cd kgrab
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest -v

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kgrab-0.1.4.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kgrab-0.1.4-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file kgrab-0.1.4.tar.gz.

File metadata

  • Download URL: kgrab-0.1.4.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for kgrab-0.1.4.tar.gz
Algorithm Hash digest
SHA256 5d8b6fc3a1b7c29dc8d39f8547c0386da9eeda500e0b6e18086a2823c71468d2
MD5 7cbb0ed634423eec816a8f41e4c4ff99
BLAKE2b-256 e1060e024e62249ceb6337c098381e392255dc45c9ecb326b525ac86336395a8

See more details on using hashes here.

File details

Details for the file kgrab-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: kgrab-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for kgrab-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8a25051333ae6f3fb932b59d7d9fc5e9a5f1e255b94d01f57e357342034cba0c
MD5 ce37c10cdfef5ed8777adc336f49960b
BLAKE2b-256 21784a4ea553dc791354830701076b292a1cae05a44fee1bcfd787a2f60fbd23

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page