Get the FREE Ultimate OpenClaw Setup Guide →

cloudflare -template

Reusable template for creating serverless Model Context Protocol (MCP) servers with provider plugin system. Deploy to Cloudflare Workers, Vercel, or any edge runtime.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio mahmoudfazeli-cloudflare-mcp-template node src/worker.ts \
  --env CF_WORKER_ENV="development" \
  --env OAUTH_KV_NAMESPACE="OAuth KV namespace (set up via npm run setup-oauth)"

How to use

This MCP server template runs as a Cloudflare Workers project and exposes a provider plugin system that allows you to register and use MCP tools through a modular provider architecture. The included example provider offers basic ping/echo/status tooling out of the box, demonstrating how providers can be wired into the MCP server factory and how the MCP transport and runtime validate inputs and return consistent JSON-RPC responses. You can access the running server locally at http://localhost:8787/ once started, where you’ll see the example tools visible and invocable via the MCP API surface. The setup also includes OAuth 2.1 integration with dynamic client registration and KV-backed credential storage, enabling secure authentication flows in multi-environment deployments.

How to install

Prerequisites:

  • Node.js and npm installed
  • Wrangler (Cloudflare) CLI installed for local testing and deployment
  • git installed

Installation steps:

  1. Clone the template and prepare your project git clone https://github.com/mahmoudfazeli/cloudflare-mcp-template.git cd cloudflare-mcp-template mkdir ../your-mcp-project cp -r template/* ../your-mcp-project/ cd ../your-mcp-project/

  2. Configure project name in template files

    Replace placeholders in package.json and wrangler config if needed

    sed 's/{{PROJECT_NAME}}/your-project-name/g' package.json.template > package.json sed 's/{{PROJECT_NAME}}/your-project-name/g' wrangler.toml.template > wrangler.toml

  3. Install dependencies npm install

  4. Set up OAuth 2.1 infrastructure (creates KV namespaces) npm run setup-oauth

  5. Run locally for testing npm run dev

Optional for Cloudflare deployment:

  • Configure Wrangler with your Cloudflare account and environment settings
  • Deploy to Cloudflare Workers using Wrangler commands (e.g., wrangler publish)

Additional notes

Tips and common considerations:

  • The template uses a provider plugin system; to add your own provider, follow docs in docs/PROVIDERS.md and integrate your API client with the server factory pattern.
  • OAuth 2.1 integration relies on KV namespaces created by setup-oauth; ensure those namespaces are correctly provisioned in your Cloudflare account.
  • Environment naming supports multiple environments (development, staging, production) to align with the template’s recommended workflow.
  • When deploying, consider enabling CORS and configuring production security features as outlined in the template docs.
  • If you encounter local testing limits, verify that the local dev server (port 8787) is not blocked by firewall and that Wrangler is properly configured for local emulation.

Related MCP Servers

Sponsor this space

Reach thousands of developers