Skip to main content
Glama
Discord MCP Server

Discord MCP Server

by mofumofupop

mcp-server

特定の Discord サーバーのメンバーだけが使える、リモート MCP サーバーです。Cloudflare Workers で動きます。Discord の操作には @djsk/discord-mcp を使い、その前に Discord OAuth2 によるログインとツールの許可リストを置いています。

仕組み

MCP クライアントが接続すると、この Worker の同意画面が開きます。許可すると Discord でログインし、Worker はユーザーのトークンで GET /users/@me/guilds/{guild.id}/member を呼んで、DISCORD_GUILD_ID のサーバーに参加しているかを確認します。参加していないユーザーと、メンバーシップ審査 (ルールへの同意) を終えていないユーザーにはトークンを発行しません。Discord のトークンは確認が済んだらすぐ失効させ、保存しません。

/mcp へのリクエストのたびに、bot でもう一度参加を確認します。結果は KV に membershipCacheTtlSeconds 秒 (既定は 300 秒) 保持するので、サーバーを抜けたユーザーは遅くともその時間が過ぎると使えなくなります。

Discord への操作はすべて bot のトークンで行います。メッセージを送ると、送信者は bot になります。操作できるのは DISCORD_GUILD_ID のサーバーだけです。ツールの guild_id 引数は tools/list に出さず、呼び出しのたびに DISCORD_GUILD_ID を入れます。AI がサーバー ID を知らなくても使えます。ツールの呼び出しはユーザー ID とツール名を Workers Logs に記録します。

Related MCP server: Discord MCP Server

公開するツール

公開するツールは mcp.config.jsonc の allowedTools で決めます。ここにないツールは tools/list に出ず、呼び出しても拒否します。toolset に新しいツールが増えても、allowedTools に足すまでは公開されません。

初期状態で公開しているのは、default toolset のうちの次のツールです。

  • 読み取り: ユーザー、サーバー、チャンネル、ロール、メンバー、スレッド、ピン留め、メッセージ、リアクションの取得と検索

  • 書き込み: メッセージの送信と編集 (bot が送ったものだけ)、bot のリアクションの追加と削除、スレッドの作成と参加

ban、kick、timeout、ロールの付け外し、メッセージの削除、ピン留めの変更、DM の送信のように、ほかのユーザーに影響する操作は公開していません。ツールの一覧は discord-mcp-cli の docs/tools.md にあります。

WARNING

メンバーは、bot が見えるチャンネルをすべて読めます。運営用の非公開チャンネルなどを読ませたくない場合は、bot のロールからそのチャンネルの閲覧権限を外してください。同じように、bot に「@everyone、@here、全てのロールにメンション」の権限があると、メンバーが bot 経由で全員にメンションできます。不要なら外してください。

設定

設定は 2 か所に分かれています。

  • mcp.config.jsonc: リポジトリで管理する設定。有効にする toolset、公開するツール、参加確認のキャッシュ時間

  • Worker の secret: デプロイ先ごとの値と秘密の値

secret

内容

DISCORD_GUILD_ID

利用者が参加していなければならないサーバーの ID

DISCORD_CLIENT_ID

Discord アプリケーションの ID

DISCORD_CLIENT_SECRET

Discord アプリケーションの OAuth2 クライアントシークレット

DISCORD_BOT_TOKEN

同じアプリケーションの bot トークン

secret が足りないか形式が正しくない場合、Worker は最初のリクエストで不足している項目を並べたエラーを返します。

セットアップ

Discord アプリケーション

Discord Developer Portal でアプリケーションを開き、次を設定します。

  1. OAuth2 の Redirects に https://<Worker のホスト名>/callback を追加する

  2. bot を対象のサーバーに招待しておく。メンバーの参加確認には特権インテントは不要です。メッセージの本文を読むには Message Content Intent を有効にします

Cloudflare

  1. KV namespace を作り、wrangler.jsonc の OAUTH_KV の id に設定する

  2. Workers Builds でこのリポジトリを接続するか、pnpm run deploy でデプロイする

  3. ダッシュボードの Settings > Variables and Secrets か pnpm exec wrangler secret put <名前> で、上の 4 つの secret を設定する

MCP クライアントからの接続

エンドポイントは https://<Worker のホスト名>/mcp です。Claude Code なら次のように追加します。

claude mcp add --transport http discord https://<Worker のホスト名>/mcp

最初の接続でブラウザが開き、同意画面と Discord のログインに進みます。

開発

pnpm install
cp .dev.vars.example .dev.vars   # 値を埋める
pnpm run dev

pnpm run typecheck で型を、pnpm test でツールの許可判定のテストを実行します。wrangler.jsonc を変えたら pnpm run types で worker-configuration.d.ts を作り直してください。

ローカルで Discord のログインまで試すには、Discord アプリケーションの Redirects に http://localhost:8787/callback も追加します。

ライセンス

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables comprehensive interaction with Discord servers to manage guilds, channels, messages, and members through an agentic workflow. It supports RAG capabilities, rate-limited message operations, and includes a React-based dashboard for monitoring and configuration.
      2
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to interact with Discord through the REST API and real-time events, supporting message management, user info, channel operations, and more with security controls.
      18 npm
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI assistants to interact with Discord guilds, channels, messages, threads, members, roles, webhooks, and DMs through a focused set of tools.
      MIT
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables AI assistants to interact with Discord through a bot, supporting server and member inspection, channel and role management, message and reaction operations, forum management, and webhook configuration.
      2,790 npm
      MIT