Built-in authentication for EdgeFastMCP is planned for a future release. Both FastMCP and EdgeFastMCP use Hono internally, so there’s no technical barrier—EdgeFastMCP was simply written before OAuth was added to FastMCP.In the meantime, use Hono middleware:
import { EdgeFastMCP } from "fastmcp/edge";import { z } from "zod";const server = new EdgeFastMCP({ name: "My Edge Server", version: "1.0.0", description: "MCP server running on Cloudflare Workers",});// Add tools, resources, prompts as usualserver.addTool({ name: "greet", description: "Greet someone", parameters: z.object({ name: z.string(), }), execute: async ({ name }) => { return `Hello, ${name}! Served from the edge.`; },});// Export the server as the default (required for Cloudflare Workers)export default server;
Here’s a complete example from the FastMCP repository:
src/examples/edge-cloudflare-worker.ts
import { EdgeFastMCP } from "fastmcp/edge";import { z } from "zod";// Create the edge-compatible MCP serverconst server = new EdgeFastMCP({ description: "An MCP server running on Cloudflare Workers", name: "CloudflareWorkerMCP", version: "1.0.0",});// Add a simple toolserver.addTool({ description: "Greet someone by name", execute: async ({ name }) => { return `Hello, ${name}! This response is from a Cloudflare Worker.`; }, name: "greet", parameters: z.object({ name: z.string().describe("The name to greet"), }),});// Add a tool that returns structured contentserver.addTool({ description: "Get weather information for a location", execute: async ({ location }) => { // In a real app, you would call a weather API here return { content: [ { text: `Weather for ${location}:\n- Temperature: 72°F\n- Conditions: Sunny\n- Humidity: 45%`, type: "text", }, ], }; }, name: "get_weather", parameters: z.object({ location: z.string().describe("The city or location"), }),});// Add a static resourceserver.addResource({ description: "Information about this MCP server", load: async () => { return "This is a FastMCP server running on Cloudflare Workers edge runtime."; }, mimeType: "text/plain", name: "Server Info", uri: "info://server",});// Add a prompt templateserver.addPrompt({ arguments: [ { description: "Programming language", name: "language", required: true }, { description: "What to focus on (optional)", name: "focus", required: false, }, ], description: "Generate a prompt to analyze code", load: async (args) => { const focus = args.focus ? ` focusing on ${args.focus}` : ""; return { messages: [ { content: { text: `Please analyze the following ${args.language} code${focus}:`, type: "text", }, role: "user", }, ], }; }, name: "analyze_code",});// Export the server as the default (Cloudflare Workers format)export default server;