8000 feat(tools): add web_fetch to read public pages and APIs by geminixiang · Pull Request #176 · geminixiang/mikan · GitHub
[go: up one dir, main page]

Skip to content

feat(tools): add web_fetch to read public pages and APIs - #176

Merged
geminixiang merged 2 commits into
mainfrom
feat/web-fetch
Oct 11, 2026
Merged

geminixiang merged 2 commits into
mainfrom
feat/web-fetch

Conversation

@geminixiang
@geminixiang geminixiang commented Oct 11, 2026 •
Copy link
Copy Markdown
Owner

Why

Asked for current facts (package and language versions, a release, today's weather, this week's news), the agent answered from memory or from stale search snippets. jev_browser timed out or failed on most official pages.

What

web_fetch reads a public web page or API from the host:

  • HTML becomes Markdown through @mdream/js (minimal preset, which drops navigation and page chrome); JSON and plain text are returned as they are.
  • The result goes through guardMcpToolResult, so a long page is bounded and the full text is saved in the workspace for read/grep, like an MCP result.
  • Its own undici Agent refuses private, loopback, and link-local addresses (Node BlockList) before connecting: IP literals in the connector, names in the connect lookup. Redirects and DNS answers go through the same check.
  • It needs no key. New dependency: @mdream/js (MIT, 0.6 MB installed, 2 dependencies).

@mdream/js was chosen after converting seven real pages with html-to-text, turndown, node-html-markdown, and Readability with Turndown: it kept the answer on every page with the smallest output. Readability dropped a version table; node-html-markdown took 29 s on a 3 MB page.

Pi's web tools are coding-agent extensions that pi-durable cannot load, so this is a mikan tool (ADR 0023).

Acceptance eval

Scripted model and faked network, main vs this branch:

Case main This branch
Read a page no web_fetch tool URL, title, and text with links; scripts and navigation removed
127.0.0.1:8080, 169.254.169.254, localhost, [::1], file:// no tool all refused, no request sent
Public URL redirecting to a non-public address no tool refused before connecting (unit test with real local servers)
Long page no tool bounded result plus the path of the full text in the workspace
JSON no tool returned as it is
HTTP 404 no tool error with status
Request size 34,895 chars, 16 tools 35,801 chars, 17 tools (+906)

Real model, same 10 questions, run through the conversation runtime without a chat platform, graded against the official sources:

Setup Correct Confidently wrong Mean seconds
main 2 1 33
Brave Search MCP 7 2 25
This branch 10 0 7

Trade-offs

  • The tool's Agent bypasses the daemon's EnvHttpProxyAgent, because a proxy would resolve names itself and defeat the address check. A deployment that reaches the web only through a proxy cannot use web_fetch.
  • Sites see the host's public IP.

Verification

  • npm run lint && npm run fmt:check && npm run knip && npm run build && npm run typecheck && npm test: 2,101 passed.
  • New src/test/web-fetch-tool.test.ts (27 tests, real local HTTP servers on 127.0.0.1 and [::1]).
  • This changes the tools a Slack run offers, so the Slack E2E workflow should run before merge.

The agent answered current-fact questions from memory or stale search snippets, and jev_browser timed out on most official pages. web_fetch reads a public URL from the host and returns its text in 12,000-character windows. It refuses private, loopback, and link-local targets on every redirect hop and again at connect time. See ADR 0023.
…d the MCP result guard

Replace the hand-written HTML conversion, address classification, redirect loop, and windowing with @mdream/js, Node's BlockList, undici's redirects and connect lookup, and the existing bound-and-spill guard for MCP results.
@cloudflare-workers-and-pages
cloudflare-workers-and-pages Bot commented Oct 11, 2026 •
Copy link
Copy Markdown

Deploying mikan with  Cloudflare Pages  Cloudflare Pages

Latest commit: b265f8c
Status: ✅  Deploy successful!
Preview URL: https://8ef45ee3.mikan-1wv.pages.dev
Branch Preview URL: https://feat-web-fetch.mikan-1wv.pages.dev

View logs

@geminixiang
geminixiang merged commit 76d0eec into main Oct 11, 2026
7 checks passed
@geminixiang
geminixiang deleted the feat/web-fetch branch October 11, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0