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.
- 01 Getting Started with MCP Server 20 min
- 02 Adding Custom Tools 25 min
- 03 External API Integration 30 min
- 04 Deploy to Cloudflare Workers 25 min
- 05 Cloudflare KV Storage 30 min
- 06 Building a Persistent Todo App 45 min
- 07 You're an MCP Builder Now 15 min
Workshop Steps
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.
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
# 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
⛅️ 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
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_modulesand runnpm installagain - Inspector won’t connect: Verify your MCP server is running on
http://localhost:8787and 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
# In a new terminal window (keep your server running)
npx @modelcontextprotocol/inspector
Inspector Connection Process:
- The inspector starts at
http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=[your_token] - Open this URL in your browser (the inspector will do this automatically)
- Make sure “Streamable HTTP” is the Transport Type
- Enter
http://localhost:8787/mcpas the URL - Click “Connect” to establish the connection
- Make sure you’re on the “Tools” tab
- Click “List Tools”
- Click the “add” tool and run it with 2 numbers
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