mcpField
D
Discord Notification MCP Server

Discord Notification MCP Server

本地服务
github.com/kstonekuan通信协作870 周前更新

关于 Discord Notification MCP Server

Discord Notification MCP Server 会在 Claude Code 完成任务、遇到错误或需要输入时向 Discord 发送通知。它基于 TypeScript 和 Cloudflare Agents SDK 构建,支持 SSE 与 Streamable HTTP。

主要功能

  1. 01通过 `send_discord_message` 发送消息
  2. 02支持嵌入内容、TTS 和提及控制
  3. 03支持 SSE 与 Streamable HTTP 传输
  4. 04使用 Cloudflare secrets 保存 Webhook 凭据
  5. 05部署到 Cloudflare Workers

适用场景

  1. 01Claude Code 完成任务时通知 Discord
  2. 02将执行错误报告到 Discord
  3. 03通过 Discord 通知请求用户输入
  4. 04发送带格式的构建或状态更新

MCP 相关

该 MCP 服务提供 `send_discord_message` 工具,用于发送 Discord 通知。MCP 客户端可通过 SSE 或 Streamable HTTP 连接。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"discord-notification": {
"command": "npx",
"args": [
"-y",
"wrangler"
]
}
}
}
启动命令npx -y wrangler

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npmwrangler

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

Discord 通知 MCP 服务

Discord MCP 徽标

一个 MCP(模型上下文协议)服务,可在 Claude Code 完成任务时向 Discord 发送通知。使用 TypeScript 和 Cloudflare Agents SDK 构建,可部署在 Cloudflare Workers 上。

功能

  • 🤖 MCP 工具:提供用于发送通知的 send_discord_message 工具
  • 🚀 Cloudflare Workers:以无服务器方式运行,并提供全球分发
  • 🔐 安全:使用 Cloudflare 密钥存储凭据
  • 🌐 双传输方式:同时支持 SSE 和 Streamable HTTP,确保最大兼容性
  • 💾 Durable Objects:提供 McpAgent 所需的状态管理
  • 💬 丰富格式:支持嵌入内容、TTS 消息和提及控制

架构

此服务使用 Cloudflare 的 Agents SDK 实现 MCP 规范:

  • GET /sse:用于 MCP 通信的 SSE 端点
  • POST /mcp:用于 MCP 通信的 Streamable HTTP 端点
  • 使用 TypeScript、MCP SDK 和 Cloudflare Agents SDK 构建
  • 完善的 JSON-RPC 2.0 错误处理
  • 使用 Durable Objects 管理有状态连接(McpAgent 所需)
  • 已启用 Node.js 兼容模式

设置

前置条件
  1. Discord Webhook:在 Discord 频道中创建 webhook:
    • 右键点击频道 → 编辑频道 → 整合 → Webhooks
    • 点击“新建 Webhook”并复制 webhook URL
  2. Cloudflare 账户:在 cloudflare.com 注册
安装
  1. 克隆此代码库
  2. 安装依赖项:
    pnpm install
    
配置
  1. 根据示例创建 .dev.vars 文件:

    cp .dev.vars.example .dev.vars
    

    然后在 .dev.vars 中填写你的 webhook URL。此文件用于本地开发和部署。

  2. 对于生产环境部署,请设置 Cloudflare 密钥:

    npx wrangler secret put WEBHOOK_URL
    
  3. 如有需要,更新 wrangler.toml 中的 Worker 名称

部署

部署到 Cloudflare Workers:

# First set secrets
npx wrangler secret put WEBHOOK_URL

# Then deploy
pnpm run deploy

替代方案:持续部署

你也可以直接在 Cloudflare 控制面板中设置持续部署。 了解更多关于 Cloudflare 的 Git 集成 的信息。

Claude Code 配置

通过 SSE 传输方式使用 CLI 将 MCP 服务添加到 Claude Code:

# For production deployment (SSE)
claude mcp add discord-notify https://your-worker-name.workers.dev/sse -t sse

# For local development
claude mcp add discord-notify http://localhost:8787/sse -t sse

注意:此服务同时支持 SSE(服务器发送事件)和 Streamable HTTP 传输方式。SSE 表现良好,而 Streamable HTTP 可靠性更高,也是较新的标准。

你可以通过以下命令验证配置:

claude mcp list

使用

配置完成后,Claude Code 可在你需要时向 Discord 发送通知。

可用工具

send_discord_message:向 Discord 发送通知消息

  • content(必填):要发送的消息内容
  • tts(可选):以文本转语音消息的形式发送
  • embeds(可选):用于丰富格式的嵌入对象数组
  • allowed_mentions(可选):控制要解析哪些提及

使用示例:

// Simple message
await send_discord_message({ content: "Task completed!" })

// Rich embed message
await send_discord_message({ 
  content: "Status Update",
  embeds: [{
    title: "Build Results",
    description: "All tests passed",
    color: 5025616, // Green
    fields: [
      { name: "Tests", value: "52/52", inline: true },
      { name: "Duration", value: "2m 34s", inline: true }
    ]
  }]
})
何时会收到通知

在以下情况下,Claude Code 会发送通知:

  • 你明确提出要求,例如:“完成后通知我”或“在 Discord 上告诉我”
  • 执行过程中发生错误
  • 到达重要里程碑
  • 需要用户输入或干预
使用场景示例
# You say: "Deploy to production and notify me when done"
# Result: 🤖 Claude Code Notification
#         Deployment completed successfully! The app is now live.

# You say: "Run all tests and let me know the results"
# Result: 🤖 Claude Code Notification
#         All tests passed! 52/52 tests successful.

# You say: "Process this data and notify me if there are any errors"
# Result: 🤖 Claude Code Notification
#         Error: Failed to process row 451 - invalid date format
通知示例
Discord 通知示例

Claude Code 发送的 Discord 通知示例

Claude Code 集成示例

Claude Code 在任务完成期间发送通知

CLAUDE.md 示例

为了鼓励 Claude Code 有效使用 Discord 通知,请将以下内容添加到 CLAUDE.md:

# Discord Notifications

Use the mcp__discord-notify__send_discord_message tool to send notifications to Discord.

- Always send a Discord notification when:
  - A task is fully complete
  - You need user input to continue
  - An error occurs that requires user attention
  - The user explicitly asks for a notification (e.g., "notify me", "send me a message", "let me know")

- Include relevant details in notifications:
  - For builds/tests: success/failure status and counts
  - For errors: the specific error message and file location

- Use concise, informative messages like:
  - "✅ Build completed successfully (2m 34s)"
  - "❌ Tests failed: 3/52 failing in auth.test.ts"
  - "⚠️ Need permission to modify /etc/hosts"

开发

在本地运行:

# Start local development server
pnpm dev

在本地开发时,Wrangler 会自动从 .dev.vars 文件加载环境变量。

部署前运行所有检查:

pnpm build

此命令会运行:

  1. pnpm format - 使用 Biome 格式化代码
  2. pnpm lint:fix - 修复 lint 问题
  3. pnpm cf-typegen - 生成 Cloudflare 类型
  4. pnpm type-check - 检查 TypeScript 类型

测试服务:

# Test SSE connection
curl http://localhost:8787/sse

# Test health endpoint
curl http://localhost:8787/

调试

测试 SSE 连接

你可以直接测试 SSE 端点:

curl -N http://localhost:8787/sse

这应该会返回一个以 endpoint 事件开头的事件流。

常见问题
  1. 连接立即关闭:检查你的 worker 是否正在运行,并且可以通过指定的 URL 访问。

  2. 未收到 endpoint 事件:确保正确发送 SSE 标头,并且事件流格式正确。

  3. 未发送 Discord 通知:确认 worker 环境中已正确设置 WEBHOOK_URL。

技术详情

  • 语言:TypeScript(目标版本 ES2021)
  • 运行时:兼容 Node.js 的 Cloudflare Workers
  • 协议:MCP(Model Context Protocol)
  • 传输方式:SSE 和 Streamable HTTP
  • 状态管理:Durable Objects(McpAgent 所必需)
  • 可观测性:已启用监控

参考资料

本项目参考以下指南构建:

相关项目

许可证

MIT

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。