Skip to content

Commit 8e3b117

Browse files
gildesmaraisclaude
andauthored
docs: add Ruby API reference, MCP details and network safeguards (#1308)
* docs: add Ruby API reference, MCP details and network safeguards Add a Ruby API reference page with error handling, an apply example, MCP response cache and validation issue shapes, and a network safeguards section with troubleshooting entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: align Ruby API strategy list and network guard wording Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: scope network guard wording per strategy Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 16aa699 commit 8e3b117

7 files changed

Lines changed: 329 additions & 13 deletions

File tree

‎src/content/docs/ruby-gem/guides/capturing-feed-configs.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ See the [CLI reference](/ruby-gem/reference/cli-reference/#capture) for the full
5454

5555
## Ruby API
5656

57+
All options and result types: [Ruby API Reference](/ruby-gem/reference/ruby-api/).
58+
5759
<Code
5860
code={`
5961
require 'html2rss'

‎src/content/docs/ruby-gem/guides/managing-feed-configs.mdx‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,29 @@ For URL-only auto discovery, `Html2rss.scrape(url)` returns the same `FeedResult
100100

101101
Depth and method contracts: [YARD for `html2rss`](https://www.rubydoc.info/gems/html2rss).
102102

103+
### Ruby API: apply
104+
105+
Use `Html2rss.apply` to ship a feed. It builds the feed once and returns an `Html2rss::Apply::Result`. Unlike `Html2rss.feed`, it also exposes `empty?`, `item_count` and a `quality_report`.
106+
107+
<Code
108+
code={`
109+
require 'html2rss'
110+
config = Html2rss.config_from_yaml_file('feeds.yml', 'my-first-feed')
111+
result = Html2rss.apply(config)
112+
# apply returns an empty result instead of raising, so check it
113+
abort 'feed has no items' if result.empty?
114+
File.write('my-first-feed.xml', result.to_rss.to_s)
115+
result.item_count
116+
# => 12
117+
result.to_json_feed(feed_url: 'https://example.com/feeds/my-first-feed.json')
118+
result.quality_report.warnings
119+
# => []
120+
`}
121+
lang="ruby"
122+
/>
123+
124+
The CLI exits 1 on an empty feed and the MCP tool returns `isError`; the Ruby method leaves that decision to you. Full method list: [Ruby API Reference](/ruby-gem/reference/ruby-api/#apply).
125+
103126
### Command Line
104127

105128
<Code

‎src/content/docs/ruby-gem/index.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ If you are getting started with `html2rss`, we recommend starting with the [**fi
2424

2525
- **[Tutorials](/ruby-gem/tutorials/your-first-feed/)**: Step-by-step guides to help you get started with `html2rss`.
2626
- **[Guides](/ruby-gem/guides/)**: Practical examples and solutions for common tasks, including [capturing feed configs](/ruby-gem/guides/capturing-feed-configs/) and [AI agent workflows](/ruby-gem/guides/ai-agent-workflows/).
27-
- **[Reference](/ruby-gem/reference/)**: Detailed information on configuration options, CLI commands, and the [MCP server](/ruby-gem/reference/mcp-server/).
27+
- **[Reference](/ruby-gem/reference/)**: Detailed information on configuration options, CLI commands, the [Ruby API](/ruby-gem/reference/ruby-api/), and the [MCP server](/ruby-gem/reference/mcp-server/).

‎src/content/docs/ruby-gem/reference/mcp-server.mdx‎

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Daemon logs go to **stderr** (stdout is JSON-RPC). Default `LOG_LEVEL` for the M
3030

3131
`scrape` and `capture` use `strategy: "auto"` by default so html2rss can choose an available fetch path from the scrape result. Prefer native RSS/Atom when present; weak homepage URLs may be rewritten via entry resolution.
3232

33-
Keep `auto` for normal use. Pin `strategy: "botasaurus"` only when a diagnostic requires browser rendering or browser-specific controls.
33+
The published `strategy` values are `auto`, `default`, `httpx` and `botasaurus`. Keep `auto` for normal use. For `inspect` and `recon`, `auto` stays on the cheap default fetch; pin `botasaurus` when you need browser rendering there. Pin `strategy: "botasaurus"` only when a diagnostic requires browser rendering or browser-specific controls.
3434

3535
Read `html2rss://runtime` for `botasaurus_configured` (boolean only). Set `BOTASAURUS_SCRAPER_URL` on the **MCP process** env.
3636

@@ -52,6 +52,8 @@ Every tool returns one JSON object in text content and `structuredContent`:
5252

5353
`isError` matches `ok: false`. Articles live in `payload.items`; YAML in `payload.yaml`; RSS in `payload.rss`.
5454

55+
When a result was built from cached pages, the envelope also carries `cache: { hits, max_age_seconds }`. See [Response cache](#response-cache).
56+
5557
`next_step` is one of: `done`, `inspect`, `recon`, `validate`, `apply`, `scrape`, `capture`, `read_runtime`, `test`.
5658

5759
## Tools (7 bare verbs + batch trio)
@@ -83,28 +85,33 @@ Curation verdict and `native_feed` preference (`BUILD` / `DEFER` / `DROP`).
8385

8486
Derive a reusable YAML draft (`payload.yaml`). Same serializer as CLI `html2rss capture`. Catalog feeds still need `directory.topics` and explicit channel `title` / `url`.
8587

86-
- **Parameters:** `url` (required); `strategy`; optional `items_selector`
88+
- **Parameters:** `url` (required); `strategy`; `items_selector`; `force` (skip native feed detection); `topics` (array of directory topics); `title`; `summary`; `enhance` (force on or off); `limit`; `max_redirects`; `max_requests`
8789
- Typical `next_step`: `test` or `inspect`
8890

8991
### `validate`
9092

9193
Schema-only check against `html2rss://schema`. Exactly one of `config` or `yaml`.
9294

9395
- Success `next_step` is usually `test`
96+
- Failure returns `isError` with `payload.issues`, an array of `{ path, code, message, expected, actual }`. `path` is an array of keys. `code` is one of `missing_key`, `type_mismatch`, `unknown_value`, `invalid_value`, `constraint`, `parse`.
9497

9598
### `test`
9699

97-
Schema validation plus live extraction (`min_items`, optional `strict_quality`, `compare_enhance`).
100+
Schema validation plus live extraction.
98101

102+
- **Parameters:** exactly one of `config` or `yaml`; `min_items` (default `1`); `strict_quality` (default `false`); `compare_enhance` (default `false`); `strategy`
99103
- Success `next_step` is `apply`
100-
- Payload includes sample items, timing, and `quality_report` when present
104+
- A schema failure returns the same issue shape as `validate`, under `payload.validation_issues`, and `next_step` is `validate`. Any other failure points back to `capture`
105+
- Payload includes `sample_items`, `items`, timing, `failure_kind` and `quality_report` when present
106+
- The MCP tool does not expose the Ruby `sample_limit` option; it uses the default of 3
101107

102108
### `apply`
103109

104110
Ship gate: build RSS from a config. Required `url` plus exactly one of `config` or `yaml`.
105111

106-
- **Payload:** `rss`, `item_count`
107-
- `isError` when zero items
112+
- **Payload:** `rss`, `item_count`, `quality_report`
113+
- `isError` when zero items; `next_step` is then `inspect`
114+
- A missing `channel.url` is filled from `url`
108115

109116
### Batch trio
110117

@@ -114,14 +121,16 @@ Ship gate: build RSS from a config. Required `url` plus exactly one of `config`
114121
| `batch_inspect` | Parallel inspect |
115122
| `batch_recon` | Parallel recon |
116123

124+
All three take `urls` (1 to 25), `strategy` and `concurrency` (worker threads, `1..10`, default `5`). `batch_scrape` also takes `limit` (default `10` per URL).
125+
117126
## Resources
118127

119-
| URI | Description |
120-
| ----------------------- | ------------------------------------------------------------------------------------------------------------------ |
121-
| `html2rss://schema` | Feed config JSON Schema |
122-
| `html2rss://extractors` | Extractor names |
123-
| `html2rss://strategies` | Runtime strategy names for client discovery; prefer `auto`, `default`, or `botasaurus` |
124-
| `html2rss://runtime` | `version`, `mcp_contract_version`, `catalog_fingerprint`, `tools`, `botasaurus_configured` — never the scraper URL |
128+
| URI | Description |
129+
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
130+
| `html2rss://schema` | Feed config JSON Schema |
131+
| `html2rss://extractors` | Extractor names |
132+
| `html2rss://strategies` | Published strategy names: `auto`, `default`, `httpx`, `botasaurus`; prefer `auto` |
133+
| `html2rss://runtime` | `version`, `mcp_contract_version` (currently `4`), `catalog_fingerprint`, `tools`, `botasaurus_configured`, `response_cache_ttl` (`null` when off) — never the scraper URL |
125134

126135
`validate` / `apply` reject `strategy: local_file` and `request.local_file_path`. Use CLI `--input` for fixtures.
127136

@@ -132,6 +141,17 @@ Ship gate: build RSS from a config. Required `url` plus exactly one of `config`
132141
| `scrape-webpage` | One `scrape` call; `inspect` only if weak |
133142
| `capture-feed-config` | `capture` → `test` → `apply` (catalog rewrite when targeting html2rss-configs) |
134143

144+
## Response cache
145+
146+
The MCP process is long-lived, so an agent that runs `inspect`, `capture`, `validate` and `test` on one URL should not refetch it. The server caches initial page fetches in memory.
147+
148+
- **On by default, 300 seconds.** Set `HTML2RSS_RESPONSE_CACHE_TTL=<seconds>` on the MCP process to change it.
149+
- **Disable it** with `0`, `off` or `false`. An unusable value logs a warning and falls back to 300.
150+
- Only initial 2xx fetches are cached. Follow-up requests and block pages always hit the network.
151+
- Memory is bounded to 32 entries and 32 MiB of bodies; the oldest entry goes first.
152+
- To force a refetch, wait out the TTL or restart with the cache off.
153+
- The cache is an MCP server setting. The Ruby library and the CLI do not cache by default.
154+
135155
## Client setup
136156

137157
See [AI Agent Workflows](/ruby-gem/guides/ai-agent-workflows/) for Cursor / Claude Desktop `mcp.json` examples and the `html2rss-config` skill.

0 commit comments

Comments
 (0)