Discord MCP Server

Discord MCP Server

A secure server that enables interaction with Discord channels through JWT-authenticated API calls, allowing users to send messages, fetch channel data, search content, and perform moderation actions.

Category
访问服务器

README

Discord MCP Server with Bearer Token Authentication

A secure Discord MCP (Model Context Protocol) server that provides Discord integration tools with JWT Bearer Token authentication.

🔐 Security Features

  • Bearer Token Authentication using JWT tokens
  • Discord token protection - tokens are embedded in JWT claims, not passed as parameters
  • Audit logging - all tool calls are logged with user information
  • Temporary bot connections - no persistent Discord bot instances
  • RSA key pair encryption for token signing and verification

📋 Available Tools

Tool Description
send_message Send messages to Discord channels
get_messages Fetch recent messages from channels
get_channel_info Get channel metadata and information
search_messages Search for messages containing keywords
moderate_content Delete specific messages from channels

🚀 Setup and Installation

Prerequisites

  • Python 3.8+
  • Discord bot token with appropriate permissions
  • Virtual environment (recommended)

Installation

  1. Install dependencies (already installed in your venv):

    pip install discord.py fastapi fastmcp uvicorn python-dotenv PyJWT
    
  2. Create a Discord bot and get your bot token:

    • Go to Discord Developer Portal
    • Create a new application and bot
    • Copy the bot token
    • Invite the bot to your server with necessary permissions
  3. Set up environment variables (optional):

    # Create .env file
    echo "DISCORD_TOKEN=your_discord_bot_token_here" > .env
    

🏃‍♂️ Running the Server

Start the Server

python app.py

The server will start on http://localhost:8000 and display:

  • Available tools
  • Authentication information
  • Token generation instructions

Generate Access Token

Replace YOUR_DISCORD_TOKEN with your actual Discord bot token:

python -c "from app import generate_access_token; print(generate_access_token('YOUR_DISCORD_TOKEN'))"

🔧 Using the Server

Authentication

All requests must include a JWT Bearer token in the Authorization header:

Authorization: Bearer <your_jwt_token>

Making Tool Calls

Endpoint: POST /mcp/v1/tools/invoke

Headers:

Authorization: Bearer <your_jwt_token>
Content-Type: application/json

Request Format:

{
  "method": "tool_name",
  "params": {
    "parameter1": "value1",
    "parameter2": "value2"
  }
}

Examples

Get Channel Information

curl -X POST http://localhost:8000/mcp/v1/tools/invoke \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "method": "get_channel_info",
    "params": {
      "channel_id": "1234567890123456789"
    }
  }'

Send a Message

curl -X POST http://localhost:8000/mcp/v1/tools/invoke \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "method": "send_message",
    "params": {
      "channel_id": "1234567890123456789",
      "message": "Hello from MCP server!"
    }
  }'

Search Messages

curl -X POST http://localhost:8000/mcp/v1/tools/invoke \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "method": "search_messages",
    "params": {
      "channel_id": "1234567890123456789",
      "query": "hello",
      "limit": 10
    }
  }'

🧪 Testing

Use the provided test script to verify your setup:

# Update YOUR_DISCORD_TOKEN in test_server.py first
python test_server.py

📊 Monitoring and Logs

  • Audit logs are written to audit.log
  • Server logs are displayed in the console
  • Each tool call is logged with user ID, parameters, and success/failure status

🏗️ Architecture

Authentication Flow

  1. Token Generation: Discord token is embedded in JWT claims
  2. Request Authentication: JWT is validated using RSA public key
  3. Token Extraction: Discord token is extracted from validated JWT
  4. Tool Execution: Temporary Discord bot connection is created
  5. Cleanup: Bot connection is properly closed after operation

Security Benefits

  • No token exposure: Discord tokens never appear in request parameters
  • Centralized auth: Single authentication point for all tools
  • Audit trail: Complete logging of all authenticated operations
  • Temporary connections: No persistent bot instances reduce attack surface

🔒 Security Considerations

Development vs Production

  • Development: Uses generated RSA key pairs (current setup)
  • Production: Should use external OAuth 2.1 provider or IdP

Token Security

  • JWT tokens expire after 1 hour (configurable)
  • Discord tokens are embedded in JWT claims, not visible in requests
  • RSA encryption ensures token integrity

Best Practices

  1. Rotate tokens regularly in production
  2. Use HTTPS for all communications
  3. Store Discord tokens securely (environment variables, secrets manager)
  4. Monitor audit logs for unusual activity
  5. Implement rate limiting if needed

🤝 Integration with MCP Clients

This server follows the MCP specification and can be used with:

  • Claude Desktop with MCP integration
  • Custom MCP clients
  • API testing tools (Postman, curl, etc.)

📚 References

🐛 Troubleshooting

Common Issues

  1. "No Discord token found in authentication"

    • Verify your JWT token contains the Discord token in claims
    • Check token generation with correct Discord bot token
  2. "Bot doesn't have permission"

    • Ensure Discord bot has necessary permissions in the server
    • Check channel permissions specifically
  3. "Server not reachable"

    • Verify server is running on localhost:8000
    • Check for port conflicts
  4. "Invalid token"

    • Token may be expired (1 hour default)
    • Generate a new token
    • Verify token format in Authorization header

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选