TypeScriptADK-TS

MCP Discord

An MCP server for interacting with Discord bots and channels

  • Package: @iqai/mcp-discord
  • Purpose: Interacting with Discord bots and channels using the Discord.js library.

Usage with ADK TypeScript

import {McpDiscord} from "@iqai/adk";

const toolset = McpDiscord({
  env: {
    DISCORD_TOKEN: process.env.DISCORD_TOKEN,
  },
})

const tools = await toolset.getTools()
import {McpToolset} from "@iqai/adk";

const toolset = new McpToolset({
  name: "Discord MCP Client",
  description: "Client for Discord bot operations",
  transport: {
    mode: "stdio",
    command: "pnpm",
    args: ["dlx", "@iqai/mcp-discord"],
    env: {
      DISCORD_TOKEN: process.env.DISCORD_TOKEN,
      PATH: process.env.PATH || "",
    },
  },
})

const tools = await toolset.getTools()
{
  "mcpServers": {
    "discord-mcp-server": {
      "command": "pnpm",
      "args": ["dlx", "@iqai/mcp-discord"],
      "env": {
        "DISCORD_TOKEN": "your_bot_token_here"
      }
    }
  }
}

Features

  • Provides tools to send messages, get server information, manage channels, create forum posts, handle reactions, and manage webhooks.
  • Uses the Discord.js library, a powerful Discord bot framework for Node.js.
  • Supports both channel IDs and channel names for flexible interaction.

Available Tools

discord_create_category
guildId:stringname:stringposition:numberreason:string

Description

Creates a new category in a Discord server.

discord_edit_category
categoryId:stringname:stringposition:numberreason:string

Description

Edits an existing Discord category (name and position).

discord_delete_category
categoryId:stringreason:string

Description

Deletes a Discord category by ID.

discord_login
token:string

Description

Logs in to Discord using the configured token

discord_send
channelId:stringmessage:string

Description

Sends a message to a specified Discord text channel

discord_get_forum_channels
guildId:string

Description

Lists all forum channels in a specified Discord server (guild)

discord_create_forum_post
forumChannelId:stringtitle:stringcontent:stringtags:array

Description

Creates a new post in a Discord forum channel with optional tags

discord_get_forum_post
threadId:string

Description

Retrieves details about a forum post including its messages

discord_reply_to_forum
threadId:stringmessage:string

Description

Adds a reply to an existing forum post or thread

discord_create_text_channel
guildId:stringchannelName:stringtopic:string

Description

Creates a new text channel in a Discord server with an optional topic

discord_delete_channel
channelId:stringreason:string

Description

Deletes a Discord channel with an optional reason

discord_read_messages
channelId:stringlimit:number

Description

Retrieves messages from a Discord text channel with a configurable limit

discord_get_server_info
guildId:string

Description

Retrieves detailed information about a Discord server including channels and member count

discord_add_reaction
channelId:stringmessageId:stringemoji:string

Description

Adds an emoji reaction to a specific Discord message

discord_add_multiple_reactions
channelId:stringmessageId:stringemojis:array

Description

Adds multiple emoji reactions to a Discord message at once

discord_remove_reaction
channelId:stringmessageId:stringemoji:stringuserId:string

Description

Removes a specific emoji reaction from a Discord message

discord_delete_forum_post
threadId:stringreason:string

Description

Deletes a forum post or thread with an optional reason

discord_delete_message
channelId:stringmessageId:stringreason:string

Description

Deletes a specific message from a Discord text channel

discord_create_webhook
channelId:stringname:stringavatar:stringreason:string

Description

Creates a new webhook for a Discord channel

discord_send_webhook_message
webhookId:stringwebhookToken:stringcontent:stringusername:stringavatarURL:stringthreadId:string

Description

Sends a message to a Discord channel using a webhook

discord_edit_webhook
webhookId:stringwebhookToken:stringname:stringavatar:stringchannelId:stringreason:string

Description

Edits an existing webhook for a Discord channel

discord_delete_webhook
webhookId:stringwebhookToken:stringreason:string

Description

Deletes an existing webhook for a Discord channel

Sampling

Sampling enables an mcp server to request llm sampling (generations or completions) from the client. The mcp-discord server listens to new messages and bot mentions and uses sampling to get llm responses and responds to them, basically in a nutshell allowing for bi-directional communication.

This is useful when you want agentic capabilities ie building a discord bot that can respond to messages and also send messages to other users.

Resources

Environment Variables

  • DISCORD_TOKEN: Your Discord bot token (required)
  • SAMPLING_ENABLED: Enable bi-directional message sampling (default: true)
  • DEFAULT_RATE_LIMIT_SECONDS: Rate limit for sampling requests per user (default: 2)
  • DEFAULT_MESSAGE_CHUNK_SIZE: Max message chunk size for sampling responses (default: 2000)

Usage Examples

discord_send

Send a message to a Discord channel:

{
  "tool_name": "discord_send",
  "arguments": {
    "channelId": "123456789012345678",
    "message": "Hello from the Discord MCP Server!"
  }
}

discord_get_server_info

Get information about a Discord server:

{
  "tool_name": "discord_get_server_info",
  "arguments": {
    "serverId": "123456789012345678"
  }
}

discord_create_forum_post

Create a forum post:

{
  "tool_name": "discord_create_forum_post",
  "arguments": {
    "channelId": "123456789012345678",
    "title": "New Discussion Topic",
    "message": "Let's discuss this important topic!"
  }
}

Response Examples

discord_send

Successful response:

{
  "success": true,
  "result": "Message sent successfully!\n\nMessage ID: 123456789012345678\nChannel ID: 123456789012345678\nSent at: 2024-03-15T12:34:56.789Z\nContent: Hello from the Discord MCP Server!"
}

discord_get_server_info

Successful response:

{
  "success": true,
  "result": "Server Information:\n\nName: My Discord Server\nID: 123456789012345678\nOwner: ServerOwner#1234\nMember Count: 1500\nCreated: 2020-01-15T10:30:00.000Z\nDescription: Welcome to our community server!"
}

Error Handling

The tools will return an error message in the result field if an error occurs. Common errors include:

  • Missing bot token: Ensure the DISCORD_TOKEN environment variable is set.
  • Invalid channel ID: Double-check the channel ID or name.
  • Bot not in server: Add the bot to the server with appropriate permissions.
  • Insufficient permissions: Ensure the bot has the required permissions for the action.

Bot Setup

Bot Setup Required

You'll need to create and configure a Discord bot before using this server.

  1. Create a bot application in the Discord Developer Portal

  2. Get your bot token from the Bot section

  3. Enable the following Privileged Gateway Intents:

    • Message Content Intent
    • Server Members Intent
    • Presence Intent
  4. Add your bot to servers with appropriate permissions:

    • Administrator (recommended for full functionality)
    • Or select specific permissions:
      • Send Messages
      • Create Public Threads
      • Send Messages in Threads
      • Manage Messages
      • Manage Threads
      • Manage Channels
      • Manage Webhooks
      • Add Reactions
      • View Channel
  5. Use the following invite link (replace INSERT_CLIENT_ID_HERE with your bot's client ID):

    • Administrator: https://discord.com/oauth2/authorize?client_id=INSERT_CLIENT_ID_HERE&scope=bot&permissions=8
    • Minimum required: https://discord.com/oauth2/authorize?client_id=INSERT_CLIENT_ID_HERE&scope=bot&permissions=52076489808