Skip to main content

Hands-on Workshop

Build an MCP Server on Cloudflare Workers

Give AI assistants real tools. Build, test, and deploy a Model Context Protocol server - from custom tools to a full persistent app.

~3 hours Beginner – Advanced Node.js v20+
Workshop Roadmap
  1. 01
    Getting Started with MCP Server 20 min
  2. 02
    Adding Custom Tools 25 min
  3. 03
    External API Integration 30 min
  4. 04
    Deploy to Cloudflare Workers 25 min
  5. 05
    Cloudflare KV Storage 30 min
  6. 06
    Building a Persistent Todo App 45 min
  7. 07
    You're an MCP Builder Now 15 min
Tools you'll use
WranglerWorkersKVMCP InspectorWorkers AI

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.

Prerequisites

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

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 Streamable HTTP for real-time bidirectional 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 new MCP server from template
npm create cloudflare@latest -- my-mcp-server --template=cloudflare/ai/demos/remote-mcp-authless

# Navigate to your project
cd my-mcp-server

# Install dependencies and start development server
npm install
npm run dev
Expected Output text

⛅️ wrangler 4.64.0 ─────────────────── Your Worker has access to the following bindings: Binding Resource Mode env.MCP_OBJECT (MyMCP) Durable Object local

╭──────────────────────────────────────────────────────────────────────╮ │ [b] open a browser [d] open devtools [c] clear console [x] to exit │ ╰──────────────────────────────────────────────────────────────────────╯ ⎔ Starting local server… [wrangler:info] Ready on http://localhost:8787

Browser output
What Just Happened?

Your MCP server is running, even if it displays “Not Found”. You’ve created a fully functional MCP server that includes:

  • Tool definitions: Pre-built tools like “add” for mathematical operations
  • MCP endpoint: The /mcp 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 v20+ from nodejs.org
  • Template not found: Update npm: npm install -g npm@latest
  • Port 8787 busy: Stop other services or use npm run dev -- --port 8788
  • Build errors: Delete node_modules and run npm install again
  • Inspector won’t connect: Verify your MCP server is running on http://localhost:8787 and the endpoint is /mcp
  • No tools visible: Check server logs for errors. The template should provide basic tools by default.

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://localhost:6274/?MCP_PROXY_AUTH_TOKEN=[your_token]
  2. Open this URL in your browser (the inspector will do this automatically)
  3. Make sure “Streamable HTTP” is the Transport Type
  4. Enter http://localhost:8787/mcp as the URL
  5. Click “Connect” to establish the connection
  6. Make sure you’re on the “Tools” tab
  7. Click “List Tools”
  8. Click the “add” tool and run it with 2 numbers
Preview for inspector
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

You now have a functional MCP server that AI assistants can connect to and use!

Learning Resources

Documentation for every tool used in this workshop.

MCP Specification

Official Model Context Protocol spec, transport details, and tool schemas

READ SPEC

Cloudflare Workers

Runtime docs, bindings reference, and deployment guides for Workers

WORKERS DOCS

Cloudflare KV

Key-value storage for persistent state in your MCP tools

KV DOCS

Workers AI

Run inference on ML models directly from your MCP server

AI DOCS

Claude Desktop

Connect your MCP server to Claude for testing and development

DOWNLOAD

Developer Channel

Video walkthroughs and tutorials for the Developer Platform

WATCH VIDEOS