README.mdβ’16.4 kB
# Discord MCP Server
[](https://opensource.org/licenses/MIT)
[](https://www.python.org/downloads/)
[](https://discord.com/)
A comprehensive Model Context Protocol (MCP) server for Discord integration. This server exposes all Discord functionality as MCP tools, enabling seamless integration with AI assistants like OpenAI, LangChain, Cursor, and Claude.
## π Features
- **Complete Discord API Coverage**: Channels, messages, threads, reactions, roles, webhooks, and more
- **MCP Standard Compliance**: JSON-RPC 2.0 based standardized API
- **High Performance**: Redis caching, rate limiting, automatic retries with exponential backoff
- **Security First**: Mention filtering, minimal permissions, audit logging
- **Production Ready**: Docker support, CI/CD pipeline, comprehensive monitoring
- **Advanced AI Features**: Message summarization, activity analysis, intelligent filtering
## π Quick Start
### Prerequisites
- Python 3.12+
- Discord Bot Token
- Redis 6.0+ (optional - uses in-memory cache if not available)
### Installation
1. **Clone the repository**
```bash
git clone https://github.com/tristan-kkim/discord-mcp.git
cd discord-mcp
```
2. **Install dependencies**
```bash
pip install -r requirements.txt
```
3. **Configure environment**
```bash
cp .env.example .env
# Edit .env with your Discord Bot Token
```
4. **Run the server**
```bash
python run.py
```
### Docker Deployment
```bash
# Using Docker Compose (recommended)
export DISCORD_BOT_TOKEN=your_bot_token_here
docker-compose up -d
# Or using Docker directly
docker build -t discord-mcp .
docker run -d -p 8000:8000 -e DISCORD_BOT_TOKEN=your_token discord-mcp
```
## π§ MCP Client Integration
### Cursor IDE
1. Open Cursor Settings β MCP Servers
2. Add server: `http://localhost:8000/mcp`
3. Start using Discord tools in your AI conversations
### OpenAI ChatGPT
1. Create a Custom GPT
2. Add Action with URL: `http://your-server:8000/mcp`
3. Configure with your Discord server details
### Claude Desktop
Add to your MCP configuration:
```json
{
"mcpServers": {
"discord-mcp": {
"command": "uvx",
"args": ["discord-mcp@latest"],
"env": {
"DISCORD_BOT_TOKEN": "your_bot_token"
}
}
}
}
```
## π Available MCP Tools
### Channel & Guild Management
- `discord.list_guilds` - List all guilds the bot is member of
- `discord.list_channels` - List channels in a guild
- `discord.get_channel` - Get channel information
- `discord.create_channel` - Create a new channel
- `discord.update_channel` - Update channel settings
- `discord.delete_channel` - Delete a channel
### Message Management
- `discord.list_messages` - List messages in a channel
- `discord.get_message` - Get specific message
- `discord.send_message` - Send a message
- `discord.edit_message` - Edit a message
- `discord.delete_message` - Delete a message
- `discord.search_messages` - Search messages with filters
### Thread Management
- `discord.create_thread` - Create a thread
- `discord.list_threads` - List active/archived threads
- `discord.archive_thread` - Archive a thread
- `discord.unarchive_thread` - Unarchive a thread
### Reactions, Pins & Webhooks
- `discord.add_reaction` - Add reaction to message
- `discord.remove_reaction` - Remove reaction
- `discord.list_reactions` - List all reactions
- `discord.pin_message` - Pin a message
- `discord.unpin_message` - Unpin a message
- `discord.create_webhook` - Create webhook
- `discord.send_via_webhook` - Send message via webhook
### Role & Permission Management
- `discord.list_roles` - List guild roles
- `discord.add_role` - Assign role to member
- `discord.remove_role` - Remove role from member
- `discord.get_permissions` - Get permission information
### Advanced AI Features
- `discord.summarize_messages` - AI-powered message summarization
- `discord.rank_messages` - Intelligent message ranking
- `discord.sync_since` - Delta synchronization
- `discord.analyze_channel_activity` - Channel activity analysis
## π API Reference
### Endpoints
- `GET /` - Server status
- `GET /health` - Health check
- `GET /metrics` - Prometheus-compatible metrics
- `POST /mcp` - MCP JSON-RPC endpoint
### Example Usage
```bash
# List available tools
curl -X POST http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method": "mcp_list_tools", "id": 1}'
# Send a message
curl -X POST http://localhost:8000/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "mcp_call_tool",
"params": {
"tool": "discord.send_message",
"params": {
"channel_id": "123456789",
"content": "Hello from MCP!"
}
},
"id": 1
}'
```
## π Security
### Bot Token Security
- **Never expose your bot token** - Treat it like a password
- **Use environment variables** - Never hardcode in source code
- **Minimal permissions** - Only grant necessary Discord permissions
### Required Discord Permissions
- `Send Messages` - Send messages to channels
- `Read Message History` - Read message history
- `Manage Messages` - Edit/delete messages
- `Add Reactions` - Add reactions to messages
- `Manage Channels` - Create/modify channels (if needed)
- `Manage Roles` - Manage roles (if needed)
### Built-in Security Features
- Automatic `@everyone` and `@here` mention filtering
- Rate limiting with Discord API compliance
- Audit logging for all operations
- Input validation and sanitization
## π Monitoring & Observability
### Health Checks
```bash
curl http://localhost:8000/health
```
### Metrics
```bash
curl http://localhost:8000/metrics
```
### Logging
All logs are structured JSON with fields:
- `request_id` - Unique request identifier
- `tool` - MCP tool being called
- `channel_id` - Discord channel context
- `latency_ms` - Response time
- `success` - Operation success status
## π Production Deployment
### Environment Variables
| Variable | Description | Default | Required |
|----------|-------------|---------|----------|
| `DISCORD_BOT_TOKEN` | Discord Bot Token | - | β
|
| `REDIS_URL` | Redis connection URL | `redis://localhost:6379` | β |
| `LOG_LEVEL` | Logging level | `INFO` | β |
| `RATE_LIMIT_ENABLED` | Enable rate limiting | `true` | β |
| `CACHE_TTL` | Cache TTL in seconds | `300` | β |
| `HOST` | Server host | `0.0.0.0` | β |
| `PORT` | Server port | `8000` | β |
### Cloud Deployment
#### Heroku
```bash
heroku create your-discord-mcp
heroku config:set DISCORD_BOT_TOKEN=your_token
git push heroku main
```
#### Railway
```bash
railway login
railway init
railway add redis
railway deploy
```
#### AWS ECS/Fargate
```bash
# Use provided Dockerfile
docker build -t discord-mcp .
# Deploy to ECS with environment variables
```
## π§ͺ Testing
```bash
# Install test dependencies
pip install pytest pytest-asyncio pytest-cov
# Run unit tests
pytest tests/test_tools/
# Run integration tests
pytest tests/test_integration/
# Run with coverage
pytest --cov=. --cov-report=html
```
## π€ Contributing
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## π Documentation
- **Wiki**: [Complete Documentation](https://github.com/tristan-kkim/discord-mcp/wiki)
- **Installation Guide**: [Step-by-step Setup](https://github.com/tristan-kkim/discord-mcp/wiki/Installation-Guide)
- **Quick Start**: [5-minute Setup](https://github.com/tristan-kkim/discord-mcp/wiki/Quick-Start)
- **API Reference**: [Complete API Docs](https://github.com/tristan-kkim/discord-mcp/wiki/API-Endpoints)
- **Security Guide**: [Best Practices](https://github.com/tristan-kkim/discord-mcp/wiki/Security-Guide)
## π Support
- **Issues**: [GitHub Issues](https://github.com/tristan-kkim/discord-mcp/issues)
- **Discussions**: [GitHub Discussions](https://github.com/tristan-kkim/discord-mcp/discussions)
## π Changelog
### v1.0.0 (2024-10-29)
- π Initial release
- β
Complete Discord API integration
- β
MCP standard compliance
- β
Docker support
- β
Advanced AI features
- β
Security enhancements
- β
Comprehensive documentation
---
## νκ΅μ΄ λ¬Έμ
# Discord MCP μλ²
Discordμ ν΅μ νλ Model Context Protocol(MCP) μλ²μ
λλ€. λͺ¨λ Discord κΈ°λ₯μ MCP Tool ννλ‘ λ
ΈμΆνμ¬ OpenAI, LangChain, Cursor λ±μ MCP ν΄λΌμ΄μΈνΈμμ μμ νκ² μ¬μ©ν μ μμ΅λλ€.
## π μ£Όμ κΈ°λ₯
- **μμ ν Discord API μ§μ**: μ±λ, λ©μμ§, μ€λ λ, 리μ‘μ
, μν , μΉν
λ± λͺ¨λ Discord κΈ°λ₯
- **MCP νμ€ μ€μ**: JSON-RPC 2.0 κΈ°λ°μ νμ€νλ API
- **κ³ μ±λ₯**: Redis μΊμ±, Rate limit κ΄λ¦¬, μ§μ λ°±μ€ν μ¬μλ
- **보μ μ°μ **: λ©μ
νν°λ§, μ΅μ κΆν, κ°μ¬ λ‘κ·Έ
- **νλ‘λμ
μ€λΉ**: Docker μ§μ, CI/CD νμ΄νλΌμΈ, ν¬κ΄μ λͺ¨λν°λ§
- **κ³ κΈ AI κΈ°λ₯**: λ©μμ§ μμ½, νλ λΆμ, μ§λ₯ν νν°λ§
## π λΉ λ₯Έ μμ
### μ¬μ μꡬμ¬ν
- Python 3.12+
- Discord Bot Token
- Redis 6.0+ (μ νμ¬ν - μμΌλ©΄ λ©λͺ¨λ¦¬ μΊμ μ¬μ©)
### μ€μΉ
1. **μ μ₯μ ν΄λ‘ **
```bash
git clone https://github.com/tristan-kkim/discord-mcp.git
cd discord-mcp
```
2. **μμ‘΄μ± μ€μΉ**
```bash
pip install -r requirements.txt
```
3. **νκ²½ μ€μ **
```bash
cp .env.example .env
# .env νμΌμ Discord Bot Token μ€μ
```
4. **μλ² μ€ν**
```bash
python run.py
```
### Docker λ°°ν¬
```bash
# Docker Compose μ¬μ© (κΆμ₯)
export DISCORD_BOT_TOKEN=your_bot_token_here
docker-compose up -d
# λλ Docker μ§μ μ¬μ©
docker build -t discord-mcp .
docker run -d -p 8000:8000 -e DISCORD_BOT_TOKEN=your_token discord-mcp
```
## π§ MCP ν΄λΌμ΄μΈνΈ ν΅ν©
### Cursor IDE
1. Cursor μ€μ β MCP μλ² μ΄κΈ°
2. μλ² μΆκ°: `http://localhost:8000/mcp`
3. AI λνμμ Discord λꡬ μ¬μ© μμ
### OpenAI ChatGPT
1. Custom GPT μμ±
2. Action μΆκ°: `http://your-server:8000/mcp`
3. Discord μλ² μΈλΆμ¬νμΌλ‘ ꡬμ±
### Claude Desktop
MCP ꡬμ±μ μΆκ°:
```json
{
"mcpServers": {
"discord-mcp": {
"command": "uvx",
"args": ["discord-mcp@latest"],
"env": {
"DISCORD_BOT_TOKEN": "your_bot_token"
}
}
}
}
```
## π μ¬μ© κ°λ₯ν MCP λꡬ
### μ±λ λ° κΈΈλ κ΄λ¦¬
- `discord.list_guilds` - λ΄μ΄ μν λͺ¨λ κΈΈλ λͺ©λ‘
- `discord.list_channels` - κΈΈλμ μ±λ λͺ©λ‘
- `discord.get_channel` - μ±λ μ 보 μ‘°ν
- `discord.create_channel` - μ μ±λ μμ±
- `discord.update_channel` - μ±λ μ€μ μ
λ°μ΄νΈ
- `discord.delete_channel` - μ±λ μμ
### λ©μμ§ κ΄λ¦¬
- `discord.list_messages` - μ±λμ λ©μμ§ λͺ©λ‘
- `discord.get_message` - νΉμ λ©μμ§ μ‘°ν
- `discord.send_message` - λ©μμ§ μ μ‘
- `discord.edit_message` - λ©μμ§ νΈμ§
- `discord.delete_message` - λ©μμ§ μμ
- `discord.search_messages` - νν°λ‘ λ©μμ§ κ²μ
### μ€λ λ κ΄λ¦¬
- `discord.create_thread` - μ€λ λ μμ±
- `discord.list_threads` - νμ±/μμΉ΄μ΄λΈλ μ€λ λ λͺ©λ‘
- `discord.archive_thread` - μ€λ λ μμΉ΄μ΄λΈ
- `discord.unarchive_thread` - μ€λ λ μΈμμΉ΄μ΄λΈ
### 리μ‘μ
, ν λ° μΉν
- `discord.add_reaction` - λ©μμ§μ 리μ‘μ
μΆκ°
- `discord.remove_reaction` - 리μ‘μ
μ κ±°
- `discord.list_reactions` - λͺ¨λ 리μ‘μ
λͺ©λ‘
- `discord.pin_message` - λ©μμ§ κ³ μ
- `discord.unpin_message` - λ©μμ§ κ³ μ ν΄μ
- `discord.create_webhook` - μΉν
μμ±
- `discord.send_via_webhook` - μΉν
μΌλ‘ λ©μμ§ μ μ‘
### μν λ° κΆν κ΄λ¦¬
- `discord.list_roles` - κΈΈλ μν λͺ©λ‘
- `discord.add_role` - λ©€λ²μκ² μν λΆμ¬
- `discord.remove_role` - λ©€λ²μμ μν μ κ±°
- `discord.get_permissions` - κΆν μ 보 μ‘°ν
### κ³ κΈ AI κΈ°λ₯
- `discord.summarize_messages` - AI κΈ°λ° λ©μμ§ μμ½
- `discord.rank_messages` - μ§λ₯ν λ©μμ§ μμ
- `discord.sync_since` - λΈν λκΈ°ν
- `discord.analyze_channel_activity` - μ±λ νλ λΆμ
## π 보μ
### Bot Token 보μ
- **Bot ν ν°μ μ λ λ
ΈμΆνμ§ λ§μΈμ** - λΉλ°λ²νΈμ²λΌ μ·¨κΈ
- **νκ²½λ³μ μ¬μ©** - μμ€μ½λμ νλμ½λ© κΈμ§
- **μ΅μ κΆν** - νμν Discord κΆνλ§ λΆμ¬
### νμν Discord κΆν
- `Send Messages` - μ±λμ λ©μμ§ μ μ‘
- `Read Message History` - λ©μμ§ κΈ°λ‘ μ½κΈ°
- `Manage Messages` - λ©μμ§ νΈμ§/μμ
- `Add Reactions` - λ©μμ§μ 리μ‘μ
μΆκ°
- `Manage Channels` - μ±λ μμ±/μμ (νμμ)
- `Manage Roles` - μν κ΄λ¦¬ (νμμ)
### λ΄μ₯ 보μ κΈ°λ₯
- `@everyone` λ° `@here` λ©μ
μλ νν°λ§
- Discord API μ€μ Rate limiting
- λͺ¨λ μμ
μ λν κ°μ¬ λ‘κ·Έ
- μ
λ ₯ κ²μ¦ λ° μ μ
## π λͺ¨λν°λ§ λ° κ΄μ°°μ±
### ν¬μ€μ²΄ν¬
```bash
curl http://localhost:8000/health
```
### λ©νΈλ¦
```bash
curl http://localhost:8000/metrics
```
### λ‘κΉ
λͺ¨λ λ‘κ·Έλ λ€μ νλκ° ν¬ν¨λ ꡬ쑰νλ JSONμ
λλ€:
- `request_id` - κ³ μ μμ² μλ³μ
- `tool` - νΈμΆλλ MCP λꡬ
- `channel_id` - Discord μ±λ 컨ν
μ€νΈ
- `latency_ms` - μλ΅ μκ°
- `success` - μμ
μ±κ³΅ μν
## π νλ‘λμ
λ°°ν¬
### νκ²½ λ³μ
| λ³μ | μ€λͺ
| κΈ°λ³Έκ° | νμ |
|------|------|--------|------|
| `DISCORD_BOT_TOKEN` | Discord Bot Token | - | β
|
| `REDIS_URL` | Redis μ°κ²° URL | `redis://localhost:6379` | β |
| `LOG_LEVEL` | λ‘κΉ
λ 벨 | `INFO` | β |
| `RATE_LIMIT_ENABLED` | Rate limiting νμ±ν | `true` | β |
| `CACHE_TTL` | μΊμ TTL (μ΄) | `300` | β |
| `HOST` | μλ² νΈμ€νΈ | `0.0.0.0` | β |
| `PORT` | μλ² ν¬νΈ | `8000` | β |
### ν΄λΌμ°λ λ°°ν¬
#### Heroku
```bash
heroku create your-discord-mcp
heroku config:set DISCORD_BOT_TOKEN=your_token
git push heroku main
```
#### Railway
```bash
railway login
railway init
railway add redis
railway deploy
```
#### AWS ECS/Fargate
```bash
# μ 곡λ Dockerfile μ¬μ©
docker build -t discord-mcp .
# νκ²½ λ³μμ ν¨κ» ECSμ λ°°ν¬
```
## π§ͺ ν
μ€νΈ
```bash
# ν
μ€νΈ μμ‘΄μ± μ€μΉ
pip install pytest pytest-asyncio pytest-cov
# λ¨μ ν
μ€νΈ μ€ν
pytest tests/test_tools/
# ν΅ν© ν
μ€νΈ μ€ν
pytest tests/test_integration/
# 컀λ²λ¦¬μ§μ ν¨κ» μ€ν
pytest --cov=. --cov-report=html
```
## π€ κΈ°μ¬νκΈ°
κΈ°μ¬λ₯Ό νμν©λλ€! μμΈν λ΄μ©μ [κΈ°μ¬ κ°μ΄λ](CONTRIBUTING.md)λ₯Ό μ°Έμ‘°νμΈμ.
1. μ μ₯μ ν¬ν¬
2. κΈ°λ₯ λΈλμΉ μμ± (`git checkout -b feature/amazing-feature`)
3. λ³κ²½μ¬ν μ»€λ° (`git commit -m 'Add amazing feature'`)
4. λΈλμΉμ νΈμ (`git push origin feature/amazing-feature`)
5. Pull Request μ΄κΈ°
## π λΌμ΄μ μ€
μ΄ νλ‘μ νΈλ MIT λΌμ΄μ μ€ νμ λ°°ν¬λ©λλ€. μμΈν λ΄μ©μ [LICENSE](LICENSE) νμΌμ μ°Έμ‘°νμΈμ.
## π λ¬Έμ
- **Wiki**: [μμ ν λ¬Έμ](https://github.com/tristan-kkim/discord-mcp/wiki)
- **μ€μΉ κ°μ΄λ**: [λ¨κ³λ³ μ€μ ](https://github.com/tristan-kkim/discord-mcp/wiki/Installation-Guide)
- **λΉ λ₯Έ μμ**: [5λΆ μ€μ ](https://github.com/tristan-kkim/discord-mcp/wiki/Quick-Start)
- **API μ°Έμ‘°**: [μμ ν API λ¬Έμ](https://github.com/tristan-kkim/discord-mcp/wiki/API-Endpoints)
- **보μ κ°μ΄λ**: [λͺ¨λ² μ¬λ‘](https://github.com/tristan-kkim/discord-mcp/wiki/Security-Guide)
## π μ§μ
- **μ΄μ**: [GitHub Issues](https://github.com/tristan-kkim/discord-mcp/issues)
- **ν λ‘ **: [GitHub Discussions](https://github.com/tristan-kkim/discord-mcp/discussions)
## π λ³κ²½ λ‘κ·Έ
### v1.0.0 (2024-10-29)
- π μ΄κΈ° 릴리μ¦
- β
μμ ν Discord API ν΅ν©
- β
MCP νμ€ μ€μ
- β
Docker μ§μ
- β
κ³ κΈ AI κΈ°λ₯
- β
보μ κ°ν
- β
ν¬κ΄μ λ¬Έμν