Discord-MCP-Server

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

  1. Clone the repository

  2. Create a virtual environment:

    python -m venv myenv
    source myenv/bin/activate  # Linux/Mac
    myenv\Scripts\activate     # Windows
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. 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
  5. Start the server:

    python -m src.main
    

API Endpoints

Messages

  • POST /api/v1/messages/send - Send a message to a channel
  • GET /api/v1/messages/{channel_id} - Get messages from a channel

Channels

  • GET /api/v1/channels/list - List all accessible channels
  • GET /api/v1/channels/{channel_id} - Get channel information

Moderation

  • POST /api/v1/moderation/ban - Ban a user
  • POST /api/v1/moderation/kick - Kick a user

Authentication

  1. Include your API key in requests using the X-API-Key header
  2. The server will validate the API key and return a JWT token
  3. Use the JWT token for subsequent requests

Development

  1. Enable debug mode in .env for auto-reload
  2. Run tests with coverage:
    pytest --cov=src tests/
    

MCP Inspector

  1. Enable MCP Inspector in .env for debugging
  2. 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request