Skip to main content
Glama
discord-mcp

discord-mcp

by wjrosa
README.md
# discord-mcp

An MCP server that gives an AI agent (Claude Code, Claude Desktop, any MCP client) the **whole Discord bot
API**: 108 tools for messages, forums and threads, channels and permissions, members, roles, moderation, webhooks,
scheduled events, AutoMod, invites, slash commands, polls, live gateway events and button prompts. One server
can drive **several bots** at once.

It was built to run the Discord side of a small game studio's communities (help-desk forums, bug reports,
staff notifications, approvals) and is tested against live servers.

- **Agent-friendly inputs.** Wherever a channel is asked you can pass an id, a `discord.com/channels/...` link,
  `#name` (emoji decorations like `🚩・bugs` are ignored), or an alias you configured. Users take an id, a
  mention or a name. Roles take an id or a name. Times take ISO or relative (`2h`, `7d`, `+1h`).
- **Compact output.** Messages come back oldest first, with author, content, attachments, embeds, reactions,
  reply target and a link. Pass `raw=True` for Discord's full objects.
- **Workflow tools, not just endpoints.**
  - `link_open` reads any pasted link the way a person would.
  - `forum_threads(waiting_only=True)` finds forum posts whose last message is not from staff.
  - `thread_close` replies, tags, reacts and archives in one call.
  - `ask_buttons` posts a question with buttons and waits for an allowed person's click.
  - `permissions_explain` answers "why can't X see #Y".
- **Safe by default.**
  - `DISCORD_MCP_READ_ONLY=1` removes every write tool.
  - Profiles can be read-only, and `DISCORD_MCP_TOOLSETS` / `DISCORD_MCP_DENY_TOOLS` trim the tool list.
  - Destructive tools carry MCP `destructiveHint`.
  - `messages_purge` and `members_prune` default to a dry run.
  - `reason` goes to the server's audit log.
  - Tokens and webhook URLs are never printed unless you ask (`reveal_url`).
- **Robust.** Per-route rate-limit buckets, 429 and 5xx retry, and Discord's real error text and code returned to
  the agent ("Missing Permissions [code 50013]"). The gateway is opened only when a live tool needs it.

## Install

Needs Python 3.11+ and [uv](https://docs.astral.sh/uv/).

```bash
claude mcp add discord --env DISCORD_TOKEN=YOUR_BOT_TOKEN -- \
  uvx --from git+https://github.com/wjrosa/discord-mcp discord-mcp
```

Or clone and run `uv sync`, then point your client at `.venv/bin/discord-mcp` (Windows:
`.venv\Scripts\discord-mcp.exe`). `discord-mcp --http --port 8765` serves streamable HTTP instead of stdio.

### Create the bot

1. https://discord.com/developers/applications → New Application → Bot → Reset Token (that is
   `DISCORD_TOKEN`).
2. Under *Privileged Gateway Intents* enable **Message Content** (needed to read message text) and **Server
   Members** (needed for `members_list`). Presence is optional. Intents the bot lacks are dropped automatically
   and reported by `gateway_start`.
3. OAuth2 → URL Generator → scopes `bot` + `applications.commands`, then pick the permissions you want the
   agent to have and open the URL to add the bot to your server. What the bot can do is exactly what you grant
   here. For example, without *View Audit Log* the `audit_log` tool returns 403.

## Configuration

| Variable | Meaning |
|---|---|
| `DISCORD_TOKEN` | Bot token for a single profile named `default` |
| `DISCORD_GUILD_ID` | Default server for that profile (optional when the bot is in one server) |
| `DISCORD_MCP_CONFIG` | Path to a JSON file with several bot profiles (below) |
| `DISCORD_MCP_DEFAULT_PROFILE` | Which profile tools use when `bot` is omitted (`none` = every call must pass `bot`) |
| `DISCORD_MCP_READ_ONLY` | `1` = register read tools only |
| `DISCORD_MCP_TOOLSETS` | Comma list of toolsets to load (default `all`; `core` always loads) |
| `DISCORD_MCP_DENY_TOOLS` | Comma list of tool names never to register (e.g. `ban_add,guild_leave`) |
| `DISCORD_MCP_INTENTS` | Gateway intents to request (default: everything except typing) |

Several bots (`DISCORD_MCP_CONFIG`):

```json
{
  "default": "game1",
  "profiles": {
    "game1": {
      "env_file": "C:/secrets/game1.env", "env_key": "DISCORD_BOT_TOKEN",
      "guild_id": "123456789012345678",
      "channels": {"deploys": "234567890123456789", "bugs": "345678901234567890"}
    },
    "game2": {"token_env": "GAME2_DISCORD_TOKEN", "read_only": true}
  }
}
```

The token can come from `token_env` (an environment variable), `env_file` + `env_key` (a `.env` file),
`token_file` (a file holding only the token) or `token` (inline, not recommended). Every tool takes
`bot="game2"` to pick a profile. A broken profile is reported by `bot_profiles` and does not stop the others.
`discord-mcp --check` prints what loaded.

## Tools

| Toolset | Tools |
|---|---|
| core | `bot_profiles`, `bot_info`, `guild_overview`, `user_info`, `snowflake`, `permissions_list` |
| messages | `messages_read`, `message_get`, `link_open`, `messages_search`, `attachments_download`, `channel_export`, `message_send`, `dm_send`, `dm_channel`, `message_edit`, `message_delete`, `message_crosspost`, `message_forward`, `reaction_add`, `reaction_remove`, `reactions_list`, `pins_list`, `message_pin`, `poll_create`, `poll_results`, `poll_end`, `typing_start` |
| threads | `threads_list`, `forum_threads`, `thread_read`, `thread_create`, `forum_post`, `thread_modify`, `thread_close`, `thread_members`, `thread_member_set`, `forum_tags_set` |
| channels | `channels_list`, `channel_info`, `channel_create`, `channel_modify`, `channel_delete`, `channel_permissions_set`, `channel_permissions_delete`, `channels_reorder`, `channel_follow`, `permissions_explain` |
| members | `members_list`, `members_search`, `member_info`, `member_modify` |
| moderation | `messages_purge`, `member_timeout`, `member_kick`, `ban_add`, `ban_remove`, `bans_list`, `members_prune`, `audit_log` |
| roles | `roles_list`, `role_create`, `role_modify`, `role_delete`, `role_members_set` |
| guild | `bot_modify`, `guild_modify`, `guild_settings`, `guild_settings_update`, `guild_template`, `guild_leave`, `integration_delete` |
| expressions | `emojis_list`, `emoji_create`, `emoji_modify`, `sticker_create`, `sticker_delete`, `soundboard_sound` |
| webhooks | `webhooks_list`, `webhook_create`, `webhook_modify`, `webhook_send`, `webhook_info` |
| events | `events_list`, `event_create`, `event_modify`, `event_users` |
| automod | `automod_rules`, `automod_rule_set` |
| invites | `invites_list`, `invite_create`, `invite_info`, `invite_delete` |
| commands | `commands_list`, `command_set` |
| live | `gateway_start`, `gateway_status`, `events_read`, `events_wait`, `presence_set`, `ask_buttons`, `wait_for_reply`, `wait_for_reaction` |
| monetization | `monetization`, `entitlement_action` |
| voice | `stage_instance`, `voice_channel_status` |
| raw | `discord_api`: any REST v10 endpoint, for whatever has no dedicated tool |

`webhook_send` and `webhook_info` need no bot at all, just a webhook URL.

### Recipes

- **Read a pasted link.** `link_open(link)`. A message link returns the message with context, and a forum
  post link returns the whole post.
- **Help-desk forum.** Run `forum_threads(forum="#bugs", waiting_only=True, staff_roles=["Staff"],
  exclude_tags=["Solved"])`, then `thread_read`. Reply with `message_send(channel=thread, content=..., reply_to=link)`.
  Finish with `thread_close(thread, reply="Fixed in 1.2.3", tag="Solved", react="✅")`.
- **Approval.** `ask_buttons(channel="#deploys", question="Ship build 812?", options=["Ship", "Hold"],
  allowed_roles=["Owner"])` returns the choice and who made it.
- **Moderation sweep.** `messages_purge(channel, author=..., after="1h")` previews first; pass `dry_run=False`
  to delete. Then `member_timeout(user, "1d", reason=...)`.
- **Staff alert without a bot.** `webhook_send(webhook_url, content, username="Ops")`.

## Live events

`gateway_start` (or any live tool) opens one gateway connection per bot profile. Events are kept in a ring
buffer of 5,000, which `events_read` and `events_wait` filter by type, channel, user and text. Notes:

- Several gateway sessions on one token are allowed. Discord counts each connect against the bot's daily
  identify limit, which is why the server never connects at startup.
- Buttons whose `custom_id` starts with `mcp:` are acknowledged within Discord's 3-second limit, and other
  custom ids are left to whatever program normally runs the bot. If the application has an *Interactions
  Endpoint URL*, clicks go to that URL and never reach the gateway; `bot_info` shows it.
- `wait_for_reply` and `wait_for_reaction` poll over REST, so they work without the gateway.

## Traps this handles for you

- Bot requests without a `DiscordBot (url, version)` User-Agent fail with HTTP 400 code 40333 while
  `/users/@me` still works. The server always sends one.
- `GET /channels/{forum}/messages` returns an empty list. Forum posts are threads, so the server lists them
  from the active-thread and archived-thread endpoints.
- Archived threads only accept `archived=false` in an edit. `thread_modify` and `thread_close` unarchive first.
- When a bot creates a channel inside a category it cannot see, Discord answers 403. The server creates the
  channel top-level, then moves it into the category.
- A private channel created without an allow for the bot locks the bot out for good. `channel_create` always
  keeps the bot's own view/send access.
- Message content over 2000 characters is refused with a clear message before any request is made.

## Development

```bash
uv sync
uv run pytest tests/test_offline.py                      # no network
DISCORD_MCP_CONFIG=... uv run python tests/live_readonly.py   # read-only against your servers
DISCORD_MCP_CONFIG=... uv run python tests/live_write.py <profile>   # writes inside a temporary hidden channel
```

MIT licensed. Issues and pull requests welcome.