MCP Server with Cloudflare Workers
Servidor MCP con trabajadores de Cloudflare
Introducción
El Protocolo de Contexto de Modelo (MCP) es un estándar abierto que permite a los agentes y asistentes de IA interactuar con los servicios. Al configurar un servidor MCP, puede permitir que los asistentes de IA accedan directamente a sus API.
Cloudflare Workers, combinado con el paquete workers-mcp , proporciona una solución potente y escalable para crear servidores MCP.
Related MCP server: Remote MCP Server
Prerrequisitos
Antes de comenzar, asegúrese de tener:
Node.js instalado
CLI de Wrangler instalado (
npm install -g wrangler)
Empezando
Paso 1: Crear un nuevo trabajador de Cloudflare
Primero, inicialice un nuevo proyecto de Cloudflare Worker:
npx create-cloudflare@latest my-mcp-worker
cd my-mcp-workerLuego, autentica tu cuenta de Cloudflare:
wrangler loginPaso 2: Configurar Wrangler
Actualice su archivo wrangler.toml con los detalles de cuenta correctos:
name = "my-mcp-worker"
main = "src/index.ts"
compatibility_date = "2025-03-03"
account_id = "your-account-id"Instalación de herramientas MCP
Para habilitar la compatibilidad con MCP, instale el paquete workers-mcp :
npm install workers-mcpEjecute el comando de configuración para configurar MCP:
npx workers-mcp setupEsto hará lo siguiente:
Añadir las dependencias necesarias
Configurar un proxy local para realizar pruebas
Configurar el trabajador para el cumplimiento de MCP
Escritura de código de servidor MCP
Actualice su src/index.ts para definir su servidor 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);
}
}Componentes clave:
WorkerEntrypoint : administra las solicitudes entrantes y la exposición del método.
ProxyToSelf : garantiza el cumplimiento del protocolo MCP.
Método sayHello : una función MCP de ejemplo que los asistentes de IA pueden llamar.
Agregar llamadas API
Puedes ampliar tu servidor MCP integrándolo con API externas. Aquí tienes un ejemplo de obtención de datos meteorológicos:
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);
}
}Implementación del servidor MCP
Una vez configurado tu Worker, impleméntalo en Cloudflare:
npx wrangler deployDespués de la implementación, su Worker estará activo y los asistentes de IA podrán descubrir y usar sus herramientas MCP.
Para actualizar su servidor MCP, vuelva a implementarlo con:
npm run deployPrueba del servidor MCP
Para probar su configuración de MCP localmente:
npx workers-mcp proxyEste comando inicia un proxy local que permite que los clientes MCP (como Claude Desktop) se conecten.
Seguridad
Para proteger su servidor MCP, utilice Wrangler Secrets:
npx wrangler secret put MCP_SECRETEsto agrega un mecanismo de autenticación de secreto compartido para evitar el acceso no autorizado.
Conclusión
¡Felicitaciones! Has creado e implementado correctamente un servidor MCP con Cloudflare Workers. Ahora puedes ampliarlo con más funciones y ofrecer nuevas herramientas para asistentes de IA.
Para obtener más detalles, consulte la documentación de 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