Skip to main content
Glama
Manojbonthu

notifications-mcp

by Manojbonthu

notifications-mcp

统一通知 MCP 服务器 — 第一阶段:Gmail 通过模型上下文协议从任何 AI 代理(Claude、LangGraph、GPT)发送电子邮件警报。


功能说明

此 MCP 服务器暴露了一个 mail_send 工具,任何兼容 MCP 的 AI 代理都可以调用它通过 Gmail 发送电子邮件。

使用场景: 工厂机器停止工作 → 你的 AI 监控代理调用 mail_send → 经理、技术人员和员工立即收到警报邮件。

Machine stops → AI Agent → mail_send tool → Gmail → Manager + Technician notified

MCP 端点: http://localhost:8100/mcp


架构

notifications-mcp/
├── src/
│   ├── server.py          ← Entrypoint (Streamable HTTP + OAuth routes)
│   ├── config.py          ← Loads config.yaml
│   ├── registry.py        ← Dynamically loads channel tools
│   └── channels/
│       ├── mail/          ← Gmail channel (Phase 1)
│       ├── teams/         ← Microsoft Teams (Phase 2 placeholder)
│       └── sms/           ← SMS via Twilio (Phase 3 placeholder)

要添加新通道:创建 channels/<name>/tools.py,其中包含一个 register(mcp, cfg) 函数,将通道名称添加到 config.yamlenabled_channels 中。无需更改其他文件。


设置

1. 前提条件

  • Python 3.11+

  • 一个启用了 Gmail API 的 Google Cloud 项目

2. Google Cloud 设置

  1. 前往 Google Cloud 控制台

  2. 为你的项目启用 Gmail API

  3. 前往 API 和服务 → 凭据 → 创建凭据 → OAuth 2.0 客户端 ID

  4. 应用程序类型:Web 应用程序

  5. 添加授权重定向 URI:http://localhost:8100/auth/gmail/callback

  6. 下载 JSON → 保存为 credentials/google_credentials.json

3. 安装依赖

pip install -r requirements.txt
# or for development:
pip install -e ".[dev]"

4. 启动服务器

python -m src.server

你会看到:

{"level": "INFO", "message": "Starting notifications-mcp | host=0.0.0.0 | port=8100"}
{"level": "INFO", "message": "MCP endpoint  → http://localhost:8100/mcp"}
{"level": "INFO", "message": "Gmail OAuth   → http://localhost:8100/auth/gmail/start"}

5. 验证 Gmail(仅首次)

打开浏览器并访问:

http://localhost:8100/auth/gmail/start
  1. 你将被重定向到 Google 的同意页面

  2. 使用你要发送邮件的 Gmail 账户登录

  3. 授予“发送邮件”权限

  4. 你会看到 ✅ Gmail 已验证!— 关闭标签页

  5. 令牌已保存到 credentials/gmail_token.json,此后会自动静默刷新


使用 mail_send 工具

从 MCP Inspector(测试)

npx @modelcontextprotocol/inspector http://localhost:8100/mcp

调用 mail_send,参数如下:

{
  "to": ["manager@yourcompany.com", "technician@yourcompany.com"],
  "subject": "ALERT: Machine #3 stopped",
  "body": "Machine #3 on Floor B stopped at 18:02.\nError code: E-404.\nPlease investigate immediately."
}

从 AI 代理(Claude / LangGraph)

代理会看到此工具描述:

mail_send — 通过 Gmail 向一个或多个收件人发送电子邮件。对于工厂机器停机警报,请包含机器名称、位置、停机时间和错误代码。

代理调用方式如下:

result = await client.call_tool("mail_send", {
    "to": ["manager@factory.com", "tech@factory.com"],
    "subject": "ALERT: Machine #3 stopped",
    "body": "Machine #3 stopped at 18:02. Error: E-404. Location: Floor B, Line 2."
})

从 Antigravity / Claude Desktop

添加到你的 MCP 配置:

{
  "mcpServers": {
    "notifications": {
      "url": "http://localhost:8100/mcp"
    }
  }
}

工具参考

mail_send

通过 Gmail 向一个或多个收件人发送电子邮件。

参数

类型

必需

描述

to

list[str]

收件人电子邮件地址列表

subject

str

电子邮件主题行

body

str

电子邮件正文(纯文本)

cc

list[str]

抄送收件人

bcc

list[str]

密送收件人

成功时返回:

{"status": "sent", "message_id": "18b3c...", "recipients": ["manager@co.com"]}

失败时返回:

{"status": "failed", "error": "rate_limited", "message": "Gmail rate limit hit. Wait 60s."}

配置

编辑 config.yaml 以更改设置:

server:
  host: "0.0.0.0"
  port: 8100          # Change port here

enabled_channels:
  - mail              # Add 'teams' or 'sms' here in Phase 2/3

channels:
  mail:
    credentials_path: "credentials/google_credentials.json"
    token_path: "credentials/gmail_token.json"
    scopes:
      - "https://www.googleapis.com/auth/gmail.send"
    oauth_redirect_uri: "http://localhost:8100/auth/gmail/callback"

运行测试

pytest tests/ -v

预期输出:

tests/channels/mail/test_tools.py::test_mail_send_success PASSED
tests/channels/mail/test_tools.py::test_mail_send_not_authenticated PASSED
tests/channels/mail/test_tools.py::test_mail_send_rate_limited PASSED
tests/channels/mail/test_tools.py::test_mail_send_missing_to_field PASSED
tests/channels/mail/test_tools.py::test_mail_send_missing_subject PASSED
tests/channels/mail/test_tools.py::test_mail_send_multiple_recipients PASSED
tests/channels/mail/test_tools.py::test_mail_send_with_cc_bcc PASSED

添加第二阶段(Teams)或第三阶段(短信)

  1. 创建通道文件夹:

    src/channels/teams/__init__.py
    src/channels/teams/auth.py
    src/channels/teams/client.py
    src/channels/teams/schemas.py
    src/channels/teams/tools.py   ← must have def register(mcp, cfg)
  2. 添加到 config.yaml

    enabled_channels:
      - mail
      - teams       ← add this
    channels:
      teams:
        tenant_id: "..."
        client_id: "..."
  3. 完成。 server.pyregistry.py 无需任何更改。


安全说明

  • credentials/ 已被 gitignore — 切勿提交 Google 凭据

  • OAuth 令牌自动静默刷新 — 你只需同意一次

  • 服务器在 localhost 上运行 — 默认不暴露于互联网

  • 本地使用无需 API 密钥


第一阶段:Gmail ✅ | 第二阶段:Teams 🔜 | 第三阶段:短信 🔜

-
license - not tested
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

  • Phone, SMS & email for AI agents — one remote MCP endpoint, OAuth login, zero install.

  • Push notifications for AI agents - send instant iPhone notifications from any MCP client.

  • Read, search, send, organize, draft and schedule email across your inboxes from any MCP client.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Manojbonthu/Custom_MCP_Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server