Skip to main content
Glama
fboiero

Discord MCP

by fboiero

Discord MCP

远程 MCP 服务器(Streamable HTTP),将 Discord 暴露为工具, 用于从 Claude → 设置 → 连接器 → 添加自定义连接器 连接(https://claude.ai/ask-your-org/setup自定义 选项)。

提供的功能

基于 discord.py 的 Discord API 工具:

  • list_guilds — 机器人可访问的服务器。

  • list_channels(guild_id) — 服务器中的频道。

  • list_members(guild_id, limit) — 服务器成员。

  • list_roles(guild_id) — 服务器角色。

  • send_message(channel_id, content) — 发送消息。

  • read_messages(channel_id, limit, before_message_id) — 读取历史记录。

  • create_thread(channel_id, name, message_id?, auto_archive_minutes) — 创建线程。

  • add_reaction(channel_id, message_id, emoji) / remove_reaction(...) — 表情反应。

  • add_role_to_member(guild_id, user_id, role_id) / remove_role_from_member(...) — 角色管理。

所有 ID(服务器、频道、消息、用户、角色)均为 Discord 的 snowflake,以字符串形式表示。

Related MCP server: Discord MCP Server

1. 创建 Discord 机器人

  1. 进入 Discord 开发者门户,创建一个 New Application

  2. Bot 中,创建机器人并复制 TokenReset Token 按钮)。这就是 DISCORD_BOT_TOKEN 的值。

  3. 在同一部分 Bot → Privileged Gateway Intents,启用:

    • Server Members Intentlist_members 和角色管理所需)。

    • Message Content Intent(读取 read_messages 中消息内容所需)。

  4. OAuth2 → URL Generator

    • Scopes:bot

    • Bot Permissions(根据您的使用场景调整):View ChannelsSend MessagesRead Message HistoryCreate Public ThreadsAdd ReactionsManage Roles

    • 打开生成的 URL 并邀请机器人到您要使用的服务器。

  5. 如果要使用 add_role_to_member / remove_role_from_member,请确保 机器人的角色层级高于(更大权限)您想要分配的角色。

2. 配置环境变量

.env.example 复制为 .env 并填写:

cp .env.example .env
  • DISCORD_BOT_TOKEN:上一步的令牌。

  • MCP_AUTH_TOKEN:自定义密钥用于保护服务器(可使用 python -c "import secrets; print(secrets.token_urlsafe(32))" 生成)。Claude.ai 会在每个请求中将其作为 Authorization: Bearer <token> 头发送(参见第 4 步)。

  • 其余变量具有合理的默认值 — 请查看 .env.example 中的注释。

3. 运行服务器

本地(不使用 Docker)

python -m venv .venv && source .venv/bin/activate
pip install -e .
python -m discord_mcp   # o: discord-mcp

默认监听 http://0.0.0.0:8000/mcp

使用 Docker

docker compose up --build

或手动:

docker build -t discord-mcp .
docker run --env-file .env -p 8000:8000 discord-mcp

部署(Render / Railway / Fly.io / 任何 VPS)

该镜像是无状态持久化的通用 HTTP 容器(机器人状态保存在内存和 Discord 中),因此可部署在任何支持 Docker 的平台上:

  • 在提供商面板中配置第 2 步的环境变量。

  • 通过 HTTPS 暴露端口 8000(或你在 PORT 中定义的端口)——Claude 要求 MCP 服务器可通过 https:// 访问。

  • 部署后,连接器的 URL 将是 https://<你的域名>/mcp

为在生产环境中加强 DNS rebinding 保护,请设置 ALLOWED_HOSTS(服务器的公网主机名)和 ALLOWED_ORIGINS(例如 https://claude.ai)。

4. 在 claude.ai 中作为自定义连接器连接

  1. 进入 https://claude.ai/ask-your-org/setup(或 设置 → 连接器),选择 Add custom connector / Custom

  2. NameDiscord(或任意你喜欢的名称)。

  3. URLhttps://<你的域名>/mcp

  4. Request headers / 高级设置 中添加:

    • Header: Authorization

    • Value: Bearer <与 MCP_AUTH_TOKEN 相同的值>

  5. 保存并测试,例如向 Claude 提出 "列出可用的 Discord 服务器" ——它应该调用 list_guilds

如果您不想使用认证(仅用于快速测试,切勿用于生产),请将 MCP_AUTH_TOKEN 留空并省略该 header。

开发

pip install -e ".[dev]"
pytest

测试覆盖配置、认证中间件以及不需要真实 Discord 连接的 discord.py 逻辑(不针对真实 Discord API 进行集成测试)。

架构说明

  • discord.py 机器人作为后台任务运行在与 ASGI 服务器(Starlette/uvicorn)相同的事件循环中;它随应用的生命周期(src/discord_mcp/server.py)一起启动和关闭。

  • MCP 服务器使用 Streamable HTTP 传输(来自官方 mcp SDK 的 mcp.server.MCPServer),这是 Claude 自定义连接器支持的远程传输方式。

  • 认证是静态 bearer token,由自定义 ASGI 中间件(auth_middleware.py)验证,专为自定义连接器的"Request headers"机制设计——不实现完整的 OAuth 流程。

F
license - not found
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    -
    quality
    D
    maintenance
    A Dockerized MCP server that enables Discord integration, offering tools for role management, messaging, moderation, and server administration via natural language.
    1
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    An MCP server that enables LLMs to control Discord servers via a bot token, providing comprehensive management tools for messages, members, roles, channels, permissions, and more.
    67
    124
    MIT
  • F
    license
    C
    quality
    C
    maintenance
    An MCP server that exposes Discord bot actions as tools for LLM clients.
    4
    29
    1

View all related MCP servers

Related MCP Connectors

  • An MCP server that integrates with Discord to provide AI-powered features.

  • Markdown-first MCP server for Notion API with 8 composite tools and 39 actions.

  • MCP server for AI dialogue using various LLM models via AceDataCloud

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fboiero/DiscordMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server