|
| 1 | +# API Reference |
| 2 | + |
| 3 | +This document covers the public API surface of Context CLI: the Python API for programmatic use, the MCP tools for AI agent integration, and the CLI commands. |
| 4 | + |
| 5 | +## Python API |
| 6 | + |
| 7 | +### `audit_url(url, **kwargs) -> AuditReport` |
| 8 | + |
| 9 | +Lint a single URL and return an audit report. |
| 10 | + |
| 11 | +```python |
| 12 | +from context_cli.core.auditor import audit_url |
| 13 | + |
| 14 | +report = await audit_url("https://example.com") |
| 15 | +print(report.score) # 0-100 overall score |
| 16 | +print(report.robots) # robots.txt check result |
| 17 | +print(report.schema) # Schema.org check result |
| 18 | +print(report.content) # content density result |
| 19 | +print(report.llms_txt) # llms.txt check result |
| 20 | +``` |
| 21 | + |
| 22 | +**Parameters:** |
| 23 | + |
| 24 | +| Parameter | Type | Default | Description | |
| 25 | +|---|---|---|---| |
| 26 | +| `url` | `str` | (required) | URL to audit | |
| 27 | +| `timeout` | `int` | `15` | HTTP timeout in seconds | |
| 28 | +| `bots` | `list[str]` | `None` | Custom bot list (default: 13 bots) | |
| 29 | +| `scoring` | `str` | `"v2"` | Scoring model (`"v2"` or `"v3"`) | |
| 30 | +| `single` | `bool` | `False` | Skip multi-page discovery | |
| 31 | +| `max_pages` | `int` | `10` | Max pages to lint in multi-page mode | |
| 32 | + |
| 33 | +### `audit_site(url, **kwargs) -> list[AuditReport]` |
| 34 | + |
| 35 | +Lint multiple pages discovered from a URL. |
| 36 | + |
| 37 | +```python |
| 38 | +from context_cli.core.auditor import audit_site |
| 39 | + |
| 40 | +reports = await audit_site("https://example.com", max_pages=5) |
| 41 | +for report in reports: |
| 42 | + print(f"{report.url}: {report.score}") |
| 43 | +``` |
| 44 | + |
| 45 | +### `AuditReport` |
| 46 | + |
| 47 | +The data model returned by audit functions. |
| 48 | + |
| 49 | +```python |
| 50 | +@dataclass |
| 51 | +class AuditReport: |
| 52 | + url: str # audited URL |
| 53 | + score: float # overall 0-100 score |
| 54 | + robots: RobotsResult # robots.txt check |
| 55 | + schema: SchemaResult # Schema.org check |
| 56 | + content: ContentResult # content density check |
| 57 | + llms_txt: LlmsTxtResult # llms.txt check |
| 58 | + agent_readiness: AgentReadinessResult # V3 only |
| 59 | + pillar_scores: dict # per-pillar scores |
| 60 | + recommendations: list[str] # improvement suggestions |
| 61 | +``` |
| 62 | + |
| 63 | +## MCP Tools |
| 64 | + |
| 65 | +The MCP server exposes these tools via FastMCP. Start with `context-cli mcp`. |
| 66 | + |
| 67 | +### `audit` |
| 68 | + |
| 69 | +Run a full LLM readiness audit on a URL. |
| 70 | + |
| 71 | +**Input:** `{ "url": "https://example.com" }` |
| 72 | + |
| 73 | +**Output:** Full audit report with score, pillar breakdown, and recommendations. |
| 74 | + |
| 75 | +### `agent_readiness_audit` |
| 76 | + |
| 77 | +Run agent readiness checks against a URL (V3 scoring). |
| 78 | + |
| 79 | +**Input:** `{ "url": "https://example.com" }` |
| 80 | + |
| 81 | +**Output:** Agent readiness sub-check results (AGENTS.md, Accept: text/markdown, MCP endpoint, semantic HTML, x402, NLWeb). |
| 82 | + |
| 83 | +### `convert_to_markdown` |
| 84 | + |
| 85 | +Convert a URL's HTML to clean, token-efficient markdown. |
| 86 | + |
| 87 | +**Input:** `{ "url": "https://example.com" }` |
| 88 | + |
| 89 | +**Output:** Converted markdown content with optional token reduction statistics. |
| 90 | + |
| 91 | +### `generate_agents_md` |
| 92 | + |
| 93 | +Generate an AGENTS.md file for a URL based on its content and structure. |
| 94 | + |
| 95 | +**Input:** `{ "url": "https://example.com" }` |
| 96 | + |
| 97 | +**Output:** Generated AGENTS.md content. |
| 98 | + |
| 99 | +### `generate` |
| 100 | + |
| 101 | +Generate llms.txt and schema.jsonld files from a URL using LLM analysis. |
| 102 | + |
| 103 | +**Input:** `{ "url": "https://example.com" }` |
| 104 | + |
| 105 | +**Output:** Generated file contents. |
| 106 | + |
| 107 | +### `compare` |
| 108 | + |
| 109 | +Compare audit results between two URLs or two points in time. |
| 110 | + |
| 111 | +**Input:** `{ "url1": "https://a.com", "url2": "https://b.com" }` |
| 112 | + |
| 113 | +**Output:** Side-by-side comparison of scores and pillar breakdowns. |
| 114 | + |
| 115 | +### `history` |
| 116 | + |
| 117 | +Retrieve audit history for a URL. |
| 118 | + |
| 119 | +**Input:** `{ "url": "https://example.com" }` |
| 120 | + |
| 121 | +**Output:** Historical audit results with score trends. |
| 122 | + |
| 123 | +### `recommend` |
| 124 | + |
| 125 | +Get actionable recommendations for improving a URL's LLM readiness. |
| 126 | + |
| 127 | +**Input:** `{ "url": "https://example.com" }` |
| 128 | + |
| 129 | +**Output:** Prioritized list of improvements with expected score impact. |
| 130 | + |
| 131 | +## CLI Commands |
| 132 | + |
| 133 | +### Core Commands |
| 134 | + |
| 135 | +| Command | Description | |
| 136 | +|---|---| |
| 137 | +| `context-cli lint <url>` | Lint a URL for LLM readiness | |
| 138 | +| `context-cli markdown <url>` | Convert a URL to markdown | |
| 139 | +| `context-cli serve` | Start the reverse proxy server | |
| 140 | +| `context-cli mcp` | Start the MCP server | |
| 141 | + |
| 142 | +### Generate Commands |
| 143 | + |
| 144 | +| Command | Description | |
| 145 | +|---|---| |
| 146 | +| `context-cli generate <url>` | Generate llms.txt and schema.jsonld | |
| 147 | +| `context-cli generate-batch <file>` | Batch generate for multiple URLs | |
| 148 | +| `context-cli generate-config <server>` | Generate web server config | |
| 149 | +| `context-cli generate-x402` | Generate x402 payment config | |
| 150 | + |
| 151 | +### Analysis Commands |
| 152 | + |
| 153 | +| Command | Description | |
| 154 | +|---|---| |
| 155 | +| `context-cli radar <prompt>` | Query AI models for citations | |
| 156 | +| `context-cli benchmark <file>` | Run share-of-recommendation benchmark | |
| 157 | +| `context-cli compare <url1> <url2>` | Compare two URLs | |
| 158 | +| `context-cli history <url>` | View audit history | |
| 159 | + |
| 160 | +### Common Flags |
| 161 | + |
| 162 | +| Flag | Applies to | Description | |
| 163 | +|---|---|---| |
| 164 | +| `--single` | `lint` | Skip multi-page discovery | |
| 165 | +| `--json` | all | Output as JSON | |
| 166 | +| `--format` | `lint` | Output format (`csv`, `markdown`) | |
| 167 | +| `--verbose` | `lint` | Detailed per-pillar breakdown | |
| 168 | +| `--quiet` | `lint` | Suppress output, exit code only | |
| 169 | +| `--timeout` | `lint`, `markdown` | HTTP timeout in seconds | |
| 170 | +| `--fail-under` | `lint` | Minimum score threshold for CI | |
| 171 | +| `--fail-on-blocked-bots` | `lint` | Fail if AI bots are blocked | |
| 172 | +| `--scoring` | `lint` | Scoring model (`v2`, `v3`) | |
| 173 | +| `--file` | `lint` | Batch lint from file | |
| 174 | +| `--concurrency` | `lint`, `generate-batch` | Parallel workers | |
0 commit comments