Token导航 LogoToken导航TokenDH.com
Slack Agent MCP logo
办公协作stdio官方级别未说明来源级核验

Slack Agent MCP

MCP Server

一个用于在应用里程碑发送Slack通知的Python库,支持异步通知、错误处理和AI代理集成。

工具数

5

提示词数

0

GitHub Stars

0

资源数

0
错误处理PythonClaudeClaude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

jjurach

提供方

jjurach

最后核验

2026/5/17 20:19

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

pip install slack-notifications

详细介绍

Slack通知

一个简单的Python库,用于在应用程序里程碑时发送Slack通知。

特性

  • 🚀 用于里程碑通知的简单API
  • ⚙️ 通过环境变量或配置文件灵活配置
  • 🔄 异步支持非阻塞通知
  • 🛡️ 全面的错误处理和记录
  • 📝 完整的类型提示和文档
  • 🧪 通过示例进行了充分测试
  • 🤖 用于AI代理集成的MCP服务器
  • 具有时间查询功能的实时Slack Agent

安装

pip install slack-notifications

快速开始

  1. 设置您的Slack应用程序并获取机器人令牌:

- 首选 松弛API - 创建新应用程序或使用现有应用程序 - 将机器人添加到您的工作区 - 复制Bot用户OAuth令牌

  1. 配置环境变量:
   # Copy the example file and fill in your values
   cp .env.example .env
   # Edit .env with your actual Slack bot token

或者直接设置环境变量:

   export SLACK_BOT_TOKEN="xoxb-your-bot-token-here"
   export SLACK_DEFAULT_CHANNEL="#general"
  1. 在Python代码中使用:
   from slack_notifications import notify_milestone

   # Send a simple milestone notification
   notify_milestone("Application started successfully!")

   # Send to a specific channel with custom level
   notify_milestone("Database migration completed", channel="#dev-ops", level="info")

   # Send error notifications
   notify_milestone("Critical error occurred", level="error")

配置

应用程序支持多种配置方法,自动按以下优先级顺序加载:

  1. 环境变量(最高优先级)
  2. .env 当前目录中的文件
  3. slack_notifications.toml 文件
  4. 内置默认值(最低优先级)

使用.env文件(推荐)

对于安全的静态部署配置:

  1. 复制示例文件:
   cp .env.example .env
  1. 编辑 .env 根据您的实际值:
   # Required
   SLACK_BOT_TOKEN=xoxb-your-actual-bot-token

   # Optional (with defaults shown)
   SLACK_DEFAULT_CHANNEL=#general
   SLACK_TIMEOUT=30
   SLACK_MAX_RETRIES=3

安全说明:.env Git会自动忽略该文件,并且不应将其提交到版本控制中。

环境变量

您还可以通过环境变量设置配置:

  • SLACK_BOT_TOKEN:您的Slack机器人令牌(必填)
  • SLACK_DEFAULT_CHANNEL:通知的默认通道(默认:“#general”)
  • SLACK_TIMEOUT:请求超时(秒)(默认值:30)
  • SLACK_MAX_RETRIES:最大重试次数(默认值:3)

TOML配置文件

或者,使用 slack_notifications.toml 文件:

# slack_notifications.toml
[slack]
bot_token = "xoxb-your-bot-token-here"
default_channel = "#notifications"
timeout = 30
max_retries = 3

异步用法

对于异步应用程序中的非阻塞通知:

import asyncio
from slack_notifications import notify_milestone_async

async def main():
    # Send notification asynchronously
    await notify_milestone_async("Async operation completed")

    # Continue with other work immediately
    await do_other_work()

asyncio.run(main())

错误处理

该库包括全面的错误处理:

from slack_notifications import notify_milestone, SlackNotificationError

try:
    notify_milestone("Test notification")
    print("Notification sent successfully!")
except SlackNotificationError as e:
    print(f"Failed to send notification: {e}")

高级用法

自定义配置

from slack_notifications import SlackNotifier

# Create notifier with custom config
notifier = SlackNotifier(
    bot_token="xoxb-custom-token",
    default_channel="#custom-channel",
    timeout=60
)

notifier.notify("Custom notification")

日志集成

该库与Python的日志模块集成:

import logging
from slack_notifications import SlackHandler

# Add Slack handler to your logger
logger = logging.getLogger()
slack_handler = SlackHandler(channel="#logs", level=logging.ERROR)
logger.addHandler(slack_handler)

# Now errors will be sent to Slack automatically
logger.error("This error will appear in Slack!")

用于AI代理的MCP服务器

slack代理项目现在包括一个FastMCP服务器,允许AI代理通过模型上下文协议(MCP)向slack通道发送通知。

启动MCP服务器

python slack_mcp_server.py

可用的MCP工具

  • send_slack_message(message, channel, level) -发送通知消息
  • send_slack_success(message, channel) -发送成功通知
  • send_slack_warning(message, channel) -发送警告通知
  • send_slack_error(message, channel) -发送错误通知
  • configure_slack_notifications(...) -配置Slack设置

AI代理集成

AI代理可以使用这些工具发送Slack消息。例如:

AI Agent: I need to notify the team about the deployment.

MCP Tool Call: send_slack_success("🚀 Production deployment completed successfully!", "#devops")

docs/mcp-service-setup.md 有关详细的设置和使用说明。

模型配置(概念变更)

松弛代理项目支持人工智能模型配置和管理方式的概念性变化。这一变化在以下方面引入了明确的分离 模型 (用户与之交互的内容)以及 后端 (提供者实现)。

模型与后端概念

  • 模型:具有友好名称、描述和功能的面向用户的界面
  • 后端:实际提供者实现(OpenAI、Anthropic、Ollama等)

这实现了灵活的路由、故障转移、成本优化和多提供商支持。

配置结构

# models: What users see and select
models:
  creative-writer:
    backend: "anthropic/claude-3-sonnet"
    description: "Creative writing assistant"
    capabilities: ["chat", "completion"]

  fast-chat:
    backend: "ollama/llama3.2:3b"
    description: "Fast local responses"

# backends: Provider configurations
backends:
  anthropic:
    provider: "anthropic"
    api_key: "${ANTHROPIC_API_KEY}"

  ollama:
    provider: "ollama"
    base_url: "http://localhost:11434"

好处

  • 提供者不可知论:在不更改面向用户的型号名称的情况下切换提供程序
  • 故障转移:自动回退到其他提供商
  • 成本优化:找到最便宜的供应商
  • 负载平衡:跨多个后端分发请求

docs/model-backend-concept.md 完整的概念文件和 examples/model_configure.yaml 用于配置示例。

Slack代理

该项目包括一个Slack机器人程序,使用Web API监控频道,并使用当前CST时间响应时间查询。

运行Slack代理

export SLACK_BOT_TOKEN="xoxb-your-bot-token-here"
python slack_agent.py

配置

Slack Agent支持其他配置:

# Optional: Comma-separated list of channel IDs to monitor
export SLACK_AGENT_CHANNELS="C1234567890,C0987654321"

# Optional: Polling interval in seconds (default: 5)
export SLACK_AGENT_POLL_INTERVAL=5

如果 SLACK_AGENT_CHANNELS 如果未设置,代理将自动发现和监视名称中带有“general”的频道。

时间查询响应

代理会响应与时间相关的确切查询:

  • “现在几点了”→ “当前时间为2025年12月25日美国中部时间上午11:00:00”
  • “现在几点了?”→ 反应
  • “时间”→ 反应
  • “当前时间”→ 反应

日志记录

所有交互都会用CST时间戳记录到stdout中:

2025-12-25 11:00:00 CST - slack_agent - INFO - [2025-12-25 11:00:00 CST] Starting Slack Agent...
2025-12-25 11:00:00 CST - slack_agent - INFO - Bot authenticated as user: U1234567890
2025-12-25 11:00:00 CST - slack_agent - INFO - Monitoring channels: C1234567890
2025-12-25 11:00:00 CST - slack_agent - INFO - [2025-12-25 11:00:00 CST] MESSAGE - Channel: C1234567890, User: U1234567890, Text: 'what time is it?'
2025-12-25 11:00:00 CST - slack_agent - INFO - [2025-12-25 11:00:00 CST] RESPONSE - Sent time to channel C1234567890: The current time is 11:00:00 AM CST on 2025-12-25

docs/slack-agent-usage.md 了解完整的设置和使用说明。

文档

对于AI代理

面向开发者

系统文档

发展

设置

git clone https://github.com/yourusername/slack-notifications.git
cd slack-notifications
pip install -e ".[dev,test]"

测试

pytest

建筑

python -m build

文档

对于AI代理

面向开发者

例子

指南

______________________________________________________________________

最后更新日期:2026-02-01

许可证-请参阅 许可证 文件以获取详细信息。

贡献

欢迎投稿!请参阅 贡献.md 作为指导方针。

目录标签

目录标签

错误处理PythonClaudeSlack通知本地部署Python库异步通知AI代理集成

支持客户端

Claude

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

oauth

工具数量(toolCount,工具数)

5

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdiooauth部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP