MCP Server with Cloudflare Workers
带有 Cloudflare Workers 的 MCP 服务器
介绍
模型上下文协议 (MCP) 是一项开放标准,支持 AI 代理和助手与服务进行交互。通过设置 MCP 服务器,您可以允许 AI 助手直接访问您的 API。
Cloudflare Workers 与workers-mcp包相结合,为构建 MCP 服务器提供了强大且可扩展的解决方案。
Related MCP server: Remote MCP Server
先决条件
在开始之前,请确保您已:
Node.js 已安装
已安装 Wrangler CLI(
npm install -g wrangler)
入门
步骤 1:创建新的 Cloudflare Worker
首先,初始化一个新的 Cloudflare Worker 项目:
npx create-cloudflare@latest my-mcp-worker
cd my-mcp-worker然后,验证您的 Cloudflare 帐户:
wrangler login步骤2:配置Wrangler
使用正确的帐户详细信息更新您的wrangler.toml文件:
name = "my-mcp-worker"
main = "src/index.ts"
compatibility_date = "2025-03-03"
account_id = "your-account-id"安装 MCP 工具
要启用 MCP 支持,请安装workers-mcp包:
npm install workers-mcp运行设置命令来配置 MCP:
npx workers-mcp setup这将:
添加必要的依赖项
设置本地代理进行测试
配置 Worker 以符合 MCP 要求
编写 MCP 服务器代码
更新您的src/index.ts以定义您的 MCP 服务器:
import { WorkerEntrypoint } from 'cloudflare:workers';
import { ProxyToSelf } from 'workers-mcp';
export default class MyWorker extends WorkerEntrypoint<Env> {
/**
* A friendly greeting from your MCP server.
* @param name {string} The name of the user.
* @return {string} A personalized greeting.
*/
sayHello(name: string) {
return `Hello from an MCP Worker, ${name}!`;
}
/**
* @ignore
*/
async fetch(request: Request): Promise<Response> {
return new ProxyToSelf(this).fetch(request);
}
}关键组件:
WorkerEntrypoint :管理传入的请求和方法暴露。
ProxyToSelf :确保符合 MCP 协议。
sayHello 方法:AI 助手可以调用的示例 MCP 函数。
添加 API 调用
您可以通过集成外部 API 来扩展您的 MCP 服务器。以下是获取天气数据的示例:
export default class WeatherWorker extends WorkerEntrypoint<Env> {
/**
* Fetch weather data for a given location.
* @param location {string} The city or ZIP code.
* @return {object} Weather details.
*/
async getWeather(location: string) {
const response = await fetch(`https://api.weather.example/v1/${location}`);
const data = await response.json();
return {
temperature: data.temp,
conditions: data.conditions,
forecast: data.forecast
};
}
async fetch(request: Request): Promise<Response> {
return new ProxyToSelf(this).fetch(request);
}
}部署 MCP 服务器
设置好 Worker 后,将其部署到 Cloudflare:
npx wrangler deploy部署后,您的 Worker 即可上线,并且 AI 助手可以发现并使用您的 MCP 工具。
要更新您的 MCP 服务器,请使用以下命令重新部署:
npm run deploy测试 MCP 服务器
要在本地测试您的 MCP 设置:
npx workers-mcp proxy此命令启动本地代理,允许 MCP 客户端(如 Claude Desktop)连接。
安全
为了保护您的 MCP 服务器,请使用 Wrangler Secrets:
npx wrangler secret put MCP_SECRET这增加了一个共享秘密认证机制来防止未经授权的访问。
结论
恭喜!您已成功使用 Cloudflare Workers 构建并部署 MCP 服务器。现在您可以扩展其功能,并为 AI 助手提供新的工具。
有关更多详细信息,请查看Cloudflare MCP 文档。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Cloudflare Workers MCP server: ai-model-router
The Telnyx MCP server is an official implementation of the Model Context Protocol that enables AI clients (like Claude Desktop, Cursor, and OpenAI Agents) to interact with Telnyx's telephony, messaging, and AI assistant APIs. It provides comprehensive capabilities including making and managing phone calls, sending SMS/MMS messages, purchasing and configuring phone numbers, creating AI assistants with custom instructions, managing cloud storage buckets, scraping and embedding website content, and handling integration secrets. The server exists as both a local implementation and a remotely hosted version, allowing developers to integrate real-world communication infrastructure directly into AI applications.
Related MCP Servers
AlicenseNot gradedqualityFmaintenanceA server that implements the Model Context Protocol (MCP) on Cloudflare Workers, allowing AI models to access custom tools without authentication.151MIT- FlicenseNot gradedqualityDmaintenanceA deployable Model Context Protocol server for Cloudflare Workers that enables AI models to use custom tools without authentication requirements.
- FlicenseNot gradedqualityCmaintenanceA serverless implementation of Model Context Protocol on Cloudflare Workers that enables connecting AI assistants like Claude to custom tools without authentication.
- FlicenseNot gradedqualityCmaintenanceA deployable Model Context Protocol server on Cloudflare Workers that enables AI tools integration without authentication requirements.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/sivakumarl/my-mcp-worker'
If you have feedback or need assistance with the MCP directory API, please join our Discord server