Labsco
cloudflare logo

Workers MCP

βœ“ Officialβ˜… 643

from cloudflare

An MCP transport for interacting with your own Cloudflare Worker.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeQuick setup

workers-mcp

Talk to a Cloudflare Worker from Claude Desktop!

[!WARNING] You should start here instead β€” and build a remote MCP server

You can connect to remote MCP servers from Claude Desktop, Cursor, and other clients using mcp-remote.

What is workers-mcp?

This package provides both the CLI tooling and the in-Worker logic to connect Claude Desktop (or any MCP Client) to a Cloudflare Worker on your account, so you can customise it to suit your needs. It works via a build step that can translate TypeScript methods of your Worker like this:

Copy & paste β€” that's it
export class ExampleWorkerMCP extends WorkerEntrypoint {
 /**
 * Generates a random number. This is extra random because it had to travel all the way to
 * your nearest Cloudflare PoP to be calculated which... something something lava lamps?
 *
 * @return {string} A message containing a super duper random number
 * */
 async getRandomNumber() {
 return `Your random number is ${Math.random()}`
 }
 
 // ...etc
}

...into MCP tools that a local Node.js server can expose to MCP clients. The Node.js server acts as a proxy, handling stdio transport locally, and calling the relevant method of your Worker running on Cloudflare. This allows you to expose any function or API in your app, or any service in Cloudflare's developer platform, back to a LLM in your coding agent, Claude Desktop or other MCP client.

Yes, I know that Math.random() works the same on a Worker as it does on your local machine, but don't tell Claude 🀫

Using with Other MCP Clients

Cursor

To get your Cloudflare MCP server working in Cursor, you need to combine the 'command' and 'args' from your config file into a single string and use type 'command'.

For example, if your config file looks like:

Copy & paste β€” that's it
{
 "mcpServers": {
 "your-mcp-server-name": {
 "command": "/path/to/workers-mcp",
 "args": [
 "run",
 "your-mcp-server-name",
 "https://your-server-url.workers.dev",
 "/path/to/your/project"
 ],
 "env": {}
 }
 }
}

In Cursor, create an MCP server entry with:

  • type: command

  • command: /path/to/workers-mcp run your-mcp-server-name https://your-server-url.workers.dev /path/to/your/project

Other MCP Clients

For Windsurf and other MCP clients, update your configuration file to include your worker so you could use the tools directly from the client:

Copy & paste β€” that's it
{
 "mcpServers": {
 "your-mcp-server-name": {
 "command": "/path/to/workers-mcp",
 "args": [
 "run",
 "your-mcp-server-name",
 "https://your-server-url.workers.dev",
 "/path/to/your/project"
 ],
 "env": {}
 }
 }
}

Make sure to replace the placeholders with your actual server name, URL, and project path.

Examples

See the examples directory for a few ideas of what to use this for:

  • examples/01-hello-world is a snapshot taken after the installation instructions above

  • examples/02-image-generation uses Workers AI to run the Flux image generation model. Claude is really good at suggesting prompts and can actually interpret the outcome and decide what new prompts to try to achieve the outcome you want.

  • TODO Browser Rendering

  • TODO Durable Objects