Token导航 LogoToken导航TokenDH.com
开发敏感数据github未标认证来源可访问clear审计提醒

cloudflare-mcp-serverCloudflare MCP server 搜索

Agent Skill

cloudflare-mcp-server 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

624

周安装

25

GitHub Stars

14

下载量

202
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:cloudflare-mcp-server(Cloudflare MCP server 搜索)
来源仓库:https://github.com/jackspace/claudeskillz
仓库路径:skills/cloudflare-mcp-server
安装命令:
npx skills add https://github.com/jackspace/claudeskillz --skill cloudflare-mcp-server
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/jackspace/claudeskillz --skill cloudflare-mcp-server

简介

cloudflare-mcp-server 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中围绕仓库状态或协作事项进行整理。

  • 适用于需要分析代码变更、跟踪 Issue 进展或生成协作报告的场景。
  • 通过 npx skills add 命令从指定仓库安装,需确认权限范围和操作边界。
  • 安装前建议检查维护状态,避免触发联网或文件读写等敏感操作。
  • 可结合原始 README 和仓库内容进一步核验具体功能和使用方式。

SKILL.md

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:

  1. McpAgent class patterns and tool definitions
  2. OAuth integration (all 4 auth patterns)
  3. Durable Objects for per-session state
  4. WebSocket hibernation API
  5. Dual transport configuration (SSE + HTTP)
  6. 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, server validates

Template: Create custom JWTVerifier middleware

Setup:

import { JWTVerifier } from "agents/mcp";

const verifier = new JWTVerifier({
  secret: env.JWT_SECRET,
  issuer: "your-auth-server"
});

// Validate token before serving MCP requests

Security: ✅ Secure if tokens are properly managed


Pattern 3: OAuth Proxy (workers-oauth-provider)

Use case: GitHub, Google, Azure OAuth integration

How it works: Cloudflare Worker proxies OAuth to third-party provider

Template: templates/mcp-oauth-proxy.ts

Setup:

import { OAuthProvider, GitHubHandler } from "@cloudflare/workers-oauth-provider";

export default new OAuthProvider({
  authorizeEndpoint: "/authorize",
  tokenEndpoint: "/token",
  clientRegistrationEndpoint: "/register",

  defaultHandler: new GitHubHandler({
    clientId: (env) => env.GITHUB_CLIENT_ID,
    clientSecret: (env) => env.GITHUB_CLIENT_SECRET,
    scopes: ["repo", "user:email"],

    context: async (accessToken) => {
      // Fetch user info from GitHub
      const octokit = new Octokit({ auth: accessToken });
      const { data: user } = await octokit.rest.users.getAuthenticated();

      return {
        login: user.login,
        email: user.email,
        accessToken
      };
    }
  }),

  kv: (env) => env.OAUTH_KV,
  apiHandlers: {
    "/sse": MyMCP.serveSSE("/sse"),
    "/mcp": MyMCP.serve("/mcp")
  },

  allowConsentScreen: true,
  allowDynamicClientRegistration: true
});

Required bindings:

{
  "kv_namespaces": [
    { "binding": "OAUTH_KV", "id": "YOUR_KV_ID" }
  ]
}

Security: ✅✅ Secure, production-ready


Pattern 4: Remote OAuth with DCR

Use case: Full OAuth provider, custom consent screens

How it works: Your Worker is the OAuth provider

Template: See Cloudflare's remote-mcp-authkit demo

Setup: Complex, requires full OAuth 2.1 implementation

Security: ✅✅✅ Most secure, full control


Stateful MCP Servers with Durable Objects

Use Durable Objects when your MCP server needs:

  • Per-session persistent state
  • Conversation history
  • Game state (chess, tic-tac-toe)
  • Cached API responses
  • User preferences

Storage API Pattern

Template: templates/mcp-stateful-do.ts

Store values:

await this.state.storage.put("key", "value");
await this.state.storage.put("user_prefs", { theme: "dark" });

Retrieve values:

const value = await this.state.storage.get<string>("key");
const prefs = await this.state.storage.get<object>("user_prefs");

List keys:

const allKeys = await this.state.storage.list();

Delete keys:

await this.state.storage.delete("key");

Configuration

wrangler.jsonc:

{
  "durable_objects": {
    "bindings": [
      {
        "name": "MY_MCP",
        "class_name": "MyMCP",
        "script_name": "my-mcp-server"
      }
    ]
  },

  "migrations": [
    { "tag": "v1", "new_classes": ["MyMCP"] }
  ]
}

IMPORTANT: Migrations are required on first deployment!


WebSocket Hibernation for Cost Optimization

Problem: Long-lived WebSocket connections cost CPU time

Solution: WebSocket Hibernation API suspends connections when idle

Pattern

Serialize metadata (preserves data during hibernation):

webSocket.serializeAttachment({
  userId: "123",
  sessionId: "abc",
  connectedAt: Date.now()
});

Retrieve on wake:

const metadata = webSocket.deserializeAttachment();
console.log(metadata.userId); // "123"

Storage for persistent state:

// ❌ DON'T: In-memory state lost on hibernation
this.userId = "123";

// ✅ DO: Use storage API
await this.state.storage.put("userId", "123");

Cost Savings

Without hibernation:

  • 1000 concurrent WebSockets × 10ms CPU/sec = 10 CPU-sec/sec
  • Cost: ~$0.50/day

With hibernation:

  • CPU only on messages (99% idle time suspended)
  • Cost: ~$0.01/day (50x reduction!)

Worker & Durable Objects Basics

*Self-contained section for standalone use*

Worker Export Pattern

Workers must export a fetch handler:

export default {
  fetch(request: Request, env: Env, ctx: ExecutionContext): Response | Promise<Response> {
    // Handle request
    return new Response("Hello");
  }
};

Durable Objects Class Structure

DOs extend McpAgent (for MCP servers):

export class MyMCP extends McpAgent<Env> {
  constructor(state: DurableObjectState, env: Env) {
    super(state, env);
  }

  // Your methods here
}

Bindings Configuration

Environment bindings give Workers access to resources:

{
  "kv_namespaces": [{ "binding": "MY_KV", "id": "..." }],
  "durable_objects": {
    "bindings": [{ "name": "MY_DO", "class_name": "MyDO" }]
  },
  "r2_buckets": [{ "binding": "MY_BUCKET", "bucket_name": "..." }]
}

Access in code:

env.MY_KV.get("key");
env.MY_DO.idFromName("session-123").getStub(env);
env.MY_BUCKET.get("file.txt");

Deployment & Testing

Local Development

# Start dev server (uses Miniflare for local DOs)
npm run dev

# Start dev server with remote Durable Objects (more accurate)
npx wrangler dev --remote

Access at: http://localhost:8788/sse

Test with MCP Inspector

npx @modelcontextprotocol/inspector@latest
  1. Open http://localhost:5173
  2. Enter MCP server URL
  3. Click "Connect"
  4. Use "List Tools" to see available tools
  5. Test tool calls with parameters

Deploy to Cloudflare

# First time: Login
npx wrangler login

# Deploy
npx wrangler deploy

# Check deployment
npx wrangler tail

Your server is live at:

https://my-mcp-server.YOUR_ACCOUNT.workers.dev/sse

Connect Claude Desktop

~/.config/claude/claude_desktop_config.json (Linux/Mac):

{
  "mcpServers": {
    "my-mcp": {
      "url": "https://my-mcp-server.your-account.workers.dev/sse"
    }
  }
}

%APPDATA%/Claude/claude_desktop_config.json (Windows)

With OAuth:

{
  "mcpServers": {
    "my-mcp": {
      "url": "https://my-mcp-oauth.your-account.workers.dev/sse",
      "auth": {
        "type": "oauth",
        "authorizationUrl": "https://my-mcp-oauth.your-account.workers.dev/authorize",
        "tokenUrl": "https://my-mcp-oauth.your-account.workers.dev/token"
      }
    }
  }
}

Restart Claude Desktop after config changes.


Common Patterns

API Proxy MCP Server

Use case: Wrap external API with MCP tools

Pattern:

this.server.tool(
  "search_wikipedia",
  "Search Wikipedia for a topic",
  { query: z.string() },
  async ({ query }) => {
    const response = await fetch(
      `https://en.wikipedia.org/api/rest_v1/page/summary/${encodeURIComponent(query)}`
    );
    const data = await response.json();

    return {
      content: [{
        type: "text",
        text: data.extract
      }]
    };
  }
);

Database-Backed Tools

Use case: Query D1, KV, or external databases

Pattern:

this.server.tool(
  "get_user",
  "Get user details from database",
  { userId: z.string() },
  async ({ userId }) => {
    // Query Durable Objects storage
    const user = await this.state.storage.get<User>(`user:${userId}`);

    // Or query D1 database
    const result = await env.DB.prepare(
      "SELECT * FROM users WHERE id = ?"
    ).bind(userId).first();

    return {
      content: [{
        type: "text",
        text: JSON.stringify(user || result, null, 2)
      }]
    };
  }
);

Multi-Tool Coordination

Use case: Tools that call other tools

Pattern:

// Store result from first tool
await this.state.storage.put("last_search", result);

// Second tool reads it
const lastSearch = await this.state.storage.get("last_search");

Caching Strategy

Use case: Cache expensive API calls

Pattern:

this.server.tool(
  "get_weather",
  "Get weather (cached 5 minutes)",
  { city: z.string() },
  async ({ city }) => {
    const cacheKey = `weather:${city}`;
    const cached = await this.state.storage.get<CachedWeather>(cacheKey);

    // Check cache freshness
    if (cached && Date.now() - cached.timestamp < 5 * 60 * 1000) {
      return {
        content: [{ type: "text", text: cached.data }]
      };
    }

    // Fetch fresh data
    const weather = await fetchWeatherAPI(city);

    // Cache it
    await this.state.storage.put(cacheKey, {
      data: weather,
      timestamp: Date.now()
    });

    return {
      content: [{ type: "text", text: weather }]
    };
  }
);

Rate Limiting with Durable Objects

Use case: Prevent abuse, respect upstream rate limits

Pattern:

async rateLimit(key: string, maxRequests: number, windowMs: number): Promise<boolean> {
  const now = Date.now();
  const requests = await this.state.storage.get<number[]>(`ratelimit:${key}`) || [];

  // Remove old requests outside window
  const recentRequests = requests.filter(ts => now - ts < windowMs);

  if (recentRequests.length >= maxRequests) {
    return false; // Rate limited
  }

  // Add this request
  recentRequests.push(now);
  await this.state.storage.put(`ratelimit:${key}`, recentRequests);

  return true; // Allowed
}

// Use in tool
if (!await this.rateLimit(userId, 10, 60 * 1000)) {
  return {
    content: [{ type: "text", text: "Rate limit exceeded (10 requests/minute)" }],
    isError: true
  };
}

15 Known Errors (With Solutions)

1. McpAgent Class Not Exported

Error: TypeError: Cannot read properties of undefined (reading 'serve')

Cause: Forgot to export McpAgent class

Solution:

export class MyMCP extends McpAgent { ... }  // ✅ Must export
export default { fetch() { ... } }

2. Transport Mismatch

Error: Connection failed: Unexpected response format

Cause: Client expects /sse but server only serves /mcp

Solution: Serve both transports (see Transport Methods section)


3. OAuth Redirect URI Mismatch

Error: OAuth error: redirect_uri does not match

Cause: Client configured with localhost, but deployed to workers.dev

Solution: Update claude_desktop_config.json after deployment


4. WebSocket Hibernation State Loss

Error: Tool calls fail after reconnect with "state not found"

Cause: In-memory state cleared on hibernation

Solution: Use this.state.storage instead of instance properties


5. Durable Objects Binding Missing

Error: Error: Cannot read properties of undefined (reading 'idFromName')

Cause: Forgot DO binding in wrangler.jsonc

Solution: Add binding (see Stateful MCP Servers section)


6. Migration Not Defined

Error: Error: Durable Object class MyMCP has no migration defined

Cause: First DO deployment requires migration

Solution:

{
  "migrations": [
    { "tag": "v1", "new_classes": ["MyMCP"] }
  ]
}

7. CORS Errors on Remote MCP

Error: Access to fetch at '...' blocked by CORS policy

Cause: MCP server doesn't return CORS headers

Solution: Use OAuthProvider (handles CORS) or add headers manually


8. Client Configuration Format Error

Error: Claude Desktop doesn't recognize server

Cause: Wrong JSON format in claude_desktop_config.json

Solution: See "Connect Claude Desktop" section for correct format


9. serializeAttachment() Not Used

Error: WebSocket metadata lost on hibernation wake

Cause: Not using serializeAttachment()

Solution: See WebSocket Hibernation section


10. OAuth Consent Screen Disabled

Security risk: Users don't see permissions

Cause: allowConsentScreen: false in production

Solution: Always set allowConsentScreen: true in production


11. JWT Signing Key Missing

Error: Error: JWT_SIGNING_KEY environment variable not set

Cause: OAuth Provider requires signing key

Solution:

openssl rand -base64 32
# Add to wrangler.jsonc vars

12. Environment Variables Not Configured

Error: env.MY_VAR is undefined

Cause: Variables in .dev.vars but not in wrangler.jsonc

Solution: Add to "vars" section in wrangler.jsonc


13. Tool Schema Validation Error

Error: ZodError: Invalid input type

Cause: Client sends string, schema expects number

Solution: Use Zod transforms:

z.string().transform(val => parseInt(val, 10))

14. Multiple Transport Endpoints Conflicting

Error: /sse returns 404 after adding /mcp

Cause: Incorrect path matching

Solution: Use startsWith() or exact matches


15. Local Testing with Miniflare Limitations

Error: OAuth flow fails in local dev

Cause: Miniflare doesn't support all DO features

Solution: Use npx wrangler dev --remote for full DO support


Configuration Reference

Complete wrangler.jsonc (All Features)

{
  "name": "my-mcp-server",
  "main": "src/index.ts",
  "compatibility_date": "2025-01-01",
  "compatibility_flags": ["nodejs_compat"],
  "account_id": "YOUR_ACCOUNT_ID",

  "vars": {
    "ENVIRONMENT": "production",
    "GITHUB_CLIENT_ID": "optional-pre-configured-id"
  },

  "kv_namespaces": [
    {
      "binding": "OAUTH_KV",
      "id": "YOUR_KV_ID",
      "preview_id": "YOUR_PREVIEW_KV_ID"
    }
  ],

  "durable_objects": {
    "bindings": [
      {
        "name": "MY_MCP",
        "class_name": "MyMCP",
        "script_name": "my-mcp-server"
      }
    ]
  },

  "migrations": [
    { "tag": "v1", "new_classes": ["MyMCP"] }
  ],

  "node_compat": true
}

Complete package.json

See templates/package.json

Complete claude_desktop_config.json

See templates/claude_desktop_config.json


Additional Resources

Official Documentation

Official Examples

Tools


When NOT to Use This Skill

Don't use this skill when:

  • Building Python MCP servers (use fastmcp skill instead)
  • Building local-only MCP servers (use typescript-mcp skill)
  • You need non-Cloudflare hosting (AWS Lambda, GCP, etc.)
  • You're working with Claude.ai web interface skills (different from MCP)

Use this skill specifically for: TypeScript + Cloudflare Workers + Remote MCP


Version Information

  • @modelcontextprotocol/sdk: 1.21.0
  • @cloudflare/workers-oauth-provider: 0.0.13
  • agents (Cloudflare Agents SDK): 0.2.20
  • Last Verified: 2025-11-04

Production tested: Based on Cloudflare's official MCP servers (mcp-server-cloudflare, workers-mcp)


Token Efficiency

Without this skill:

  • Research scattered docs: ~10k tokens
  • Debug 15 errors: ~30k tokens
  • Total: ~40k tokens

With this skill:

  • Read skill: ~4k tokens
  • Copy templates: ~1k tokens
  • Total: ~5k tokens

Savings: ~87% (40k → 5k tokens)

Errors prevented: 15 (100% prevention rate)


Questions? Check:

  • references/authentication.md - Auth patterns comparison
  • references/transport.md - SSE vs HTTP technical details
  • references/oauth-providers.md - GitHub, Google, Azure setup
  • references/common-issues.md - Error troubleshooting deep-dives
  • references/official-examples.md - Curated links to Cloudflare examples

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

29.61%
按下载量换算60

windsurf

26.22%
按下载量换算53

OpenCode

19.37%
按下载量换算39

Codex

11.97%
按下载量换算24

Antigravity

7.37%
按下载量换算15

Gemini CLI

3.76%
按下载量换算8

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

可疑

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。

来源信息

继续浏览同类 Skills