Skip to content

Architecture

This section is the contributor + advanced operator reference for how discord-mcp is built. The other sections describe what the server does (Tools), how to use it (Recipes), and how to run it (Operations). This section is about how it’s organized under the hood.

discord-mcp is a layered TypeScript server. Tools live in a Sapphire-style piece registry; every call goes through a four-layer Koa-style middleware chain (telemetry → validate → preconditions → audit); REST traffic is wrapped in a Cockatiel resilience policy (bulkhead → circuit → retry → timeout); optional Gateway support adds five subscribable resource URIs backed by a debounced WebSocket client. Each of those layers gets its own deep-dive page below.

The shape comes from one constraint: MCP is an agent contract. Agents are higher-volume, lower-trust, and harder to debug than humans, so the server has to do more of the cross-cutting work itself — validation, auth, audit, observability, structured errors with recovery hints — rather than expect every tool to re-implement them. The pieces below are the answer to “what does the server need to do once, so each tool can be short.”

If you’re a contributor, start with Overview to get the layout, then jump to whichever subsystem you’re touching. The deep-dive pages each link to source files via GitHub permalinks so you can read implementation in a tab.

If you’re an operator trying to understand a production behavior, the fastest path is usually:

  1. Look up the env var or error code on the relevant Operations page.
  2. Follow that page’s “Related” links into the architecture deep-dive.
  3. Use the source-map table at the bottom of the architecture page to find the exact file responsible.

The architecture pages assume familiarity with Discord’s API model and basic TypeScript. We do not re-explain MCP itself — see modelcontextprotocol.io for that.

  • Get started — install and run the server.
  • Tools — auto-generated reference for all 192 tools.
  • Recipes — multi-tool workflows that exercise these subsystems.
  • Operations — production-running concerns: telemetry, resilience, audit, client matrix.