Discord MCP Server
Enables direct interaction with Discord servers to send messages, read channel history, and post rich embeds through natural conversation. It provides tools for listing channels and managing communication within Discord guilds using the Model Context Protocol.
README
Discord MCP Server
A Python MCP (Model Context Protocol) server that lets you interact with Discord directly from Claude Code sessions. Send messages, read channels, post rich embeds, and list server channels — all through natural conversation with Claude.
Prerequisites
- Docker and Docker Compose installed
- Claude Code CLI installed
- A Discord bot token (setup guide below)
Discord Bot Setup
- Go to the Discord Developer Portal
- Click New Application, give it a name, and create it
- Go to Bot in the left sidebar
- Click Reset Token and copy the token — this is your
DISCORD_BOT_TOKEN - Under Privileged Gateway Intents, enable Message Content Intent
- Go to OAuth2 > URL Generator in the left sidebar
- Select scopes:
bot - Select bot permissions:
Send Messages,Read Message History,View Channels - Copy the generated URL and open it in your browser to invite the bot to your server
Installation
1. Clone the repository
git clone <your-repo-url>
cd discord-mcp-server
2. Set up environment variables
cp .env.example .env
# Edit .env and add your DISCORD_BOT_TOKEN and optionally DISCORD_DEFAULT_GUILD_ID
3. Build the Docker image
docker compose build
4. Register with Claude Code
Add the following to your Claude Code MCP settings. You can configure this in
~/.claude/settings.json (global) or .mcp.json (project-level):
{
"mcpServers": {
"discord-mcp": {
"command": "docker",
"args": [
"compose",
"-f", "/absolute/path/to/discord-mcp-server/docker-compose.yml",
"run", "--rm", "-i", "discord-mcp"
],
"env": {
"DISCORD_BOT_TOKEN": "your-bot-token-here",
"DISCORD_DEFAULT_GUILD_ID": "your-guild-id-here"
}
}
}
}
Note: Replace
/absolute/path/to/discord-mcp-serverwith the actual absolute path to this project on your machine. Replace the token and guild ID with your actual values.
Usage Examples
Once configured, you can use these tools in any Claude Code session:
List channels in a server:
"Show me all the channels in my Discord server"
Send a message:
"Send 'Deployment complete!' to the #general channel"
Read recent messages:
"What are the last 5 messages in #random?"
Send a rich embed:
"Send an embed to #updates with title 'Release v2.0' and a green color, with fields for 'Changes' and 'Breaking Changes'"
Tool Reference
discord_list_channels
Lists all text channels in a Discord server.
| Parameter | Type | Required | Description |
|---|---|---|---|
guild_id |
string | Yes | Discord server/guild ID |
discord_send_message
Sends a plain text message to a channel.
| Parameter | Type | Required | Description |
|---|---|---|---|
channel |
string | Yes | Channel ID or name (e.g. "general") |
content |
string | Yes | Message text (max 2000 chars) |
guild_id |
string | No | Server ID. Required if channel is a name and no default is set. |
discord_read_messages
Reads recent messages from a channel.
| Parameter | Type | Required | Description |
|---|---|---|---|
channel |
string | Yes | Channel ID or name |
guild_id |
string | No | Server ID. Required if channel is a name and no default is set. |
limit |
integer | No | Number of messages (default: 10, max: 50) |
discord_send_embed
Sends a rich embed message to a channel.
| Parameter | Type | Required | Description |
|---|---|---|---|
channel |
string | Yes | Channel ID or name |
title |
string | Yes | Embed title (max 256 chars) |
description |
string | No | Embed body text (max 4096 chars) |
color |
integer | No | Color as decimal (e.g. 3447003 for blue) |
fields |
list | No | List of {name, value, inline} objects (max 25 fields) |
content |
string | No | Plain text alongside the embed |
guild_id |
string | No | Server ID. Required if channel is a name and no default is set. |
Environment Variables
| Variable | Required | Description |
|---|---|---|
DISCORD_BOT_TOKEN |
Yes | Bot token from Discord Developer Portal |
DISCORD_DEFAULT_GUILD_ID |
No | Default server ID for all tool calls |
Architecture
Claude Code ←stdio→ MCP Server (Python) ←HTTPS→ Discord API v10
src/discord_mcp/types.py— Pydantic models with Discord API limit validation (Channel, Message, SendResult, Embed)src/discord_mcp/discord_client.py— Async Discord REST API wrapper using httpxsrc/discord_mcp/server.py— MCP tool definitions and handler functions
Key design decisions:
- All Discord API interaction goes through
DiscordClient— never call httpx directly from server.py - Tool handlers are separated from
@mcp.tool()decorators for testability - Channel names are resolved case-insensitively via the Discord API
- Guild ID follows a fallback chain: explicit parameter →
DISCORD_DEFAULT_GUILD_IDenv var → None
Security
- Input validation — Guild IDs and channel IDs are validated as numeric Discord snowflakes before use in API URLs
- Content length enforcement — Message content (2000 chars) and all embed fields (title 256, description 4096, field name 256, field value 1024, max 25 fields, 6000 total) are validated before sending to the Discord API
- Embed sanitization — Embed fields are validated through Pydantic models (
EmbedField), preventing injection of arbitrary embed properties - Error message hygiene — Failed channel lookups do not enumerate available channels, preventing server structure disclosure
- Rate limit handling — The client retries once with backoff on 429 responses (capped at 5s)
- Docker hardening — Container runs as a non-root
appuser - Dependency pinning — All dependencies (production and dev) use compatible-release (
~=) constraints - Reproducible builds —
requirements-lock.txtpins all transitive dependency versions; Docker builds install from the lock file
Development
Running locally (without Docker)
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
export DISCORD_BOT_TOKEN=your-token
export DISCORD_DEFAULT_GUILD_ID=your-guild-id
discord-mcp
Running tests
pip install -e ".[dev]"
pytest tests/ -v
Tests use respx to mock httpx requests — no real Discord API calls are made.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。