HC

heygarrison/cf-mcp

Developer tools

이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기

6 stars 9 forks 품질 45 트렌드 14

A single Cloudflare Worker that serves both a REST API and an MCP (Model Context Protocol) interface.

개요

A single Cloudflare Worker that serves both a REST API and an MCP (Model Context Protocol) interface. - 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 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 The server will start at http://localhost:8787 After deployment, your API will be available globally on Cloudflare's edge network!

README

원문 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
GitHub에서 전체 README 보기

설치

This server does not publish a one-line install command.

Open the repository installation guide MCP 초보자라면? mcpskill.org 가이드부터 시작하세요 →