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
访问服务器

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.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选