CF-MCP

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.

Category
Visit Server

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 product
  • POST /api/products - Create a new product
  • PUT /api/products/:id - Update a product
  • DELETE /api/products/:id - Delete a product

MCP Tools

The MCP endpoint wraps all REST operations as tools:

  • list_products - Query products with filters
  • get_product - Retrieve product details
  • create_product - Add new products
  • update_product - Modify existing products
  • delete_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

  1. Add authentication (API keys, OAuth)
  2. Implement rate limiting
  3. Add caching with Cloudflare KV
  4. Connect to Cloudflare D1 for persistent storage
  5. Add streaming responses
  6. 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

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
Kagi MCP Server

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.

Official
Featured
Python
graphlit-mcp-server

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.

Official
Featured
TypeScript
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured