mcp-client-discord

mcp-client-discord

Listens for Discord @mentions via Gateway and queues them for processing by an agent, exposing a tool to retrieve pending mentions for automated responses.

Category
访问服务器

README

mcp-client-discord

Discord Event Listener with Claude-Powered Auto-Response via KADI Broker.

Overview

mcp-client-discord is a TypeScript-based MCP server that listens for Discord @mentions and queues them for template-agent-typescript to process. It uses Discord Gateway to receive real-time events.

Architecture

Discord Channel → Gateway Event → Mention Queue → template-agent-typescript → Claude API → mcp-server-discord → Discord Reply

Components

  • Discord Gateway: Real-time WebSocket connection for receiving events
  • Mention Queue: In-memory queue (max 100) of unprocessed @mentions
  • MCP Server: Exposes get_discord_mentions tool for KADI broker integration
  • Tool Registration: Available to any KADI agent via broker

Setup

1. Install Dependencies

npm install

2. Configure Environment

Copy .env.example to .env:

cp .env.example .env

Edit .env with your Discord bot token:

DISCORD_TOKEN=your_discord_bot_token_here
DISCORD_GUILD_ID=your_discord_guild_id_here  # Optional
MCP_LOG_LEVEL=info

3. Get Discord Bot Token

  1. Go to Discord Developer Portal
  2. Create a new application
  3. Go to "Bot" section
  4. Click "Reset Token" and copy the token
  5. Enable "Message Content Intent" in bot settings
  6. Invite bot to your server with proper permissions (Send Messages, Read Messages, etc.)

4. Build

npm run build

5. Run

Development mode (with hot-reload):

npm run dev

Production mode:

npm start

MCP Tools

get_discord_mentions

Retrieve pending Discord @mentions from the queue.

Input:

  • limit (optional): Maximum number of mentions to retrieve (1-50, default: 10)

Output:

{
  "mentions": [
    {
      "id": "message_id",
      "user": "user_id",
      "username": "username",
      "text": "message text without @bot mention",
      "channel": "channel_id",
      "channelName": "channel_name",
      "guild": "guild_id",
      "ts": "ISO_timestamp"
    }
  ],
  "count": 1,
  "retrieved_at": "ISO_timestamp"
}

Integration with KADI Broker

The MCP server is registered in kadi-broker/config/mcp-upstreams.json:

{
  "id": "discord-client",
  "name": "Discord Event Listener (mcp-client-discord)",
  "type": "stdio",
  "prefix": "discord_client",
  "enabled": true,
  "stdio": {
    "command": "node",
    "args": ["C:\\p4\\Personal\\SD\\mcp-client-discord\\dist\\index.js"],
    "env": {
      "DISCORD_TOKEN": "your_token",
      "DISCORD_GUILD_ID": "your_guild_id"
    }
  },
  "networks": ["discord"]
}

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 server
  • ✅ 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.

discord.mention.{BOT_USER_ID}

Published when the bot is @mentioned in Discord.

Event Payload (DiscordMentionEvent):

{
  id: string;           // Unique message ID
  user: string;         // Discord user ID who mentioned the bot
  username: string;     // Discord username
  text: string;         // Message text (with @bot mention removed)
  channel: string;      // Discord channel ID
  channelName: string;  // Discord channel name
  guild: string;        // Discord guild/server ID
  ts: string;           // ISO 8601 timestamp
  timestamp: string;    // ISO 8601 datetime when event was published
}

Usage with Agent_TypeScript

Agent_TypeScript polls this MCP server for new @mentions:

// In Agent_TypeScript
const protocol = client.getBrokerProtocol();

const result = await protocol.invokeTool({
  targetAgent: 'discord-client',
  toolName: 'discord_client_get_discord_mentions',
  toolInput: { limit: 5 },
  timeout: 10000
});

const mentions = JSON.parse(result.content[0].text).mentions;

Discord Bot Permissions

Required bot permissions:

  • View Channels
  • Send Messages
  • Read Message History
  • Add Reactions (optional)

Required Gateway Intents:

  • Guilds
  • Guild Messages
  • Message Content

Logging

The server logs to console with emoji indicators:

  • 🚀 Startup messages
  • 📬 Mention queued
  • 📤 Mentions retrieved
  • ✅ Success messages
  • ❌ Error messages
  • 💬 Received mention

Troubleshooting

"Discord client not ready after timeout"

  • Check DISCORD_TOKEN is valid
  • Verify bot has been invited to server
  • Ensure internet connection is stable

"Channel not found" errors

  • Verify bot has access to the channel
  • Check channel permissions

Bot not responding to mentions

  • Verify "Message Content Intent" is enabled
  • Check bot has "Send Messages" permission
  • Ensure bot is not muted or blocked

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选