MCP on Cloudflare Workers
MCP (Model Context Protocol) is how AI agents discover and call external tools. If your Cloudflare Worker already has service functions, adding MCP support takes one file. I did it for two projects. Both came in under 70 lines.
The key insight: MCP tools just call the same service functions your API routes already use. No new business logic. The MCP layer is pure protocol translation.
The pattern
Two packages: @modelcontextprotocol/sdk for the server and
agents/mcp from Cloudflare's agents package for the HTTP
transport handler. Create an McpServer, register tools,
export the handler.
Each tool() call is a name, a description agents read to
decide when to call it, a Zod schema for the inputs, and a handler that
returns content blocks. The handler calls the same service functions your
Hono routes call. Nothing new to write.
Wiring it up
In your Worker's fetch handler, intercept the MCP path
before Hono. Three lines:
That's it. Any MCP-compatible agent can now connect to
https://your-worker.workers.dev/api/mcp and discover your
tools. The rest of your API keeps working exactly as before.
Why bother?
REST endpoints serve browsers. MCP endpoints serve agents. Same data, different consumers. An agent connecting via MCP gets tool descriptions, typed schemas, and a standard protocol for discovery. It doesn't need to parse your API docs or guess at endpoints.
I added MCP to a Berlin transit app (3 tools, 68 lines) and a travel planning app (4 tools, 59 lines). Both took under an hour. Both reuse 100% of their existing service code.
transit MCP source (68 lines)
modelcontextprotocol.io