discord-dm-mcp

discord-dm-mcp

A tiny MCP server that lets Claude send Discord direct messages through a bot with nothing to host.

Category
访问服务器

README

discord-dm-mcp

A tiny MCP server that lets Claude send Discord direct messages through a bot — with nothing to host.

Sending a DM is just two stateless HTTPS POSTs to Discord's REST API, so there is no gateway/websocket connection to keep alive and no server to run. This package is a stdio MCP server: it runs as a subprocess of whatever launches it — your local Claude client, or a Claude cloud routine via a committed .mcp.json. Each user brings their own Discord bot token; the package itself holds no secrets.

It exposes a single tool, send_discord_dm.


How "no hosting" works

Where you use it Where the server runs You host a machine?
Local Claude Code / Desktop / Cursor your laptop (a subprocess) No
Claude cloud routine (via .mcp.json) Anthropic's ephemeral sandbox No

The only path that would require hosting is a remote ("Connector chip") MCP server, because a remote MCP must be reachable at a URL. This package avoids that by using stdio. (See the trade-off.)


Prerequisites (one-time Discord setup)

  1. Create a bot. https://discord.com/developers/applications → New Application → BotReset Token → copy the token. This is your DISCORD_BOT_TOKEN.
    • You do not need any privileged intents (Message Content, etc.) — those gate the gateway, not REST sends. This bot never reads messages.
  2. Invite the bot to your server with the bot scope and zero permissions (DMs aren't governed by a permission bit):
    https://discord.com/oauth2/authorize?client_id=YOUR_APP_ID&scope=bot&permissions=0
    
  3. The bot must share that server with every recipient. Discord only delivers a DM if the bot and the user have a mutual guild. Otherwise the send fails with error 50007 ("Cannot send messages to this user"). The recipient must also not have DMs disabled / the bot blocked.
  4. Get recipient user IDs. In Discord: Settings → Advanced → Developer Mode on, then right-click a user → Copy User ID. (Or build a consented GitHub→Discord mapping.)

Install — local Claude clients

No repo, no GitHub needed — just npm:

claude mcp add discord-dm \
  --env DISCORD_BOT_TOKEN="your-bot-token" \
  -- npx -y discord-dm-mcp

For Claude Desktop / Cursor, add the equivalent to the client's MCP config:

{
  "mcpServers": {
    "discord-dm": {
      "command": "npx",
      "args": ["-y", "discord-dm-mcp"],
      "env": { "DISCORD_BOT_TOKEN": "your-bot-token" }
    }
  }
}

Install — Claude cloud routine

A cloud routine can't use a local stdio server you added with claude mcp add (that lives on your machine). Instead the routine clones a repo and reads .mcp.json from it. So:

  1. Point the routine at a repo that contains a .mcp.json (the one at the root of this repo works as-is — it npx-installs the published package):

    {
      "mcpServers": {
        "discord-dm": {
          "command": "npx",
          "args": ["-y", "discord-dm-mcp"],
          "env": { "DISCORD_BOT_TOKEN": "${DISCORD_BOT_TOKEN}" }
        }
      }
    }
    

    The repo can be a near-empty stub — its only job is to carry this file. The ${DISCORD_BOT_TOKEN} is expanded from the routine's environment variable.

  2. Set the env var. In the routine's environment ("Default" or a custom one) add an Environment variable DISCORD_BOT_TOKEN=....

    ⚠️ Claude routines have no dedicated secrets store yet — env vars are visible to anyone who can edit the environment and may appear in transcripts. Treat this token as low-confidentiality and scope the bot to least privilege (it needs no guild permissions). Rotate it if a transcript is shared.

  3. Allow Discord egress. The Default environment's "Trusted" network access blocks discord.com (requests fail with 403 host_not_allowed). Edit the environment's Network access to Full, or Custom with discord.com added to the allowlist. (Custom-allowlist propagation has had bugs; if Discord still 403s, use Full.)

  4. Reference the tool from the routine Instructions, e.g. "If you're unsure whether to merge, call send_discord_dm to ask the PR author."

Running from a checkout instead of npm (e.g. before publishing): copy examples/.mcp.local-repo.json to the repo root as .mcp.json and set the environment Setup script to npm ci && npm run build.


Tool: send_discord_dm

Field Type Notes
discordUserId string Recipient's numeric Discord ID. One of this or githubLogin is required.
githubLogin string Resolved to a Discord ID via DISCORD_USER_MAP.
content string Plain message text, sent as-is.
escalation object Structured decision request (formatted into the body). Fields below.
escalation.prUrl string Link to the PR / item.
escalation.uncertainty string What the agent is unsure about.
escalation.evidence string Relevant evidence / context.
escalation.options string[] Rendered as A) … B) … plus a Custom) option.
escalation.recommendation string The agent's recommended option.
dryRun boolean Resolve + format but never call Discord.

Provide content, escalation, or both. Mentions are always disabled (allowed_mentions: { parse: [] }), so messages never accidentally ping @everyone, roles, or users.

Errors are returned as tool errors (isError: true), not thrown: unknown recipient, missing token, the no-mutual-guild 50007/50278 case (not retried), and other Discord API failures. Rate-limit 429s are retried automatically honoring Retry-After.


Configuration (environment variables)

Var Required Purpose
DISCORD_BOT_TOKEN to send Bot token. Not needed for dry runs.
DISCORD_DRY_RUN no 1/true/yes forces dry-run globally.
DISCORD_USER_MAP no Inline JSON or path to a {githubLogin: discordUserId} file.
DISCORD_API_BASE no Override https://discord.com/api/v10.

Mapping GitHub logins to Discord IDs

Set DISCORD_USER_MAP to inline JSON ({"octocat":"123..."}) or a file path (see examples/mapping.example.json). Keys match the GitHub login case-insensitively. For a consented mapping, have users link their own GitHub via Discord OAuth2 (identify + connections scopes) and only DM logins present in the map.


Develop / verify

npm install
npm run build      # tsc -> dist/
npm test           # unit tests (pure functions)
npm run smoke      # builds, starts the server over stdio, calls the tool in dry-run

npm run smoke proves the full MCP round-trip with no token and no network.


Why stdio and not a remote connector?

A custom connector (the chip in Claude's "Connectors" UI) is a remote MCP server: Claude connects out to a URL, so it must be hosted (even serverless = a deployment). A stdio server runs as a child process of the client, so it needs no host. The trade:

  • stdio (this package): no hosting; works locally and in cloud routines via .mcp.json. Not shown as a Connector chip.
  • remote connector: shown as a chip and reusable across clients, but you must host (serverless like Cloudflare Workers is the lightest option).

Responsible use

Discord's Developer Policy requires consent before initiating processes on a user's behalf and prohibits unsolicited / bulk DMs. Use this for opted-in, transactional, one-at-a-time notifications (e.g. asking a PR author a question), never to broadcast. Using a user token / selfbot to DM is forbidden by Discord and can get the account terminated — this package uses a proper bot token only.

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选