Tathagat017/Discord-Mcp-server
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.
FastMCP Discord Integration Server is a secure, scalable backend server built with FastAPI and FastMCP, enabling AI models to interact with Discord through a comprehensive set of tools.
send_message
Send messages to Discord channels
get_messages
Retrieve recent messages from channels
get_channel_info
Get detailed channel information
search_messages
Search messages by keyword
delete_message
Delete specific messages
ban_user
Ban users from guilds
kick_user
Kick users from guilds
get_guild_info
Get detailed guild information
FastMCP Discord Integration Server
A secure, scalable Model Context Protocol (MCP) backend server built with FastAPI and FastMCP, enabling AI models to interact with Discord through a comprehensive set of tools.
๐ Features
- Discord Bot Integration: Send messages, retrieve history, search content, and moderate channels
- MCP Protocol Support: Full compatibility with MCP Inspector and MCP clients
- Secure Authentication: API key-based authentication with role-based permissions
- Multi-tenancy: Support for multiple Discord bots per client
- Real-time Debugging: Integration with MCP Inspector for request monitoring
- Comprehensive Logging: Structured logging with audit trail
- Rate Limiting: Built-in protection against abuse
- FastAPI Integration: RESTful API endpoints alongside MCP tools
๐ ๏ธ Available MCP Tools
Tool | Description | Permissions Required |
---|---|---|
send_message | Send messages to Discord channels | Send Messages |
get_messages | Retrieve recent messages from channels | Read Message History |
get_channel_info | Get detailed channel information | View Channels |
search_messages | Search messages by keyword | Read Message History |
delete_message | Delete specific messages | Manage Messages |
ban_user | Ban users from guilds | Ban Members |
kick_user | Kick users from guilds | Kick Members |
get_guild_info | Get detailed guild information | View Channels |
๐ Quick Start
1. Prerequisites
- Python 3.8+
- Discord Bot Token
- Virtual environment (recommended)
2. Installation
# Clone the repository
git clone <repository-url>
cd fastmcp-discord-server
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
3. Configuration
# Copy the sample environment file
cp env.sample .env
# Edit .env with your configuration
nano .env
Required Environment Variables:
DISCORD_BOT_TOKEN
: Your Discord bot tokenAPI_KEY_SECRET
: Secret for API key generationJWT_SECRET_KEY
: Secret for JWT tokens
4. Discord Bot Setup
- Go to Discord Developer Portal
- Create a new application
- Go to "Bot" section and create a bot
- Copy the bot token to your
.env
file - Enable the following bot permissions:
- Send Messages
- Read Message History
- View Channels
- Manage Messages (for moderation)
- Ban Members (for moderation)
- Kick Members (for moderation)
5. Running the Server
# Run FastAPI server (recommended for development)
python -m app.main
# Or run MCP server directly
python -m app.main mcp
# Or using uvicorn directly
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000
๐ก API Usage
Authentication
All API calls require authentication via API key:
# Generate an API key
curl -X POST "http://localhost:8000/generate-api-key" \
-H "Content-Type: application/json" \
-d '{"user_id": "your_user_id"}'
Using MCP Tools
# List available tools
curl -X GET "http://localhost:8000/mcp/tools" \
-H "X-API-Key: your_api_key"
# Call a tool
curl -X POST "http://localhost:8000/mcp/call-tool" \
-H "X-API-Key: your_api_key" \
-H "Content-Type: application/json" \
-d '{
"tool_name": "send_message",
"parameters": {
"channel_id": 123456789,
"content": "Hello from MCP!"
}
}'
Health Check
curl -X GET "http://localhost:8000/health"
๐ง MCP Client Integration
Using with MCP Inspector
- Install MCP Inspector
- Configure connection to
http://localhost:8000
- Use API key for authentication
- Monitor real-time requests and responses
Using with AI Models
Configure your AI model client to use the MCP server:
{
"server_url": "http://localhost:8000",
"api_key": "your_api_key",
"tools": ["send_message", "get_messages", "search_messages"]
}
๐๏ธ Project Structure
fastmcp_backend/
โโโ app/
โ โโโ __init__.py
โ โโโ main.py # Main FastAPI + MCP server
โ โโโ config.py # Configuration management
โ โโโ auth/
โ โ โโโ __init__.py
โ โ โโโ middleware.py # Authentication middleware
โ โโโ discord/
โ โ โโโ __init__.py
โ โ โโโ bot.py # Discord bot integration
โ โโโ mcp/
โ โ โโโ __init__.py
โ โ โโโ tools.py # MCP tools implementation
โ โโโ models/
โ โ โโโ __init__.py
โ โโโ schemas/
โ โ โโโ __init__.py
โ โโโ db/
โ โ โโโ __init__.py
โ โโโ tests/
โ โโโ __init__.py
โโโ requirements.txt
โโโ env.sample
โโโ README.md
๐ Security Features
- API Key Authentication: Secure HMAC-based API keys
- Rate Limiting: Configurable request limits
- CORS Protection: Configurable allowed origins
- Input Validation: Pydantic schema validation
- Audit Logging: Complete action logging
- Permission Checks: Role-based access control
๐งช Testing
# Run tests
pytest app/tests/
# Run with coverage
pytest --cov=app app/tests/
# Run specific test
pytest app/tests/test_discord.py
๐ Monitoring
Logs
Logs are structured and include:
- Request/response details
- User actions
- Error tracking
- Performance metrics
Health Monitoring
The /health
endpoint provides:
- Server status
- Discord bot status
- System metrics
- Timestamp information
๐ Deployment
Development
python -m app.main
Production
# Using gunicorn
gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker
# Using Docker (create Dockerfile)
docker build -t fastmcp-discord .
docker run -p 8000:8000 fastmcp-discord
๐ Examples
Send a Message
import httpx
async def send_discord_message():
async with httpx.AsyncClient() as client:
response = await client.post(
"http://localhost:8000/mcp/call-tool",
headers={"X-API-Key": "your_api_key"},
json={
"tool_name": "send_message",
"parameters": {
"channel_id": 123456789,
"content": "Hello from FastMCP!"
}
}
)
return response.json()
Search Messages
async def search_messages():
async with httpx.AsyncClient() as client:
response = await client.post(
"http://localhost:8000/mcp/call-tool",
headers={"X-API-Key": "your_api_key"},
json={
"tool_name": "search_messages",
"parameters": {
"channel_id": 123456789,
"query": "important",
"limit": 10
}
}
)
return response.json()
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Support
- Check the Issues page
- Read the Documentation
- Join our Discord Community
๐ Changelog
v1.0.0
- Initial release
- Full MCP protocol support
- Discord bot integration
- Authentication system
- Comprehensive logging
- Rate limiting
- Health monitoring