home / skills / secondsky / claude-skills / cloudflare-mcp-server

This skill helps you implement MCP servers on Cloudflare Workers, enabling tools, resources, prompts, and transports with ready-to-use templates.

npx playbooks add skill secondsky/claude-skills --skill cloudflare-mcp-server

Review the files below or copy the command above to add this skill to your agents.

Files (27)
SKILL.md
1.9 KB
---
name: cloudflare-mcp-server
description: Build MCP (Model Context Protocol) servers on Cloudflare Workers with tools, resources, and prompts.
license: MIT
---

# Cloudflare MCP Server

**Last Updated**: 2025-11-21

## Quick Start

```typescript
import { McpServer } from '@modelcontextprotocol/sdk';

const server = new McpServer({
  name: 'my-server',
  version: '1.0.0'
});

server.tool('getTodo', async ({ id }) => ({
  id,
  title: 'Task',
  completed: false
}));

export default server;
```

## Core Concepts

- **Tools**: Functions AI can call
- **Resources**: Data AI can access
- **Prompts**: Reusable templates
- **Transports**: SSE, HTTP, WebSocket

## Example Tool

```typescript
server.tool('searchDocs', {
  description: 'Search documentation',
  parameters: {
    type: 'object',
    properties: {
      query: { type: 'string' }
    }
  },
  handler: async ({ query }) => {
    return { results: [...] };
  }
});
```

## Resources

### Core Documentation
- `references/quick-start-guide.md` (704 lines) - Official Cloudflare templates, complete step-by-step workflow, 5-minute setup
- `references/core-concepts.md` (66 lines) - MCP fundamentals: tools, resources, prompts, transports
- `references/worker-basics.md` (326 lines) - Worker & Durable Objects basics, transport selection, HTTP fundamentals
- `references/stateful-servers.md` (246 lines) - Durable Objects integration, WebSocket hibernation, cost optimization, common patterns
- `references/production-deployment.md` (814 lines) - Deployment & testing, configuration reference, authentication patterns, 22 known errors with solutions

### Templates
- `templates/basic-mcp.ts` - Minimal MCP server
- `templates/tools-example.ts` - Tool definitions
- `templates/durable-object-mcp.ts` - Stateful MCP with DO
- `templates/websocket-mcp.ts` - WebSocket transport

**Official Docs**: https://modelcontextprotocol.io | **Cloudflare**: https://developers.cloudflare.com/workers/runtime-apis/durable-objects/

Overview

This skill helps you build Model Context Protocol (MCP) servers on Cloudflare Workers using TypeScript and production-ready patterns. It bundles tools, resource conventions, prompt templates, and transport examples so you can deploy stateful or stateless MCP endpoints quickly. Designed for Claude Code CLI workflows, it includes Durable Object patterns and WebSocket/SSE/HTTP transports.

How this skill works

The skill exposes a McpServer abstraction where you register tools (callable functions), resources (readable data surfaces), and prompts (reusable templates). It provides example templates for minimal servers, durable-object-backed stateful servers, and WebSocket transports so you can pick the right architecture. Included reference docs and production notes cover deployment, authentication, error handling, and cost-conscious Durable Object usage.

When to use it

  • You need an MCP server running on Cloudflare Workers for low-latency AI tool access.
  • You want a production-ready template that includes Durable Object patterns for stateful interactions.
  • You need examples for WebSocket, SSE, or HTTP transports to support real-time LLM tool calls.
  • You want clear deployment and testing guidance for Cloudflare plus known production errors and fixes.
  • You are integrating Claude Code CLI workflows or building plugins that require server-side tools and prompts.

Best practices

  • Define clear tool schemas and parameter validation to avoid runtime errors.
  • Use Durable Objects for session/state management and design hibernation-friendly handlers to reduce costs.
  • Prefer typed TypeScript handlers and export a single McpServer instance for easy deployment.
  • Use the production-deployment guide for authentication, environment variables, and CI/CD checks.
  • Test transports locally and with Cloudflare’s preview to catch transport-specific edge cases early.

Example use cases

  • Expose a 'searchDocs' tool that queries indexed documentation and returns structured results to the model.
  • Create a stateful chat session using Durable Objects and WebSocket transport for persistent conversation memory.
  • Implement a lightweight HTTP-only MCP for synchronous tool calls like fetching user profile or todo items.
  • Build a production-ready MCP with authentication and rate limiting following the deployment guide.
  • Prototype prompt templates and reusable tool handlers for rapid Claude Code plugin development.

FAQ

What transports are supported?

Examples include SSE, HTTP, and WebSocket transports with templates and notes on when to use each.

Does this include Durable Object examples?

Yes. There are templates and a dedicated reference for stateful servers using Durable Objects and cost optimization patterns.