Learn MCP

Build a Model Context Protocol server with Cloudflare Workers.

What You'll Build

  • Custom AI assistant tools
  • Persistent todo applications
  • External API integrations
  • Real-time data processors

Prerequisites

  • Node.js v18+
  • Cloudflare Account
  • Terminal/Command Line
  • Basic JavaScript knowledge

Workshop Format

  • 7 hands-on steps
  • Progressive complexity
  • Deploy to production

MCP Fundamentals

What is Model Context Protocol?

MCP is a standardized protocol that allows AI assistants to connect to external systems and tools. Instead of being limited to their training data, assistants can access real-time information and perform actions through MCP servers.

Core Components

  • Transport: Server-Sent Events (SSE) for real-time communication
  • Tools: Functions that AI assistants can call
  • Resources: Data sources (files, databases, APIs)
  • Prompts: Reusable prompt templates

How It Works

Your MCP server runs on Cloudflare Workers and exposes tools via HTTP endpoints. AI assistants connect to your server and can call these tools to perform tasks like:

  • Reading and writing data to databases
  • Making API calls to external services
  • Processing files and generating content
  • Managing persistent state with KV storage

Prerequisites

Before starting the workshop, ensure you have:

💻

Node.js v18+

Download from nodejs.org

☁️

Free Cloudflare Account

Sign up here (no credit card needed)

Wrangler CLI

npm install -g wrangler && wrangler login

🧠

Basic JavaScript

Familiarity with Node.js and terminal usage

Ready? Jump into the hands-on workshop below! ⬇️

Workshop Steps

WORKSHOP STEPS
STEP 01

Getting Started with MCP Server

Set up a functional MCP server using Cloudflare Workers. Understand basic MCP server structure and test MCP tools using the inspector interface.

🎯 Learning Objectives

  • Set up a functional MCP server with Cloudflare Workers
  • Understand MCP server basic structure and architecture
  • Test MCP tools using the official inspector interface
  • Troubleshoot common connection and setup issues
🛠️ Understanding MCP (Model Context Protocol)

MCP is an open standard that enables AI assistants to connect to external tools and data sources. Think of it as a universal interface that lets AI systems perform actions beyond their training - like reading files, calling APIs, or managing databases.

  • Server-Client Architecture: Your MCP server exposes tools that AI clients can discover and use
  • Standardized Communication: Uses SSE (Server-Sent Events) for real-time communication
  • Tool Discovery: AI assistants can list available tools and their parameters automatically
  • Global Deployment: Run on Cloudflare Workers for worldwide, low-latency access

Step 1

Create Your MCP Server

What we're building
A Cloudflare Workers-based MCP server that AI assistants can connect to and use.
Why this matters
Cloudflare Workers provide global deployment with minimal latency, making your MCP tools available worldwide.
Create Your MCP Server bash

// Create new MCP server from template npm create cloudflare@latest — my-mcp-server —template=cloudflare/ai/demos/remote-mcp-authless

// Navigate to your new project cd my-mcp-server

// Install dependencies and start development server npm install npm start

Expected Output text

⚡ Local MCP server running at http://localhost:8787 🔧 SSE endpoint available at http://localhost:8787/sse

📝 What Just Happened?

You’ve created a fully functional MCP server that includes:

  • Tool definitions: Pre-built tools like “add” for mathematical operations
  • SSE endpoint: The /sse route that AI assistants connect to
  • Error handling: Robust error responses for debugging
  • CORS support: Proper headers for cross-origin requests
Troubleshooting
  • npm not found: Install Node.js v18+ from nodejs.org
  • Template not found: Update npm: npm install -g npm@latest
  • Permission denied: Use sudo npm install -g wrangler (macOS/Linux)
  • Port 8787 busy: Stop other services or use npm start -- --port 8788
  • Build errors: Delete node_modules and run npm install again

Step 2: Test with MCP Inspector

What we're building
A connection between the MCP Inspector and your server to verify functionality and test tools.
Why this matters
The inspector is the easiest way to verify your MCP server is working and explore available tools.
# In a new terminal window (keep your server running)
npx @modelcontextprotocol/inspector

Inspector Connection Process:

  1. The inspector starts at http://127.0.0.1:6274
  2. Open this URL in your browser
  3. Select “SSE” as the Transport Type
  4. Enter http://localhost:8787/sse as the Server URL
  5. Click “Connect” to establish the connection
  6. Navigate to the “Tools” tab to see available functions
  7. Test the “add” tool with parameters like {"a": 5, "b": 3}
📝 What You Should See

Once connected, the inspector will show:

  • Server Info: Basic metadata about your MCP server
  • Available Tools: List of tools with their descriptions and parameters
  • Tool Testing: Interface to call tools with custom parameters
  • Response Data: JSON responses from your tool executions
Successful Connection bash

✅ Connected to MCP Server 🔧 Found 1 tool: “add” 📊 Server responding to requests

Step 3: Understanding Your MCP Server

What we're building
Understanding of your MCP server's architecture and how AI assistants interact with its tools.
Why this matters
MCP servers expose tools that AI assistants can use to perform actions and access data beyond their training.
🛠️ MCP Server Architecture

Your MCP server provides a standardized interface for AI assistants to:

  • Discover tools: List available functions and their parameters
  • Execute tools: Run functions with provided arguments
  • Handle errors: Provide meaningful feedback when things go wrong

🔍 Common Issues & Solutions

Inspector won’t connect:

Verify your MCP server is running on http://localhost:8787 and the SSE endpoint is /sse

No tools visible:

Check server logs for errors. The template should provide basic tools by default.

Port already in use:

Stop other services using port 8787 or modify the port in your configuration.

Great work! You now have a functional MCP server that AI assistants can connect to and use. You’re ready to add custom tools in Step 2!

Learning Resources

Essential resources for mastering MCP development and building powerful AI tools.

📖 MCP Documentation

Official Model Context Protocol documentation with API references and best practices

READ DOCS

🎥 Developer Channel

Getting started guides and how-to videos for the Developer Platform and AI tools

WATCH VIDEOS

💬 Community

Open community where users can ask questions and share ideas and solutions

JOIN COMMUNITY

🔧 Cloudflare Workers

Deploy your MCP servers globally with Cloudflare Workers documentation

WORKERS DOCS

💾 Cloudflare KV

Learn about key-value storage for building persistent MCP applications

KV DOCS

💙 Claude Desktop

Connect your MCP servers to Claude Desktop for AI-powered development

DOWNLOAD CLAUDE