cf-worker -template
Một skeleton đầy đủ để bạn bắt đầu nhanh với Cloudflare Workers: routes, utils, services, bindings (KV/D1/R2), Durable Objects, cron.
claude mcp add --transport stdio pnstack-cf-worker-mcp-template node src/index.ts \ --env CF_API_TOKEN="Cloudflare API token if deploying via Wrangler" \ --env CF_ACCOUNT_ID="Cloudflare account ID" \ --env WRANGLER_CONFIG="Optional: path to wrangler.toml or Wrangler config"
How to use
This MCP server template provides a Cloudflare Workers-based implementation that exposes an MCP (Streamable HTTP) endpoint at POST /mcp. It includes tools scaffolding (e.g., hello and api tools) that can be scaffolded and invoked through the MCP protocol. The template also demonstrates how to enable OpenAI-compatible embeddings and various Cloudflare bindings (KV, D1, R2, Durable Objects, and AI integrations). To interact with the MCP, initialize the session with a JSON-RPC 2.0 payload, list available tools, and call a specific tool by name with its arguments. If you request an event-stream response (Accept: text/event-stream), the server will emit SSE data for real-time updates during tool execution.
How to install
Prerequisites:
- Node.js v18 or later
- npm (comes with Node.js)
- Wrangler CLI for Cloudflare Workers (optional if deploying directly with other tooling): npm i -g wrangler
Installation steps:
- Clone or download the repository template.
- Install dependencies: npm install
- (Optional) Configure Wrangler for Cloudflare Workers by creating or editing wrangler.toml with your account and zone details.
- Run in development mode: npm run dev
- Deploy to Cloudflare Workers: npm run deploy
Notes:
- If you plan to use bindings (KV, D1, R2, DO, AI), ensure they are configured in wrangler.toml and enabled in the Cloudflare dashboard.
- Set necessary secrets such as CF_API_TOKEN and CF_ACCOUNT_ID when deploying or running authenticated operations.
Additional notes
Tips and common considerations:
- The template supports multiple MCP tools (e.g., hello, api). Use the tool scaffold and tool invocation patterns shown in the README to add or call tools via JSON-RPC.
- When enabling OpenAI embeddings, provide OPENAI_API_KEY as an environment variable and use the /v1/embeddings endpoints through the server's route (with proper baseURL pointing to the local or remote endpoint).
- If you do not enable certain bindings (KV/D1/R2/DO), keep the related sections commented in wrangler.toml to avoid deployment errors.
- For local testing, you can simulate the MCP calls using standard JSON-RPC payloads shown in the README (initialize, tools/list, tools/call).
- Ensure compatibility_date is updated periodically to use the latest API surface.
- If using SSE responses, set Accept: text/event-stream on the request and handle streaming data on the client side.
Related MCP Servers
mcp
MCP server for the Cloudflare API
MiniMax -JS
Official MiniMax Model Context Protocol (MCP) JavaScript implementation that provides seamless integration with MiniMax's powerful AI capabilities including image generation, video generation, text-to-speech, and voice cloning APIs.
MCP -Starter
A Model Context Protocol server starter template
ez
The easiest path to getting an MCP server going
google -remote
Collection of Google-native tools (e.g., Gmail, Calendar) for the MCP
canlii
canlii mcp for people in law in canada