Back to MCP directory
publicPublicdnsLocal runtime

ai-powered-image-generation-worker

该项目利用MCP协议、Cloudflare和Resend API构建AI邮件助手,实现自动撰写、发送和管理邮件,大幅减少人工处理时间。

article

README

🚀 电子邮件革命:利用MCP、Resend和Cloudflare实现AI数字员工

使用智能AI驱动的电子邮件助理消除收件箱过载

🚀 快速开始

本项目打造了一款智能电子邮件数字员工,借助Model Context Protocol(MCP)、Cloudflare Durable Objects以及Resend电子邮件API,该数字员工可自主编写、发送和管理电子邮件,能大幅减少团队处理邮件任务所耗费的时间。

✨ 主要特性

解决电子邮件难题

专业人士平均每天会将28%的工作时间(每周超11小时)用于处理收件箱,高管这一比例更是接近40%。此电子邮件数字员工解决方案能帮您挽回这些被浪费的时间,具体体现如下:

  • 自主编写和发送电子邮件:生成贴合上下文的邮件内容。
  • 智能处理通信:智能处理收件。
  • 维护整个对话线程的上下文
  • 全天候24/7运行,无需人工监督

关键技术优势

本项目运用了三种强大的技术:

  1. MCP(模型上下文协议):让AI模型可直接与应用程序和服务交互。
  2. Cloudflare Durable Objects:提供有状态的无服务器计算,并支持高效休眠。
  3. Resend电子邮件API:实现可靠、可追踪的电子邮件通信。

功能亮点

  • AI驱动的电子邮件编写:生成与上下文相关的邮件内容。
  • 自主发送:无需人工干预即可安排和发送邮件。
  • 有状态会话:在多次交互中维护上下文。
  • 成本效益:支持休眠,仅在活动处理时付费。
  • 企业级安全性:具备bearer令牌身份验证和安全的API集成。
  • 全面日志记录:详细记录活动,便于监控和调试。

💻 使用示例

基础用法

该实现的核心是一个使用Durable Objects维护状态的MCP服务器,以下是核心代码:

import { McpAgent } from "agents/mcp";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { Resend } from "resend";

// 定义数字员工
export class EmailWorker extends McpAgent<Bindings, State, Props> {
  server = new McpServer({
    name: "EmailAssistant",
    version: "1.0.0",
  });

  async init() {
    // 设置电子邮件发送功能
    this.server.tool(
      "sendEmail",
      {
        to: z.string().email(),
        subject: z.string(),
        body: z.string()
      },
      async ({ to, subject, body }) => {
        try {
          const resend = new Resend(this.env.API_KEY);
          const { data, error } = await resend.emails.send({
            from: "your-brand@company.com",
            to,
            subject,
            text: body,
          });

          if (error) {
            return { content: [{ type: "text", text: `失败: ${error.message}` }] };
          }

          return { content: [{ type: "text", text: `电子邮件发送成功!` }] };
        } catch (err) {
          return { content: [{ type: "text", text: `错误: ${err.message}` }] };
        }
      }
    );
  }
}
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client