dhruvsahu007/Discord-MCP-Server
3.1
If you are the rightful owner of Discord-MCP-Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A FastAPI server that integrates with Discord and provides a Model Context Protocol (MCP) interface for bot interactions.
Discord MCP Server
A FastAPI server that integrates with Discord and provides a Model Context Protocol (MCP) interface for bot interactions.
Features
- Discord bot integration with message, channel, and moderation capabilities
- API key authentication and JWT token-based security
- MCP Inspector integration for debugging
- Rate limiting and error handling
- Comprehensive test suite
Setup
-
Clone the repository
-
Create a virtual environment:
python -m venv myenv source myenv/bin/activate # Linux/Mac myenv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.env
file based on.env.example
and fill in your credentials:- Get Discord credentials from the Discord Developer Portal:
- Bot Token: Found in the "Bot" tab
- Client ID: Found in "General Information"
- Client Secret: Found in "OAuth2" section
- Generate secure random strings for API_KEY_SALT and JWT_SECRET_KEY
- Get Discord credentials from the Discord Developer Portal:
-
Start the server:
python -m src.main
API Endpoints
Messages
POST /api/v1/messages/send
- Send a message to a channelGET /api/v1/messages/{channel_id}
- Get messages from a channel
Channels
GET /api/v1/channels/list
- List all accessible channelsGET /api/v1/channels/{channel_id}
- Get channel information
Moderation
POST /api/v1/moderation/ban
- Ban a userPOST /api/v1/moderation/kick
- Kick a user
Authentication
- Include your API key in requests using the
X-API-Key
header - The server will validate the API key and return a JWT token
- Use the JWT token for subsequent requests
Development
- Enable debug mode in
.env
for auto-reload - Run tests with coverage:
pytest --cov=src tests/
MCP Inspector
- Enable MCP Inspector in
.env
for debugging - Access the inspector UI at
http://localhost:9000
Error Handling
The server includes comprehensive error handling:
- Invalid API keys return 401
- Missing permissions return 403
- Resource not found returns 404
- Server errors return 500 with error details
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request