#15414: feat(web-fetch): add Accept: text/markdown header for Cloudflare Markdown for Agents
agents
stale
size: XS
## Summary
Adds `Accept: text/markdown, text/html;q=0.9, */*;q=0.8` to `web_fetch` HTTP requests, enabling [Cloudflare Markdown for Agents](https://blog.cloudflare.com/markdown-for-agents/) support.
When a server returns `Content-Type: text/markdown`, the body is used directly (extractor: `markdown-native`) — skipping HTML extraction entirely. This can reduce token consumption by ~80% on supporting sites.
**Fully backward-compatible:** non-supporting sites return `text/html` as usual and hit the existing Readability/Firecrawl pipeline.
## Changes
- `src/agents/tools/web-fetch.ts`: Updated `Accept` header + added `text/markdown` content-type handling
## Testing
- TypeScript compiles clean (`tsc --noEmit`)
- All 11 existing web-fetch tests pass
- Linter (oxlint) + formatter (oxfmt) clean
Closes #15393
🤖 AI-assisted (Claude Opus 4)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This change updates `web_fetch` to send an `Accept: text/markdown, text/html;q=0.9, */*;q=0.8` header and adds a fast-path for `Content-Type: text/markdown` responses (marking them as `extractor="markdown-native"` and skipping the HTML Readability/Firecrawl extraction pipeline).
Overall this fits cleanly into the existing fetch/extract flow, but there are a couple of behavioral inconsistencies to fix so `extractMode` remains the primary contract and content-type detection is robust.
<h3>Confidence Score: 3/5</h3>
- Mostly safe to merge after fixing output-format consistency for markdown responses.
- The PR is small and well-scoped, but currently changes `web_fetch` semantics in a way that can surprise callers: `extractMode: "text"` can return markdown when a server replies `text/markdown`, and Content-Type detection is case-sensitive. Both are straightforward to address.
- src/agents/tools/web-fetch.ts
<sub>Last reviewed commit: 8de4bb6</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#15251: feat(web-fetch): send Accept: text/markdown header for Cloudflare M...
by wujieli0207 · 2026-02-13
95.1%
#15242: feat(web-fetch): Add Accept header for Cloudflare Markdown for Agen...
by drkraft · 2026-02-13
88.9%
#16590: fix(web-fetch): use bot UA for markdown to enable Cloudflare LLM co...
by Imccccc · 2026-02-14
84.7%
#15530: docs(web_fetch): document markdown-first Accept header and cf-markd...
by novavale · 2026-02-13
83.6%
#20423: fix(web-fetch): cap htmlToMarkdown input size to prevent catastroph...
by Limitless2023 · 2026-02-18
75.4%
#12794: fix: catch firecrawl fallback errors in web_fetch to prevent unhand...
by zerone0x · 2026-02-09
71.6%
#22644: feat(web-fetch): add allowPrivateNetwork config for web_fetch
by qingxuecc · 2026-02-21
71.0%
#14940: fix(googlechat): convert Markdown formatting to Google Chat markup
by brandonwise · 2026-02-12
70.6%
#23329: feat: Add Markdown support for cron job payload
by HeXavi8 · 2026-02-22
70.6%
#3921: fix: sanitize fetch headers to prevent ByteString crash on Unicode ...
by nexiouscaliver · 2026-01-29
70.4%