mcp-client-slack

mcp-client-slack

Listens for Slack @mentions and publishes them as real-time events to the KĀDI event bus, enabling event-driven architectures with low latency.

Category
访问服务器

README

mcp-client-slack

MCP Server that listens for Slack @mentions and publishes them as events to the KĀDI event bus for real-time processing by template-agent-typescript.

Overview

This server is part of the KĀDI Slack bot architecture. It:

  1. Connects to Slack via Socket Mode to receive real-time @mention events
  2. Validates and publishes events to KĀDI broker using topic-based routing
  3. Enables event-driven architecture with <100ms latency
  4. Works in conjunction with mcp-server-slack (for sending replies)

Architecture

Slack @mention → Socket Mode → Event Validation → KĀDI Event Bus
                                                      ↓
                                    Topic: slack.app_mention.{BOT_USER_ID}
                                                      ↓
                                             Agent_TypeScript
                                                      ↓
                                          Claude API + Reply via mcp-server-slack

Event-Driven Architecture

This server implements a publish-subscribe pattern using KĀDI's RabbitMQ infrastructure:

  • Publisher: mcp-client-slack publishes SlackMentionEvent to topic slack.app_mention.{BOT_USER_ID}
  • Subscriber: Agent_TypeScript subscribes to the same topic for real-time event delivery
  • Benefits: Real-time processing (<100ms), no polling overhead, scalable architecture

Installation

cd C:\p4\Personal\SD\mcp-client-slack
npm install

Configuration

Create .env file:

# Slack API Credentials
SLACK_BOT_TOKEN=xoxb-your-bot-token
SLACK_APP_TOKEN=xapp-your-app-token

# Anthropic Claude API (optional, not used in this server)
ANTHROPIC_API_KEY=sk-ant-your-key

# MCP Server Configuration
MCP_LOG_LEVEL=info

# KĀDI Broker Configuration (REQUIRED for event publishing)
KADI_BROKER_URL=ws://localhost:8080
SLACK_BOT_USER_ID=U01234ABCD

Environment Variables

Variable Required Description Example
SLACK_BOT_TOKEN ✅ Yes Slack bot user OAuth token xoxb-123...
SLACK_APP_TOKEN ✅ Yes Slack app-level token for Socket Mode xapp-1-A...
KADI_BROKER_URL ✅ Yes WebSocket URL for KĀDI broker ws://localhost:8080
SLACK_BOT_USER_ID ✅ Yes Slack bot user ID for event topic routing U01234ABCD
MCP_LOG_LEVEL No Logging level (debug, info, warn, error) info
ANTHROPIC_API_KEY No Not used (kept for backward compatibility) sk-ant-...

Required Slack Scopes

  • app_mentions:read - Listen for @mentions
  • chat:write - (handled by mcp-server-slack)

Usage

Development Mode

npm run dev

Production Mode

npm run build
npm start

As MCP Upstream (via KADI Broker)

Add to kadi-broker/mcp-upstreams.json:

{
  "id": "slack-client",
  "name": "Slack Event Listener",
  "type": "stdio",
  "prefix": "slack_client",
  "networks": ["slack"],
  "stdio": {
    "command": "node",
    "args": ["C:/p4/Personal/SD/mcp-client-slack/dist/index.js"],
    "env": {
      "SLACK_BOT_TOKEN": "xoxb-...",
      "SLACK_APP_TOKEN": "xapp-...",
      "ANTHROPIC_API_KEY": "sk-ant-..."
    }
  }
}

🔴 Breaking Changes

Version 2.0.0 - Event-Driven Architecture

What Changed:

  • REMOVED: get_slack_mentions MCP tool (polling-based)
  • ADDED: Event publishing to KĀDI event bus (real-time)

Impact:

  • Agents can no longer poll for mentions using get_slack_mentions
  • Agents must subscribe to slack.app_mention.{BOT_USER_ID} events instead

Migration Required:

  • Update Agent_TypeScript to use event subscription (see Migration Guide below)
  • Add KADI_BROKER_URL and SLACK_BOT_USER_ID to environment configuration

Event Topics

Topic Pattern Standard

All KĀDI events follow the standardized topic pattern: {platform}.{event_type}.{bot_id}

  • {platform}: Platform identifier (slack, discord, etc.)
  • {event_type}: Event type (app_mention, mention, etc.)
  • {bot_id}: Bot unique identifier (critical for multi-bot deployments)

Why bot_id is required:

  • ✅ Enables multiple bot instances in the same workspace
  • ✅ Routes events only to the intended bot
  • ✅ Prevents cross-bot event delivery
  • ✅ Supports multi-tenant deployments

Validation: Topics are automatically validated by @agents/shared package. Invalid patterns will log warnings but still publish.

See TOPIC_PATTERN.md for complete documentation.

slack.app_mention.{BOT_USER_ID}

Published when the bot is @mentioned in Slack.

Event Payload (SlackMentionEvent):

{
  id: string;           // Unique mention ID (Slack event timestamp)
  user: string;         // Slack user ID who mentioned the bot
  text: string;         // Message text (with @bot mention removed)
  channel: string;      // Slack channel ID
  thread_ts: string;    // Thread timestamp for replies
  ts: string;           // Event timestamp from Slack
  bot_id: string;       // Slack bot user ID (routing identifier)
  timestamp: string;    // ISO 8601 datetime when event was published
}

Example:

{
  "id": "1234567890.123456",
  "user": "U12345",
  "text": "What's the weather today?",
  "channel": "C12345",
  "thread_ts": "1234567890.123456",
  "ts": "1234567890.123456",
  "bot_id": "U01234ABCD",
  "timestamp": "2025-01-16T10:30:00.000Z"
}

Integration with Agent_TypeScript

Event Subscription (Current - v2.0.0+)

Agent_TypeScript subscribes to real-time events:

import { SlackMentionEventSchema } from './types/slack-events.js';

// Subscribe to Slack mention events
client.subscribeToEvent(`slack.app_mention.${botUserId}`, async (event: unknown) => {
  // Validate event payload
  const validationResult = SlackMentionEventSchema.safeParse(event);

  if (!validationResult.success) {
    console.error('Invalid event:', validationResult.error);
    return;
  }

  const mention = validationResult.data;

  // Process mention with Claude API
  // Reply using mcp-server-slack tools
});

Polling (Deprecated - v1.x)

⚠️ No longer supported - Update to event subscription:

// ❌ OLD (v1.x) - No longer works
const result = await client.getBrokerProtocol().invokeTool({
  targetAgent: 'slack-client',
  toolName: 'slack_client_get_slack_mentions',
  toolInput: { limit: 5 },
  timeout: 10000
});

Migration Guide

Upgrading from v1.x to v2.0.0

Step 1: Update Environment Variables

Add to .env:

KADI_BROKER_URL=ws://localhost:8080
SLACK_BOT_USER_ID=U01234ABCD  # Get from Slack app settings

Step 2: Update Agent Code

Remove polling logic:

// ❌ Remove this
setInterval(async () => {
  const result = await invokeTool({
    targetAgent: 'slack-client',
    toolName: 'slack_client_get_slack_mentions',
    ...
  });
}, 10000);

Add event subscription:

// ✅ Add this
import { SlackMentionEventSchema } from './types/slack-events.js';

client.subscribeToEvent(
  `slack.app_mention.${process.env.SLACK_BOT_USER_ID}`,
  async (event: unknown) => {
    const mention = SlackMentionEventSchema.parse(event);
    // Your existing processing logic
  }
);

Step 3: Update Dependencies

Install Zod for schema validation (if not already installed):

npm install zod

Step 4: Test Event Flow

  1. Start KĀDI broker
  2. Start mcp-client-slack (publisher)
  3. Start Agent_TypeScript (subscriber)
  4. Send test @mention in Slack
  5. Verify event received in <100ms

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选