Demonstrates how to deploy an MCP server on Cloudflare Workers edge network, wrapping REST API endpoints as MCP tools for globally distributed access with low latency.
Uses Hono as the routing framework to serve both REST API endpoints and MCP protocol handlers within a single Cloudflare Worker application.
CF-MCP: REST API + MCP Server on Cloudflare Workers
A single Cloudflare Worker that serves both a REST API and an MCP (Model Context Protocol) interface.
Architecture
Features
REST API Endpoints
GET /api/products- List all products (with filtering)GET /api/products/:id- Get a single productPOST /api/products- Create a new productPUT /api/products/:id- Update a productDELETE /api/products/:id- Delete a product
MCP Tools
The MCP endpoint wraps all REST operations as tools:
list_products- Query products with filtersget_product- Retrieve product detailscreate_product- Add new productsupdate_product- Modify existing productsdelete_product- Remove products
Getting Started
Install Dependencies
Run Locally
The server will start at http://localhost:8787
Test REST API
Test MCP Endpoint
Deploy to Cloudflare
After deployment, your API will be available globally on Cloudflare's edge network!
Key Patterns Demonstrated
1. REST-to-MCP Translation
Each REST endpoint maps to an MCP tool:
REST parameters → MCP tool arguments
REST responses → MCP tool results
REST authentication → MCP tool context
2. Edge Deployment
Single worker serves both interfaces
Global distribution via Cloudflare's network
Low latency for both REST and MCP calls
3. Unified Codebase
Share business logic between REST and MCP
DRY principle: define operations once
Easy to maintain and extend
Project Structure
Next Steps
Add authentication (API keys, OAuth)
Implement rate limiting
Add caching with Cloudflare KV
Connect to Cloudflare D1 for persistent storage
Add streaming responses
Implement pagination
Learn More
Course Title
"From the Edge and Back: Turn Any REST API into an MCP Server"
A practical, code-heavy session showing how to wrap any REST API with the Model Context Protocol and deploy it to Cloudflare Workers for lightning-fast, globally distributed access.
This server cannot be installed