Jun 24, 2025

Madhav Meda
Cloudflare Workers:
Cloudflare Workers is a serverless, globally distributed execution environment that allows developers to run their code on Cloudflare's edge network, allowing for faster response times and improved performance. Cloudflare Workers support running JavaScript, TypeScript, or WASM code close to your users, without managing or scaling servers.
Deploying MCP servers on Cloudflare Workers gives you ultra-low-latency, global access to context data right at the edge. It simplifies security and operations by leveraging built-in features like rate limiting, auth, and seamless integration with other Cloudflare services. Plus, it’s cost-effective and scales automatically with minimal overhead.
In this guide, we’ll cover step-by-step instructions on how to tackle this, so you’ll be deploying MCP servers to Cloudflare Workers in no time.
Before You Start: Verify Node.js Compatibility
Cloudflare workers run on a lightweight, V8-based runtime environment, rather than a full Node.js runtime. As a result, barebones Workers cannot directly execute Node.js APIs. Cloudflare instead provides support for a subset of Node.js APIs that allow you to use several Node.js libraries within workers. For a list of supported Node.js APIs, refer to https://developers.cloudflare.com/workers/runtime-apis/nodejs/.
Deploying a MCP Server to Workers
This guide provides steps to deploy Javascript & Typescript based MCP Servers built using @modelcontextprotocol/sdk on Cloudflare Workers.
1. Install Wrangler CLI:
Wrangler is Cloudflare’s CLI tool for developing & deploying onto Cloudflare Workers.
2. Install Cloudflare’s Agent SDK:
Cloudflare’s Agent SDK is a package that allows you to run AI Agents and MCP servers on Cloudflare Workers.
3. Write a Worker’s Script:
Cloudflare Worker requires a script that acts as the entry point to the MCP Server. The worker’s script is characterized by 2 parts:
A class that extends the MCPAgent class from the Agents SDK
An ESModule that handles the incoming requests to the Worker
Below is an example worker’s script that enables us to serve the MCP Server. Place the worker script wherever it is most appropriate in your project structure.
4. Create the wrangler config file:
In your project root folder, create a file called wrangler.jsonc, which includes the information required for deploying & running the MCP Server on Cloudflare Workers.
Refer to Cloudflare Docs for Wrangler Configuration for more details.
After making the changes to the config file, run the following command. This will generate & inject the Cloudflarecloudflare types required to run the Worker.
Note: Ensure that you run npx wrangler types each time you modify the wrangler config file so that the Cloudflare types are accessible in your project.
Secrets as Environment Variables:
The environment variables defined as part of the wrangler config file are processed as-is and are stored as plain text, which is a significant security risk. Instead, Cloudflare offers the following options to provide secrets as environment variables to the workers:
For Locally Hosted Workers:
Create .dev.vars file in the root directory
List each sensitive field per line in the format shown below
For Deployed Workers:
Execute the following command as shown below in the command line. Enter the secret’s value when prompted. This will add the secret as an environment variable to the deployed worker. Cloudflare will treat it as a sensitive field & store it securely.
5. Test Cloudflare Worker locally:
Wrangler provides the feature to run your Cloudflare worker locally to test out before deploying. The following command starts the worker locally:
The output will display the local URL where your Worker is being served.
Additionally, you can test the connection to MCP Server using the MCP Inspector tool. It is a visual tool for testing & debugging MCP Servers. Execute the following commands to install & run the tool.
Open a browser and navigate to the domain where the MCP Inspector tool is hosted. Select the transport type of your MCP Server you want to connect to, and enter the domain where the MCP Server is hosted. Clicking "Connect" will allow you to perform queries against your locally hosted MCP Server.

6. Deploy onto Cloudflare Workers
Once you are confident that the Cloudflare Worker is running and the MCP Server is accessible via MCP Inspector, we can deploy the worker onto Cloudflare’s network using the following command.
After deployment, make a note of the URL where your Worker is hosted, as displayed in the output.
7. Configuration for AI Client
Finally, paste the below config in your favourite AI Client such as Claude desktop, Cursor, etc.
For SSE transport
For Streamable HTTP transport
8. What’s Next:
Authentication & Authorization for the deployed MCP Servers: https://developers.cloudflare.com/agents/guides/remote-mcp-server/#add-authentication