Give Your AI Agent a Web-Fetch Tool: a 60-Line MCP Server (Free, Self-Hosted)

Every MCP web-access tutorial I read this month pointed at a paid API.

You don’t need one. To let an AI agent read a public web page, sixty lines on the official MCP Python SDK give you a self-hosted web_fetch tool — running on your machine, no key, no per-call bill.

I built it, ran it, and pasted the real terminal output below. The catch isn’t the wiring (that part is easy). It’s the four defaults the tutorials leave out — the ones that turn a toy into something you’d actually point an agent at.

Quick answer: A Model Context Protocol (MCP) server exposes tools an LLM agent can call. With pip install mcp, one @mcp.tool() function, and mcp.run(), you get a working web_fetch(url) -> clean text tool over stdio in ~60 lines. Self-hosted, free, and returning text instead of raw HTML. The work is in the guardrails: timeout, size cap, and an SSRF check.

This is for anyone building agents or RAG who keeps hitting “give your model live web access — here’s our API.” If your target is docs, articles, RSS, or JSON endpoints that answer a plain GET, you don’t have to pay for that.

The artifact first: what the agent actually receives

Here’s the real round-trip (terminal output, reformatted for readability — the raw print() repr is denser). I started the server, connected an MCP client over stdio, asked it to list tools, then called web_fetch on example.com:

=== TOOLS THE AGENT SEES ===
- web_fetch: Fetch a public web page and return clean readable text (no raw HTML).

=== call_tool web_fetch('https://example.com') ===
isError: False
Example Domain Example Domain This domain is for use in documentation examples
without needing permission. Avoid use in operations. Learn more

That’s it. The agent asked for a URL and got back readable prose — not a wall of

soup. No tags, no