$npx -y skills add jackspace/ClaudeSkillz --skill cloudflare-mcp-serverUse this skill when building Model Context Protocol (MCP) servers on Cloudflare Workers. This skill should be used when deploying remote MCP servers with TypeScript, implementing OAuth authentication (GitHub, Google, Azure, etc.), using Durable Objects for stateful MCP servers, i
| 1 | # Cloudflare MCP Server Skill |
| 2 | |
| 3 | Build and deploy **Model Context Protocol (MCP) servers** on Cloudflare Workers with TypeScript. |
| 4 | |
| 5 | --- |
| 6 | |
| 7 | ## What is This Skill? |
| 8 | |
| 9 | This skill teaches you to build **remote MCP servers** on Cloudflare - the ONLY platform with official remote MCP support as of 2025. |
| 10 | |
| 11 | **Use this skill when**: |
| 12 | - Building MCP servers with TypeScript (@modelcontextprotocol/sdk) |
| 13 | - Deploying remote MCP servers to Cloudflare Workers |
| 14 | - Implementing OAuth authentication (GitHub, Google, Azure, custom) |
| 15 | - Creating stateful MCP servers with Durable Objects |
| 16 | - Optimizing costs with WebSocket hibernation |
| 17 | - Supporting both SSE and Streamable HTTP transports |
| 18 | - Avoiding 15+ common MCP + Cloudflare errors |
| 19 | |
| 20 | **You'll learn**: |
| 21 | 1. McpAgent class patterns and tool definitions |
| 22 | 2. OAuth integration (all 4 auth patterns) |
| 23 | 3. Durable Objects for per-session state |
| 24 | 4. WebSocket hibernation API |
| 25 | 5. Dual transport configuration (SSE + HTTP) |
| 26 | 6. Complete deployment workflow |
| 27 | |
| 28 | --- |
| 29 | |
| 30 | ## Quick Start (5 Minutes) |
| 31 | |
| 32 | ### Option 1: Deploy from Template |
| 33 | |
| 34 | ```bash |
| 35 | # Create new MCP server from Cloudflare template |
| 36 | npm create cloudflare@latest -- my-mcp-server \ |
| 37 | --template=cloudflare/ai/demos/remote-mcp-authless |
| 38 | |
| 39 | cd my-mcp-server |
| 40 | npm install |
| 41 | npm run dev |
| 42 | ``` |
| 43 | |
| 44 | Your MCP server is now running at `http://localhost:8788/sse` |
| 45 | |
| 46 | ### Option 2: Copy Templates from This Skill |
| 47 | |
| 48 | ```bash |
| 49 | # Copy basic MCP server template |
| 50 | cp ~/.claude/skills/cloudflare-mcp-server/templates/basic-mcp-server.ts src/index.ts |
| 51 | cp ~/.claude/skills/cloudflare-mcp-server/templates/wrangler-basic.jsonc wrangler.jsonc |
| 52 | cp ~/.claude/skills/cloudflare-mcp-server/templates/package.json package.json |
| 53 | |
| 54 | # Install dependencies |
| 55 | npm install |
| 56 | |
| 57 | # Start development server |
| 58 | npm run dev |
| 59 | ``` |
| 60 | |
| 61 | ### Test with MCP Inspector |
| 62 | |
| 63 | ```bash |
| 64 | # In a new terminal, start MCP Inspector |
| 65 | npx @modelcontextprotocol/inspector@latest |
| 66 | |
| 67 | # Open http://localhost:5173 |
| 68 | # Enter your MCP server URL: http://localhost:8788/sse |
| 69 | # Click "Connect" and test tools |
| 70 | ``` |
| 71 | |
| 72 | ### Deploy to Cloudflare |
| 73 | |
| 74 | ```bash |
| 75 | # Deploy to production |
| 76 | npx wrangler deploy |
| 77 | |
| 78 | # Your MCP server is now live at: |
| 79 | # https://my-mcp-server.your-account.workers.dev/sse |
| 80 | ``` |
| 81 | |
| 82 | --- |
| 83 | |
| 84 | ## Core Concepts |
| 85 | |
| 86 | ### 1. McpAgent Class |
| 87 | |
| 88 | The `McpAgent` base class from Cloudflare's Agents SDK provides: |
| 89 | - Automatic Durable Objects integration |
| 90 | - Built-in state management with SQL database |
| 91 | - Tool, resource, and prompt registration |
| 92 | - Transport handling (SSE + HTTP) |
| 93 | |
| 94 | **Basic pattern**: |
| 95 | ```typescript |
| 96 | import { McpAgent } from "agents/mcp"; |
| 97 | import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; |
| 98 | import { z } from "zod"; |
| 99 | |
| 100 | export class MyMCP extends McpAgent<Env> { |
| 101 | server = new McpServer({ |
| 102 | name: "My MCP Server", |
| 103 | version: "1.0.0" |
| 104 | }); |
| 105 | |
| 106 | async init() { |
| 107 | // Register tools here |
| 108 | this.server.tool( |
| 109 | "tool_name", |
| 110 | "Tool description", |
| 111 | { param: z.string() }, |
| 112 | async ({ param }) => ({ |
| 113 | content: [{ type: "text", text: "Result" }] |
| 114 | }) |
| 115 | ); |
| 116 | } |
| 117 | } |
| 118 | ``` |
| 119 | |
| 120 | ### 2. Tool Definitions |
| 121 | |
| 122 | Tools are functions that MCP clients can invoke. Use Zod |