Workers MCP

Official

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Allows connecting Claude Desktop to a Cloudflare Worker, enabling custom functions to be executed on Cloudflare's edge network. Supports capabilities like running Workers AI for image generation and utilizing Durable Objects for state management.

  • Enables image generation through Workers AI using the Flux model, allowing Claude to suggest prompts and interpret the generated images.

workers-mcp

与 Claude Desktop 的 Cloudflare 工作人员交谈!

[!警告]
你应该从这里开始——构建一个远程MCP 服务器

您可以使用 mcp-remote从 Claude Desktop、Cursor 和其他客户端连接到远程 MCP 服务器。

workers-mcp是什么?

此软件包提供了 CLI 工具和 Worker 内部逻辑,用于将 Claude Desktop(或任何MCP 客户端)连接到您帐户中的 Cloudflare Worker,以便您可以根据自己的需求进行自定义。它通过一个构建步骤来工作,该步骤可以转换 Worker 的 TypeScript 方法,如下所示:

export class ExampleWorkerMCP extends WorkerEntrypoint<Env> { /** * 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 }

…转换为本地 Node.js 服务器可以向 MCP 客户端公开的 MCP 工具。Node.js 服务器充当代理,在本地处理 stdio 传输,并调用在 Cloudflare 上运行的 Worker 的相关方法。这允许您将应用程序中的任何函数或 API,或Cloudflare 开发者平台中的任何服务,公开回编码代理、Claude Desktop 或其他 MCP 客户端中的 LLM。

是的,我知道Math.random()在 Worker 上的工作方式与在本地机器上相同,但不要告诉 Claude 🤫

用法

步骤 1:生成新的 Worker

使用create-cloudflare生成一个新的 Worker。

npx create-cloudflare@latest my-new-worker

我建议选择一个Hello World工作者。

步骤 2:安装workers-mcp

cd my-new-worker # I always forget this bit npm install workers-mcp

步骤 3:运行setup命令

npx workers-mcp setup

注意:如果出现问题,请运行npx workers-mcp help

步骤 4..♾️:迭代

更改 Worker 代码后,您只需运行npm run deploy即可更新有关您的函数和实时 Worker 实例的 Claude 元数据。

但是,如果您更改方法的名称或其参数,或者添加或删除方法,Claude 将无法看到更新,直到您重新启动它。

您永远不需要重新运行npx workers-mcp install:claude ,但如果您想排除 Claude 配置作为错误来源,那么这样做是安全的。

与其他 MCP 客户端一起使用

光标

要让您的 Cloudflare MCP 服务器在 Cursor 中运行,您需要将配置文件中的“command”和“args”组合成一个字符串,并使用类型“command”。

例如,如果您的配置文件如下所示:

{ "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": {} } } }

在 Cursor 中,使用以下命令创建 MCP 服务器条目:

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

其他 MCP 客户端

对于 Windsurf 和其他 MCP 客户端,请更新您的配置文件以包含您的工作程序,以便您可以直接从客户端使用这些工具:

{ "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": {} } } }

确保用实际的服务器名称、URL 和项目路径替换占位符。

示例

请参阅examples目录,了解关于如何使用它的一些想法:

  • examples/01-hello-world是按照上述安装说明拍摄的快照
  • examples/02-image-generation使用 Workers AI 运行 Flux 图像生成模型。Claude 非常擅长提供提示,并且能够准确解读结果,并决定尝试哪些新的提示来实现你想要的结果。
  • TODO 浏览器渲染
  • TODO 持久对象
-
security - not tested
A
license - permissive license
-
quality - not tested

该软件包将 Claude Desktop 和其他 MCP 客户端连接到 Cloudflare Workers,从而可以通过模型上下文协议通过自然语言访问自定义功能。

  1. What is workers-mcp?
    1. Usage
      1. Step 1: Generate a new Worker
      2. Step 2: Install workers-mcp
      3. Step 3: Run the setup command
      4. Step 4..♾️: Iterating
    2. Using with Other MCP Clients
      1. Cursor
      2. Other MCP Clients
    3. Examples
      ID: p4eywjno1o