mcp-discord

astrelya/mcp-discord

3.1

If you are the rightful owner of mcp-discord and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

A Model Context Protocol (MCP) server that enables AI agents to interact with Discord through the Discord API.

Tools
6
Resources
0
Prompts
0

Discord MCP Server

A Model Context Protocol (MCP) server that enables AI agents to interact with Discord through the Discord API. This server provides a comprehensive set of tools for managing Discord servers, channels, messages, and users.

Features

Available Tools

  • send_message - Send messages to Discord channels
  • get_messages - Retrieve recent messages from channels
  • get_channel_info - Get detailed information about channels
  • get_server_info - Get detailed information about Discord servers
  • list_servers - List all servers the bot is connected to
  • list_channels - List all channels in a specific server

Available Resources

  • discord://servers - JSON resource containing all connected Discord servers

Prerequisites

  1. Node.js (version 18 or higher)
  2. Discord Bot Token - Create a bot application at Discord Developer Portal

Setup

1. Install Dependencies

npm install

2. Configure Discord Bot

  1. Go to the Discord Developer Portal
  2. Create a new application or select an existing one
  3. Go to the "Bot" section and create a bot
  4. Copy the bot token
  5. Create a .env file in the project root:
cp .env.example .env
  1. Edit .env and add your Discord bot token:
DISCORD_TOKEN=your_discord_bot_token_here

3. Bot Permissions

Your Discord bot needs the following permissions:

  • Send Messages
  • Read Message History
  • View Channels
  • Use Slash Commands (optional)

Invite the bot to your Discord server with these permissions.

4. Build the Project

npm run build

Usage

Running the Server

npm start

For development with auto-rebuild:

npm run watch

Using with MCP Clients

This server implements the Model Context Protocol and can be used with any MCP-compatible client. Configure your client to connect to this server using stdio transport.

Example MCP configuration:

{
  "servers": {
    "discord-mcp-server": {
      "type": "stdio",
      "command": "node",
      "args": ["dist/index.js"]
    }
  }
}

Environment Variables

  • DISCORD_TOKEN (required) - Your Discord bot token

Tool Examples

Send a Message

{
  "name": "send_message",
  "arguments": {
    "channelId": "123456789012345678",
    "content": "Hello from the MCP Discord server!"
  }
}

Get Recent Messages

{
  "name": "get_messages",
  "arguments": {
    "channelId": "123456789012345678",
    "limit": 5
  }
}

List Servers

{
  "name": "list_servers",
  "arguments": {}
}

Development

Project Structure

src/
├── index.ts          # Main MCP server implementation
├── types/            # TypeScript type definitions
└── utils/            # Utility functions

.vscode/
├── mcp.json          # MCP server configuration
└── tasks.json        # VS Code build tasks

.github/
└── copilot-instructions.md  # GitHub Copilot instructions

Adding New Tools

  1. Define the input schema using Zod
  2. Add the tool definition in setupToolHandlers()
  3. Implement the handler method
  4. Update this README with documentation

Testing

Set up your .env file and run:

npm run dev

Test the server using an MCP client or by examining the logs.

Security Considerations

  • Never commit your Discord bot token to version control
  • Use environment variables for all sensitive configuration
  • Validate all inputs using Zod schemas
  • Implement proper error handling for Discord API calls
  • Consider rate limiting for production use

Troubleshooting

Common Issues

  1. Bot not responding

    • Verify the Discord token is correct
    • Check if the bot has proper permissions in the server
    • Ensure the bot is online in the Discord server
  2. Channel not found errors

    • Verify the channel ID is correct
    • Check if the bot has access to the channel
    • Ensure the channel exists and hasn't been deleted
  3. Permission errors

    • Review bot permissions in the Discord server
    • Check if the bot role is high enough in the hierarchy
    • Verify channel-specific permissions

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

ISC License - see LICENSE file for details

Resources