cloudflare-mcp-server
БесплатноБез исполняемых скриптовНе проверенBuilds and deploys remote Model Context Protocol (MCP) servers on Cloudflare Workers in TypeScript with @modelcontextprotocol/sdk: McpAgent class patterns for…
Об этом скилле
Cloudflare MCP Server Skill
Build and deploy Model Context Protocol (MCP) servers on Cloudflare Workers with TypeScript.
What is This Skill?
This skill teaches you to build remote MCP servers on Cloudflare - the ONLY platform with official remote MCP support as of 2025.
Use this skill when:
- Building MCP servers with TypeScript (@modelcontextprotocol/sdk)
- Deploying remote MCP servers to Cloudflare Workers
- Implementing OAuth authentication (GitHub, Google, Azure, custom)
- Creating stateful MCP servers with Durable Objects
- Optimizing costs with WebSocket hibernation
- Supporting both SSE and Streamable HTTP transports
- Avoiding 15+ common MCP + Cloudflare errors
You'll learn:
- McpAgent class patterns and tool definitions
- OAuth integration (all 4 auth patterns)
- Durable Objects for per-session state
- WebSocket hibernation API
- Dual transport configuration (SSE + HTTP)
- Complete deployment workflow
Quick Start (5 Minutes)
Option 1: Deploy from Template
# Create new MCP server from Cloudflare template
npm create cloudflare@latest -- my-mcp-server \
--template=cloudflare/ai/demos/remote-mcp-authless
cd my-mcp-server
npm install
npm run dev
Your MCP server is now running at http://localhost:8788/sse
Option 2: Copy Templates from This Skill
# Copy basic MCP server template
cp ~/.claude/skills/cloudflare-mcp-server/templates/basic-mcp-server.ts src/index.ts
cp ~/.claude/skills/cloudflare-mcp-server/templates/wrangler-basic.jsonc wrangler.jsonc
cp ~/.claude/skills/cloudflare-mcp-server/templates/package.json package.json
# Install dependencies
npm install
# Start development server
npm run dev
Test with MCP Inspector
# In a new terminal, start MCP Inspector
npx @modelcontextprotocol/inspector@latest
# Open http://localhost:5173
# Enter your MCP server URL: http://localhost:8788/sse
# Click "Connect" and test tools
Deploy to Cloudflare
# Deploy to production
npx wrangler deploy
# Your MCP server is now live at:
# https://my-mcp-server.your-account.workers.dev/sse
Core Concepts
1. McpAgent Class
The McpAgent base class from Cloudflare's Agents SDK provides:
- Automatic Durable Objects integration
- Built-in state management with SQL database
- Tool, resource, and prompt registration
- Transport handling (SSE + HTTP)
Basic pattern:
import { McpAgent } from "agents/mcp";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
export class MyMCP extends McpAgent<Env> {
server = new McpServer({
name: "My MCP Server",
version: "1.0.0"
});
async init() {
// Register tools here
this.server.tool(
"tool_name",
"Tool description",
{ param: z.string() },
async ({ param }) => ({
content: [{ type: "text", text: "Result" }]
})
);
}
}
2. Tool Definitions
Tools are functions that MCP clients can invoke. Use Zod for parameter validation.
Pattern:
this.server.tool(
"tool_name", // Tool identifier
"Tool description", // What it does (for LLM)
{ // Parameters (Zod schema)
param1: z.string().describe("Parameter description"),
param2: z.number().optional()
},
async ({ param1, param2 }) => { // Handler
// Your logic here
return {
content: [{ type: "text", text: "Result" }]
};
}
);
Best practices:
- Detailed descriptions: Help LLMs understand tool purpose
- Parameter descriptions: Explain expected values and constraints
- Error handling: Return
{ isError: true }for failures - Few, focused tools: Better than many granular ones
3. Transport Methods
MCP supports two transports:
SSE (Server-Sent Events) - Legacy, widely supported:
MyMCP.serveSSE("/sse").fetch(request, env, ctx)
Streamable HTTP - 2025 standard, more efficient:
MyMCP.serve("/mcp").fetch(request, env, ctx)
Support both for maximum compatibility:
export default {
fetch(request: Request, env: Env, ctx: ExecutionContext) {
const { pathname } = new URL(request.url);
if (pathname.startsWith("/sse")) {
return MyMCP.serveSSE("/sse").fetch(request, env, ctx);
}
if (pathname.startsWith("/mcp")) {
return MyMCP.serve("/mcp").fetch(request, env, ctx);
}
return new Response("Not Found", { status: 404 });
}
};
Authentication Patterns
Cloudflare MCP servers support 4 authentication patterns:
Pattern 1: No Authentication
Use case: Internal tools, development, public APIs
Template: templates/basic-mcp-server.ts
Setup: None required
Security: ⚠️ Anyone can access your MCP server
Pattern 2: Token Validation (JWTVerifier)
Use case: Pre-authenticated clients, custom auth systems
How it works: Client sends Bearer token, s
Установить cloudflare-mcp-server в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditBashGlobGrepВложенные файлы
FAQ
Что делает скилл cloudflare-mcp-server?
Builds and deploys remote Model Context Protocol (MCP) servers on Cloudflare Workers in TypeScript with @modelcontextprotocol/sdk: McpAgent class patterns for tools, resources, and prompts, all four authentication patterns (token validation, remote OAuth with DCR, OAuth proxy via workers-oauth-provider, and a full OAuth provider), GitHub/Google/Azure OAuth, Durable Objects for per-session state, WebSocket hibernation for cost savings, and dual SSE plus Streamable HTTP transports. Ships templates for basic servers, OAuth proxy, stateful Durable Object servers, and wrangler.jsonc configs, and prevents 15+ errors including McpAgent export mistakes, OAuth redirect URI mismatches, WebSocket state loss, Durable Objects binding errors, and CORS misconfiguration. Use when creating, authenticating, debugging, or deploying an MCP server on Cloudflare Workers.
Как установить скилл cloudflare-mcp-server?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл cloudflare-mcp-server запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic