Lightweight Cloudflare Worker MCP server

Lightweight Cloudflare Workers-based MCP server implementation that enables custom API interactions with a basic greeting functionality, easily extendable for integration with external services.
Back to servers
Setup instructions
Provider
Sivakumar L
Release date
Mar 21, 2025
Language
TypeScript

This MCP server implementation allows AI assistants to interact with your services through the Model Context Protocol standard. Cloudflare Workers provide a scalable platform for hosting these MCP servers.

Prerequisites

Before starting, ensure you have:

Setting Up Your MCP Server

Create a New Cloudflare Worker

First, initialize a new Cloudflare Worker project:

npx create-cloudflare@latest my-mcp-worker
cd my-mcp-worker

Then, authenticate your Cloudflare account:

wrangler login

Configure Wrangler

Update your wrangler.toml file with the correct account details:

name = "my-mcp-worker"
main = "src/index.ts"
compatibility_date = "2025-03-03"
account_id = "your-account-id"

Installing MCP Support

Install the workers-mcp package to enable MCP functionality:

npm install workers-mcp

Run the setup command to configure MCP:

npx workers-mcp setup

This will add necessary dependencies, set up a local proxy for testing, and configure the Worker for MCP compliance.

Implementing Your MCP Server

Update your src/index.ts with the following code to define a basic MCP server:

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);
  }
}

Adding API Integration

You can extend your MCP server by integrating with external APIs:

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);
  }
}

Deployment and Testing

Deploy to Cloudflare

Deploy your MCP server to Cloudflare:

npx wrangler deploy

After deployment, your Worker is live and AI assistants can discover and use your MCP tools.

Test Locally

To test your MCP setup locally:

npx workers-mcp proxy

This starts a local proxy allowing MCP clients (like Claude Desktop) to connect to your server.

Security

Secure your MCP server by adding a shared secret:

npx wrangler secret put MCP_SECRET

This adds authentication to prevent unauthorized access to your MCP server.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "my-mcp-worker" '{"command":"npx","args":["workers-mcp","proxy"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "my-mcp-worker": {
            "command": "npx",
            "args": [
                "workers-mcp",
                "proxy"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "my-mcp-worker": {
            "command": "npx",
            "args": [
                "workers-mcp",
                "proxy"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later