astrelya/mcp-discord
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.
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
- Node.js (version 18 or higher)
- Discord Bot Token - Create a bot application at Discord Developer Portal
Setup
1. Install Dependencies
npm install
2. Configure Discord Bot
- Go to the Discord Developer Portal
- Create a new application or select an existing one
- Go to the "Bot" section and create a bot
- Copy the bot token
- Create a
.envfile in the project root:
cp .env.example .env
- Edit
.envand add your Discord bot token:
DISCORD_TOKEN=your_discord_bot_token_here
3. Bot Permissions
Your Discord bot needs the following permissions:
Send MessagesRead Message HistoryView ChannelsUse 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
- Define the input schema using Zod
- Add the tool definition in
setupToolHandlers() - Implement the handler method
- 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
-
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
-
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
-
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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
ISC License - see LICENSE file for details
Resources
- Model Context Protocol Documentation
- Discord.js Guide
- Discord Developer Portal
- - Detailed usage examples and client configurations
- - Web application integration guide
- - Java application integration guide