Before we dive into building MCP servers with Cloudflare, let's understand the core concepts and architecture that make the Model Context Protocol powerful.
The Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to large language models (LLMs). Think of MCP like a USB-C port for AI - it provides a standardized way to connect AI models to different data sources and tools.
The Model Context Protocol follows a client-server architecture where your MCP server will fit into a broader ecosystem:
flowchart TD
Claude[🤖 MCP Host<br/>Claude Desktop/API]
Server[⚡ MCP Server<br/>Your Cloudflare Worker]
APIs[External APIs<br/>Travel, Calendar, etc.]
Storage[Cloudflare Services<br/>D1, KV, R2]
Claude <--> Server
Server <--> APIs
Server <--> Storage
- Your AI Interface: Claude Desktop, Claude Code, or other MCP-compatible clients
- Initiates conversations and decides when to call your tools
- Manages user permissions and consent for tool execution
- Built into Claude: Handles the MCP protocol communication
- Negotiates capabilities with your MCP server
- Sends tool requests and processes responses
- Runs on Cloudflare Workers: Globally distributed, serverless execution
- Exposes tools that Claude can call (flight search, restaurant booking, etc.)
- Connects to external APIs and data sources
- Returns structured responses back to Claude
- APIs: Travel services, calendar systems, booking platforms
- Cloudflare Services: D1 Database, KV Storage, R2 Object Storage
- Authentication: OAuth flows, API keys managed securely
Here's how a typical interaction flows through your MCP server:
- User Request: "Book me a restaurant for Friday night"
- Claude Analysis: Determines it needs to use your restaurant booking tool
- MCP Tool Call: Claude calls your Cloudflare Workers endpoint
- Server Processing: Your worker queries OpenTable API, checks availability
- Response: Structured data returned to Claude
- User Experience: Claude presents booking options and confirmations
Your MCP server can provide these core features:
Functions that Claude can execute to perform specific tasks:
// Example: Restaurant search tool
server.tool("searchRestaurants", {
location: z.string().describe("City or address to search"),
date: z.string().describe("Date in YYYY-MM-DD format"),
partySize: z.number().describe("Number of people")
}, async ({ location, date, partySize }) => {
// Your MCP server logic here
const restaurants = await searchRestaurantsAPI(location, date, partySize);
return { restaurants };
});Contextual data that Claude can reference:
- User preferences stored in Cloudflare KV
- Restaurant favorites or booking history
- Travel itineraries from previous bookings
Pre-defined conversation templates:
- Booking confirmation workflows
- Travel planning conversation starters
- Meeting summary templates
Your workshop leverages Cloudflare because it's perfect for MCP servers:
- Global Edge Deployment: Low latency responses to Claude
- Serverless Scale: Handle varying loads automatically
- Built-in Security: DDoS protection, secure environment variables
- Easy Integration: Simple HTTP endpoints that Claude can call
- Cost Effective: Pay per request, perfect for MCP tool usage patterns
Ready to build? Now that you understand how MCP works, let's dive in and build your server!