DI

Discord MCP Server for Guild Channel Messaging

Connect your Discord guild via an MCP server to let a bot read and write channel messages securely and manage messaging in real time.

Quick Install
npx -y @v-3/discordmcp

Overview

This MCP (Model Context Protocol) server connects a Discord guild to external clients via a secure, real-time interface so bots and other services can read from and write to Discord channels. Instead of granting every service a full Discord bot token or direct gateway access, the MCP server mediates messaging: it forwards messages, enforces simple access controls, and exposes an API (HTTP + WebSocket) that clients can use to subscribe to channel events and produce messages.

That architecture is useful when multiple tools, microservices, or AI systems need to interact with the same Discord guild without each maintaining a persistent Discord connection. The MCP server centralizes the Discord bot, reducing token sprawl, enabling auditable message flows, and providing low-latency event delivery to connected clients.

Features

  • Real-time message forwarding between Discord and connected MCP clients (via WebSockets)
  • REST endpoints for sending and managing messages programmatically
  • Lightweight authentication model using secrets or tokens for connected clients
  • Channel mapping and selective subscriptions (subscribe only to channels of interest)
  • Message create/edit/delete support and event propagation
  • Deployable as a Node app or containerized with Docker for production use
  • Simple configuration via environment variables or a config file

Installation / Configuration

Prereqs: Node.js (v16+) or Docker.

Clone the repository and install dependencies:

git clone https://github.com/v-3/discordmcp.git
cd discordmcp
npm install

Environment variables (recommended as a .env file):

# Discord bot token with permissions to read/write guild channels
DISCORD_TOKEN=your_discord_bot_token_here

# A secret used to sign or authenticate MCP client connections
MCP_SECRET=some_long_random_secret

# Port the MCP server listens on
PORT=8080

# Optional: restrict to a single guild
GUILD_ID=123456789012345678

Run locally:

npm start
# or with environment variables:
DISCORD_TOKEN=... MCP_SECRET=... PORT=8080 npm start

Docker:

# Example Dockerfile (if provided in repo)
FROM node:18-alpine
WORKDIR /app
COPY . .
RUN npm ci --production
ENV PORT=8080
CMD ["node", "server.js"]

docker-compose example:

version: "3.8"
services:
  discord-mcp:
    build: .
    environment:
      - DISCORD_TOKEN=${DISCORD_TOKEN}
      - MCP_SECRET=${MCP_SECRET}
      - PORT=8080
    ports:
      - "8080:8080"

Available Resources

  • Source code and issue tracker: https://github.com/v-3/discordmcp
  • Example configuration: .env (see above)
  • API surface: HTTP endpoints for message operations, WebSocket for events (see quick examples below)

Example API (quick reference)

The server typically exposes:

  • HTTP POST /api/messages — send a message to a channel
  • HTTP GET /api/channels — list channels available for the configured guild
  • WebSocket /ws — real-time events (message_create, message_update, message_delete)

Example: send a message via curl (replace token/auth as configured):

curl -X POST "http://localhost:8080/api/messages" \
  -H "Authorization: Bearer <client_token_or_signature>" \
  -H "Content-Type: application/json" \
  -d '{"channel_id":"123456789012345678","content":"Hello from MCP client!"}'

WebSocket example (Node.js) — subscribe and receive events:

import WebSocket from 'ws';

const ws = new WebSocket('ws://localhost:8080/ws', {
  headers: { Authorization: 'Bearer <client_token_or_signature>' }
});

ws.on('open', () => {
  // Example subscribe message; protocol varies by server implementation
  ws.send(JSON.stringify({ op: 'subscribe', channel_ids: ['123456789012345678'] }));
});

ws.on('message', (data) => {
  const event = JSON.parse(data.toString());
  console.log('MCP event:', event);
});

Use Cases

  • AI-assisted moderation: an AI service connects as an MCP client to read messages in moderated channels, suggest moderation actions, and post safe replies without needing the Discord token directly embedded in the AI service.
  • Multi-service orchestration: different microservices (analytics, logging, notification systems) subscribe to selected channels to react in real time without each keeping a persistent Discord gateway connection.
  • Testing and automation: CI tools send and read messages in a designated test channel through the MCP API, enabling integration tests that involve live chat without exposing the main bot token.
  • Temporary/ephemeral clients: short-lived processes (e.g., serverless functions) can authenticate to the MCP server, perform a task, and disconnect—avoiding the overhead of long-running Discord connections.

Troubleshooting & Tips

  • Ensure the Discord bot has required intents and permissions (read message history, send messages, view channels).
  • Use a secure, random MCP_SECRET and rotate regularly if exposed.
  • Limit client permissions by issuing scoped tokens or implementing per-client ACLs in the MCP server.
  • Monitor rate limits: the MCP server should centralize rate-limit handling to avoid hitting Discord API limits when many clients are active.

For full details, examples, and source, see the repository: https://github.com/v-3/discordmcp.