CF-MCP
A Cloudflare Worker that demonstrates wrapping REST APIs with Model Context Protocol, providing product management operations through both REST endpoints and MCP tools on the edge.
README
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
┌─────────────────────────────────────┐
│ Cloudflare Worker (Edge) │
│ │
│ ┌────────────────────────────────┐ │
│ │ Hono Router │ │
│ │ │ │
│ │ /api/* ─── REST API │ │
│ │ │ │
│ │ /mcp ─── MCP Protocol │ │
│ │ (wraps REST) │ │
│ └────────────────────────────────┘ │
└─────────────────────────────────────┘
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
npm install
Run Locally
npm run dev
The server will start at http://localhost:8787
Test REST API
# List all products
curl http://localhost:8787/api/products
# Get a specific product
curl http://localhost:8787/api/products/1
# Filter by category
curl http://localhost:8787/api/products?category=Electronics
# Create a product
curl -X POST http://localhost:8787/api/products \
-H "Content-Type: application/json" \
-d '{"name":"Laptop","price":999,"description":"Powerful laptop","category":"Electronics"}'
Test MCP Endpoint
# List available tools
curl -X POST http://localhost:8787/mcp \
-H "Content-Type: application/json" \
-d '{"method":"tools/list","params":{}}'
# Call a tool
curl -X POST http://localhost:8787/mcp \
-H "Content-Type: application/json" \
-d '{"method":"tools/call","params":{"name":"list_products","arguments":{"category":"Electronics"}}}'
Deploy to Cloudflare
npm run deploy
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
cf-mcp/
├── src/
│ ├── index.ts # Main Hono app + routing
│ ├── api.ts # REST API endpoints
│ └── mcp.ts # MCP protocol handler
├── wrangler.toml # Cloudflare config
├── package.json
└── tsconfig.json
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.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
E2B
Using MCP to run code via e2b.