Skip to main content

CLI tool to convert Context7 llms.txt format to locally organized markdown documentation

Project description

Context7 to Markdown (c2md)

A blazing fast CLI tool that converts Context7 formatted llms.txt files to organized markdown documentation with automatic directory structure, multi-language support, and table of contents generation.

Only caveat is Context7 does not have an open API at the moment, so you must download the raw llms.txt and you MUST add or specify the tokens query to be >= the total number of tokens.

For example, context7.com/context7/neon/llms.txt?tokens=519821.

Install with pip

pip install c2md

Install with uv

uv pip install c2md
uvx c2md

โœจ Features

  • โš“ Convert Context7 to Markdown: Transform Context7 format files into clean, organized markdown documentation
  • ๐Ÿง  Smart Organization: Automatically organizes files into logical directory structures based on source URLs.
  • ๐Ÿ—จ๏ธ Multi-Language Support: Consolidates multi-language sections into a single document.
  • ๐Ÿ“œ Table of Contents: Generates comprehensive index files to provide context to your agent.
  • ๐Ÿ—บ๏ธ URL Mapping: Intelligently maps source URLs to appropriate file paths and names
  • โŒ Error Handling: Robust error handling with detailed feedback for troubleshooting

๐Ÿค” Why c2md?

MCP is clunky, slow, adds additional prompt context, and time consuming.

With c2md, you can pass a specific section of a technology's documentation to an agent. Instead of fairly unreliable natural language search with the Context7 MCP server, you can just attach the @/path/to/000-index.md to your agent.

Depending on the number of locally available documentation sections/files, this can save tokens/context. For example, the Neon docs have around 240 sections (520,000 tokens), with the total 000-index.md costing around 4,000 tokens; alternatively, calls to the Context7 MCP can cost anywhere from 8,000 to 20,000 tokens.

๐Ÿš€ Installation

Using pip

pip install c2md

Using uv

uv pip install c2md

or

uvx c2md

Development Installation

# Clone the repository
git clone https://github.com/crisp-sh/context7-to-markdown.git
cd context7-to-markdown

# Install in development mode
pip install -e .

๐Ÿ“‹ Requirements

  • Python 3.8 or higher
  • No external dependencies required

๐Ÿ› ๏ธ Usage

After installation, use the c2md command:

Basic Usage

# output defaults to ./output/
c2md /path/to/llms.txt

Advanced Usage

# Specify output directory, 001-index.md (ToC) generated in output root
c2md /path/to/llms.txt -d /path/to/output

# Disable ToC generation
c2md /path/to/llms.txt --no-tree

# Full example with all options, no ToC/tree
c2md /path/to/llms.txt -d /path/to/output --no-tree

Command Line Options

  • input_file: Path to the Context7 format input file (required)
  • -d, --directory: Output directory (default: current directory)
  • -T, --tree: Generate table of contents index (default: enabled)
  • --no-tree: Disable table of contents generation
  • -h, --help: Show help message and exit

๐Ÿ“ Output Structure

The tool creates an organized directory structure:

output/
โ”œโ”€โ”€ 001-index.md                    # Table of contents (if enabled)
โ”œโ”€โ”€ domain1.com/
โ”‚   โ”œโ”€โ”€ section1/
โ”‚   โ”‚   โ”œโ”€โ”€ 001-page1.md
โ”‚   โ”‚   โ””โ”€โ”€ 002-page2.md
โ”‚   โ””โ”€โ”€ section2/
โ”‚       โ””โ”€โ”€ 001-page3.md
โ””โ”€โ”€ domain2.com/
    โ””โ”€โ”€ docs/
        โ””โ”€โ”€ 001-guide.md

๐ŸŽฏ Context7 Format

The tool processes Context7 format files, which should contain entries with:

  • SOURCE: URL or source identifier
  • CONTENT: The actual content to be converted
  • TITLE: Optional title for the content
  • LANGUAGE: Denotes a multi-language document

๐Ÿ—๏ธ Architecture

The tool consists of several modular components:

  • Parser: Processes Context7 format files
  • URL Mapper: Maps source URLs to file paths
  • File Organizer: Organizes content into directory structures
  • Markdown Writer: Generates clean markdown files
  • Index Generator: Creates table of contents

๐Ÿงช Testing

Run the test suite using Hatch:

# Run tests
hatch run test

# Run tests with coverage
hatch run test-cov

# Run specific test file
hatch run test tests/test_specific.py

Legacy Testing

# Install development dependencies
pip install -e ".[dev]"

# Run tests
python -m unittest discover tests

# Run tests with coverage
python -m unittest discover tests

๐Ÿ”„ Releasing

This project uses automated versioned releases with Hatch for version management.

Quick Release

# Create a patch release (0.1.0 โ†’ 0.1.1)
hatch run release patch

# Create a minor release (0.1.0 โ†’ 0.2.0)
hatch run release minor

# Create a major release (0.1.0 โ†’ 1.0.0)
hatch run release major

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a PR if you would like to contribute or have an issue.

Development Setup

# Clone the repository
git clone https://github.com/crisp-sh/context7-to-markdown.git
cd context7-to-markdown

# Create a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install
pip install -e .

Running Tests

# Run all tests with Hatch
hatch run test

# Run specific test file
hatch run test tests/test_specific.py

# Run tests with coverage
hatch run test-cov

๐Ÿ› Bug Reports

If you encounter any issues, please report them on the GitHub Issues page.

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

c2md-0.2.0.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

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

c2md-0.2.0-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file c2md-0.2.0.tar.gz.

File metadata

  • Download URL: c2md-0.2.0.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for c2md-0.2.0.tar.gz
Algorithm Hash digest
SHA256 595a353e63ac3dfc5fdd48b7d62917c4a61cffc0be3fe400fd8e20a8d1707517
MD5 8562360082de9f2a6523f59d4429e5c9
BLAKE2b-256 6ce0752cb4eb1167dc8102703d44b891861e8b0a2c7bf945049518e43abc823d

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2md-0.2.0.tar.gz:

Publisher: release.yml on crisp-sh/context7-to-markdown

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file c2md-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: c2md-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for c2md-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f055ca81d29c44c76a7505e6b354a71755256dd3b5d8f14ec00d9a17cede4f39
MD5 030a1775579c251f45889f76e32ad722
BLAKE2b-256 782c9516c57e52a5b8f0ffedc0bf9b48133e827e801ac2a9cfd1030ca1c58e42

See more details on using hashes here.

Provenance

The following attestation bundles were made for c2md-0.2.0-py3-none-any.whl:

Publisher: release.yml on crisp-sh/context7-to-markdown

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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