SuperAPI AI Directory

discord-mcp

Discord REST API: list channels, categories, roles and permission overwrites, with channel, role, guild and message management tools disabled by default.

Open website

About this tool

Purpose

discord-mcp is an MCP (Model Context Protocol) server based on the real Discord REST API, designed to let AI agents such as Claude interact with Discord through standard tool calls, for example calling list_channels(guild_id="...") to list channels, without having to build authenticated HTTP requests themselves. It is the fifth flagship project in the author's portfolio and follows the standards of github-mcp / bus-mcp (standalone pyproject, fastmcp server, typed errors, real test suite, honest README).

Main capabilities

Read-only tools (always enabled, 5 total)

  • List channels, categories, roles, and permission overwrites, etc. The specific tool names are not listed one by one in the material, but the material mentions that list_channels and list_roles are read-only tools, and the live smoke test only calls these two.

Write tools (disabled by default, 7 total)

  • The environment variable DISCORD_MCP_ENABLE_WRITE=1 (or true / yes / on) must be set to enable them. When it is unset or set to another value, all write tool calls are rejected locally, no Discord API request is made, and a policy_refusal error is returned.
  • Write tools include: create_channel, edit_channel, create_role, edit_role, edit_guild, delete_channel, create_message.
  • create_message validates the content locally: it must be a non-empty string and no more than 2000 characters (Discord's real message length limit); if violated, it returns validation_error rather than a raw Discord 400.
  • The icon_base64 / banner_base64 parameters of edit_guild accept a full data URI or raw base64 (assumed to be PNG and wrapped as data:image/png;base64,...). This PNG assumption is not verified.
  • delete_channel uses the same environment variable gating as the other write toolsand has no separate or lower threshold.

Typed errors

All tools return structured results, with success as {"ok": true, ...} and failure as {"ok": false, "error": {...}}, and do not throw unhandled exceptions. Error types include:

  • network_error: connection refused, timeout, DNS failure, or malformed request URL.
  • auth_error (401): missing or invalid bot token.
  • permission_error (403, with a Discord JSON error body): the bot lacks permission or is not in the server.
  • cloudflare_blocked (403, without a JSON error body): Discord's Cloudflare edge may reject requests due to a missing descriptive User-Agent. This is a heuristic judgment, not deterministic.
  • not_found (404): invalid guild, channel, role, or member id.
  • rate_limited (429): Discord rate limiting, carrying retry_after_s; the server does not retry automatically.
  • decode_error: the 2xx response body is not valid JSON.
  • discord_api_error: other 4xx/5xx.
  • policy_refusal: the write tool group is disabled.
  • invalid_id: the id does not pass snowflake shape validation.
  • validation_error: only for create_message, when the content is empty or exceeds 2000 characters.

Usage

Quick start

Add the following configuration to Claude Desktop/Code's MCP configuration (register it as a stdio server, invoking run_server.py via an absolute path):

{
  "mcpServers": {
    "discord-mcp": {
      "command": "python",
      "args": ["/absolute/path/to/run_server.py"],
      "env": {}
    }
  }
}
  • When DISCORD_BOT_TOKEN is not set, each tool call still returns a clean structured error (Discord's own 401) rather than crashing.
  • Write tools also require DISCORD_MCP_ENABLE_WRITE=1 to be set in the same env block, otherwise they are rejected locally and return policy_refusal.
  • A real bot token should not be written to ~/.claude.json; instead, set DISCORD_BOT_TOKEN in the process that starts the server.

Handshake check

Prints the twelve registered tool names without starting the transport, to verify that the server is wired up correctly.

Use cases

  • Let a Claude agent perform read-only queries in a Discord server (such as listing channels and roles).
  • After write tools are explicitly enabled, perform operations such as creating channels, roles, and sending messages.
  • Serve as an MCP server reference implementation showing how to connect to a real external SaaS API.

Limitations

  • It is not Discord's official MCP server and is not affiliated with Discord Inc.
  • The distinction between cloudflare_blocked and permission_error is heuristic and not guaranteed by Discord documentation.
  • get_channel_permission_overwrites and get_member_roles have not been covered by live smoke tests for all edge cases, only by respx-mocked unit tests.
  • Pagination is not implemented, and there is no list_members tool.
  • The PNG assumption for edit_guild's icon_base64 / banner_base64 has not been verified.
  • All write tools have not been tested against the real Discord API (by design), including create_message.
  • DISCORD_API_BASE is fixed to https://discord.com/api/v10,不可通过环境变量覆盖。
  • Automatic retry for rate limits is not supported; this is left to the caller.
  • Write operations are limited to the above 7 tools and do not support member role assignment/kick/ban, message edit/delete, embeds/attachments/reactions, webhook management, etc.

Testing

163 tests in total: 162 unit tests (respx-mocked, zero real network) + 1 live smoke test (requires DISCORD_MCP_LIVE=1 and DISCORD_MCP_SMOKE_GUILD_ID to be set). The live smoke test only calls list_channels / list_roles, read-only. Write tool coverage includes gate-closed rejection, gate-open success paths, error propagation, etc.