Metadata-Version: 2.5
Name: cord-mcp
Version: 0.2.0
Summary: High-performance Discord MCP server for bots and user tokens with Gateway state cache, SQLite FTS5 message search, and a streamlined Discord API v10 engine.
Project-URL: Homepage, https://github.com/rayakame/cord-mcp
Project-URL: Repository, https://github.com/rayakame/cord-mcp
Project-URL: Issues, https://github.com/rayakame/cord-mcp/issues
Project-URL: Changelog, https://github.com/rayakame/cord-mcp/blob/main/CHANGELOG.md
Project-URL: CI, https://github.com/rayakame/cord-mcp/actions
Author-email: Rayakame <github.android206@passmail.net>
License-Expression: MIT
License-File: LICENSE
Keywords: bot,discord,fts5,gateway,hikari,llm,mcp,model-context-protocol,selfbot,user-token
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.15
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Communications :: Chat
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: <3.16,>=3.15
Requires-Dist: aiohttp~=3.14
Requires-Dist: aiosqlite~=0.22
Requires-Dist: colorlog~=6.10
Requires-Dist: msgspec<1.0,>=0.23
Requires-Dist: multidict~=7.2
Provides-Extra: speedups
Requires-Dist: aiohttp[speedups]; extra == 'speedups'
Description-Content-Type: text/markdown

<div align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/rayakame/cord-mcp/main/.github/assets/banner-dark.svg">
    <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/rayakame/cord-mcp/main/.github/assets/banner-light.svg">
    <img alt="cord-mcp" src="https://raw.githubusercontent.com/rayakame/cord-mcp/main/.github/assets/banner-dark.svg" width="100%">
  </picture>

  <br>

  <p>
    <a href="https://pypi.org/project/cord-mcp/"><img src="https://img.shields.io/pypi/v/cord-mcp?style=flat-square&color=5865F2&label=PyPI" alt="PyPI"></a>
    <a href="https://pypi.org/project/cord-mcp/"><img src="https://img.shields.io/pypi/pyversions/cord-mcp?style=flat-square&color=3776AB&label=Python" alt="Python 3.15"></a>
    <a href="https://github.com/users/rayakame/packages/container/package/cord-mcp"><img src="https://img.shields.io/badge/GHCR-latest-0d9488?style=flat-square&logo=docker&logoColor=white" alt="GHCR"></a>
    <a href="https://github.com/rayakame/cord-mcp/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/rayakame/cord-mcp/ci.yml?branch=main&style=flat-square&label=CI" alt="CI"></a>
    <a href="https://github.com/microsoft/pyright"><img src="https://img.shields.io/badge/pyright-strict-5865F2?style=flat-square" alt="pyright strict"></a>
    <a href="https://github.com/astral-sh/ty"><img src="https://img.shields.io/badge/ty-checked-2dd4bf?style=flat-square" alt="ty checked"></a>
    <a href="https://github.com/rayakame/cord-mcp/blob/main/LICENSE"><img src="https://img.shields.io/pypi/l/cord-mcp?style=flat-square&color=475569&label=License" alt="License: MIT"></a>
  </p>

  <p>
    <a href="#quick-start"><strong>Quick Start</strong></a> ·
    <a href="#discord-bot-setup"><strong>Bot Setup</strong></a> ·
    <a href="#user-and-oauth2-tokens"><strong>User Tokens</strong></a> ·
    <a href="#good-to-know"><strong>Good to Know</strong></a> ·
    <a href="#capabilities"><strong>Capabilities</strong></a> ·
    <a href="#configuration"><strong>Configuration</strong></a>
  </p>
</div>

<br>

<table>
  <tr>
    <td width="50%" valign="top">
      <strong>Full Discord API v10 Surface</strong><br>
      <sub><b>77 tools</b>, <b>6 resources</b>, and <b>5 prompts</b> covering channels, threads, forums, Components V2, polls, roles, webhooks, events, audit logs, and AutoMod.</sub>
    </td>
    <td width="50%" valign="top">
      <strong>Millisecond Message Search</strong><br>
      <sub>Discord's Bot API has no guild search endpoint. <code>cord-mcp</code> indexes live and historical messages locally with SQLite FTS5.</sub>
    </td>
  </tr>
  <tr>
    <td width="50%" valign="top">
      <strong>Bot, User, or OAuth2 Token</strong><br>
      <sub>Run as a bot, as your own account, or with an OAuth2 access token. The token type is detected automatically.</sub>
    </td>
    <td width="50%" valign="top">
      <strong>Safe by Default</strong><br>
      <sub>Blocks <code>@everyone</code>, <code>@here</code>, and role pings unless asked, and supports <code>--read-only</code> and server allowlists.</sub>
    </td>
  </tr>
</table>

---

## Quick Start

### Option 1 — Local `stdio` via `uvx` *(Python 3.15+)*

For a single desktop client (Claude Desktop, Cursor, VS Code):

```json
{
  "mcpServers": {
    "cord-mcp": {
      "command": "uvx",
      "args": ["cord-mcp", "serve"],
      "env": {
        "DISCORD_TOKEN": "YOUR_DISCORD_TOKEN"
      }
    }
  }
}
```

> [!TIP]
> For a read-only setup limited to one server, add `"--read-only"` to `args` and `"CORD_MCP_ALLOWED_GUILDS": "123456789012345678"` to `env`.

### Option 2 — Always-On Docker *(recommended)*

One Gateway session and search index that several MCP clients share:

```sh
docker run -d --name cord-mcp --restart unless-stopped \
  -p 127.0.0.1:8000:8000 \
  -v cord-mcp-data:/data \
  -e DISCORD_TOKEN="YOUR_DISCORD_TOKEN" \
  -e CORD_MCP_HTTP_BEARER_TOKEN="YOUR_OPTIONAL_SECRET" \
  ghcr.io/rayakame/cord-mcp:latest
```

Or copy [`.env.example`](.env.example) to `.env` and run `docker compose up -d`. Then connect your client:

```json
{
  "mcpServers": {
    "cord-mcp": {
      "url": "http://127.0.0.1:8000/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_OPTIONAL_SECRET"
      }
    }
  }
}
```

---

## Discord Bot Setup

Enable these for your bot in the [Discord Developer Portal](https://discord.com/developers/applications):

| Setting | Requirement | Purpose |
| :--- | :--- | :--- |
| **Message Content Intent** | **Required** | Read and index message content |
| **Server Members Intent** | Recommended | Member lists and role resolution |
| **Presence Intent** | Optional | `list_presences` (the server works without it) |
| **Bot Permissions** | Per workflow | `VIEW_CHANNEL` + `READ_MESSAGE_HISTORY` to read; more for writing and moderation |

---

## User and OAuth2 Tokens

> [!WARNING]
> Automating a user account breaks Discord's Terms of Service and can get the account flagged or banned. Use a user token at your own risk.

1. Open Discord in an incognito window, log in, and copy `token` from DevTools → Application → Local Storage → `https://discord.com`. Close the window without logging out; logging out revokes the token.
2. Start the server with it:

```sh
DISCORD_TOKEN="YOUR_USER_TOKEN" cord-mcp serve --token-type user
```

- The server acts with your account's permissions and behaves like the Discord web client, with conservative request pacing.
- Run one session per token from a stable IP, and prefer `--read-only` if you only need search.
- DMs work by channel ID but are not listed. Bot-only features such as slash commands are not available.
- OAuth2 access tokens work with `--token-type bearer` (or a `Bearer ` prefix), in REST mode only.

---

## Good to Know

- **Token type:** the default `--token-type auto` detects bot, user, and bearer tokens. A token Discord rejects stops the server at startup. Set the type explicitly to skip detection.
- **Read-only and allowlist:** `--read-only` blocks every write, admin, and moderation tool. `CORD_MCP_ALLOWED_GUILDS` limits the server to the listed servers.
- **Mentions:** `@everyone`, `@here`, and role pings are blocked unless a tool call allows them.
- **Search:** `search_messages` searches the local index. Gateway mode fills it with new messages; use `backfill_channel_messages` or `backfill_guild_messages` for older ones.
- **One server per token:** processes sharing a token share Discord's rate limits. Run one always-on server and connect all clients to it.
- **IDs:** Discord IDs are passed and returned as strings.

---

## Capabilities

| Domain | Tools | What You Can Do |
| :--- | :---: | :--- |
| **Discovery & Context** | `15` | Server overview, channel and thread tree, permissions, members, roles, presences, voice, expressions |
| **Reading & Search** | `10` | History, reply context, pins, reactions, poll results, full-text search, backfill |
| **Messaging & Components V2** | `13` | Send, edit, reply, forward, Components V2, embeds, files, polls, delete, pins, reactions |
| **Channels, Forums & Threads** | `12` | Channel management, permission overwrites, threads, forum posts |
| **Guild Admin, Roles & Events** | `16` | Server settings, roles, emojis, stickers, soundboard, webhooks, invites, events, onboarding |
| **Moderation & AutoMod** | `11` | Kick, ban, timeout, voice moderation, prune, audit logs, AutoMod rules |

<details>
<summary><strong>All 77 tools, 6 resources & 5 prompts</strong></summary>

<br>

- **Discovery (15):** `get_bot_status`, `list_guilds`, `get_guild_overview`, `get_channel_tree`, `get_channel_details`, `get_effective_permissions`, `list_roles`, `list_members`, `get_member_info`, `get_user_info`, `list_presences`, `list_voice_states`, `list_emojis_and_stickers`, `list_soundboard_sounds`, `get_guild_widget`
- **Reading & Search (10):** `get_message`, `read_channel_messages`, `get_message_context`, `list_pinned_messages`, `list_reaction_users`, `get_poll_results`, `search_messages`, `backfill_channel_messages`, `backfill_guild_messages`, `get_message_store_stats`
- **Messaging (13):** `send_message`, `forward_message`, `edit_message`, `delete_message`, `bulk_delete_messages`, `pin_message`, `unpin_message`, `add_reaction`, `remove_reaction`, `clear_reactions`, `end_poll`, `trigger_typing`, `crosspost_message`
- **Channels & Threads (12):** `create_channel`, `edit_channel`, `delete_channel`, `reorder_channels`, `set_channel_permission_overwrite`, `delete_channel_permission_overwrite`, `list_threads`, `create_thread`, `edit_thread`, `create_forum_post`, `list_thread_members`, `manage_thread_membership`
- **Guild Admin (16):** `edit_guild`, `create_role`, `edit_role`, `delete_role`, `update_member_roles`, `manage_custom_emoji`, `manage_guild_sticker`, `manage_soundboard`, `list_webhooks`, `manage_webhook`, `execute_webhook`, `list_invites`, `manage_invite`, `list_scheduled_events`, `manage_scheduled_event`, `manage_stage_and_onboarding`
- **Moderation (11):** `kick_member`, `ban_member`, `bulk_ban_members`, `unban_user`, `list_bans`, `timeout_member`, `edit_member_moderation`, `prune_inactive_members`, `read_audit_logs`, `list_automod_rules`, `manage_automod_rule`
- **Resources (6):** `discord://status`, `discord://guilds`, `discord://guilds/{guild_id}/overview`, `discord://guilds/{guild_id}/channels`, `discord://channels/{channel_id}/recent`, `discord://channels/{channel_id}/pins`
- **Prompts (5):** `summarize_channel_activity`, `investigate_moderation_incident`, `audit_server_permissions`, `search_server_knowledge`, `draft_rich_announcement`

</details>

<details>
<summary><strong>Components V2 example</strong></summary>

<br>

`send_message`, `edit_message`, `create_forum_post`, and `execute_webhook` accept Components V2 layouts directly:

```json
{
  "channel_id": "123456789012345678",
  "components": [
    {
      "type": "container",
      "accent_color": "#5865F2",
      "components": [
        {
          "type": "section",
          "components": [
            { "type": "text_display", "content": "## v0.1.0 Released\nAll systems operational." }
          ],
          "accessory": {
            "type": "link_button",
            "label": "Changelog",
            "url": "https://github.com/rayakame/cord-mcp/blob/main/CHANGELOG.md"
          }
        },
        { "type": "separator", "divider": true, "spacing": "small" },
        { "type": "text_display", "content": "Gateway latency: **18ms** · FTS5 index: **ready**" }
      ]
    }
  ]
}
```

</details>

---

## Configuration

| Environment Variable | CLI Flag | Default | Description |
| :--- | :--- | :--- | :--- |
| `DISCORD_TOKEN` / `CORD_MCP_TOKEN` | `--token` | *(required)* | Bot, user, or OAuth2 token |
| `CORD_MCP_TOKEN_TYPE` | `--token-type` | `auto` | `auto`, `bot`, `user`, or `bearer` |
| `CORD_MCP_MODE` | `--mode` | `gateway` | `gateway` (live cache and indexing) or `rest` |
| `CORD_MCP_INTENTS` | `--intents` | `auto` | `auto`, `all`, `unprivileged`, or intent names (bots only) |
| `CORD_MCP_RATE_LIMIT_MODE` | `--rate-limit-mode` | `auto` | `auto` (paces user and bearer tokens), `normal`, or `safe` |
| `CORD_MCP_DB_PATH` | `--db-path` | `~/.local/share/cord-mcp/messages.db` | SQLite file or `:memory:` |
| `CORD_MCP_READ_ONLY` | `--read-only` | `false` | Block write, admin, and moderation tools |
| `CORD_MCP_ALLOWED_GUILDS` | `--allowed-guilds` | *(all)* | Comma-separated server IDs |
| `CORD_MCP_TRANSPORT` | `--transport` | `stdio` | `stdio`, `streamable-http`, or `sse` |
| `CORD_MCP_HOST` / `CORD_MCP_PORT` | `--host` / `--port` | `127.0.0.1` / `8000` | HTTP/SSE address (`GET /health` included) |
| `CORD_MCP_HTTP_BEARER_TOKEN` | `--http-bearer-token` | *(unset)* | Require `Authorization: Bearer <secret>` |
| `CORD_MCP_LOG_LEVEL` | `--log-level` | `WARNING` | `DEBUG`, `INFO`, `WARNING`, `ERROR`, or `CRITICAL` |

<details>
<summary><strong>Advanced settings</strong></summary>

<br>

| Environment Variable | Default | Description |
| :--- | :--- | :--- |
| `CORD_MCP_STARTUP_TIMEOUT` | `10.0` | Seconds to wait for the Gateway handshake (`0` = no limit) |
| `CORD_MCP_MAX_BACKFILL_PER_CALL` | `5000` | Max messages per backfill call |
| `CORD_MCP_AUTO_INDEX_GATEWAY` | `true` | Index live messages, edits, reactions, and deletes |
| `CORD_MCP_AUTO_INDEX_REST` | `true` | Index messages fetched or sent via REST |
| `CORD_MCP_ALLOW_USER_MENTIONS` | `true` | Allow user mentions in outgoing messages by default |
| `CORD_MCP_ALLOW_REPLIED_USER_MENTION` | `true` | Mention the replied-to user by default |
| `CORD_MCP_CLIENT_BUILD_NUMBER` | *(scraped)* | User tokens: override the Discord client build number |
| `CORD_MCP_CLIENT_BROWSER_VERSION` | *(scraped)* | User tokens: override the Chrome version |
| `CORD_MCP_CLIENT_PROPERTIES_OFFLINE` | `false` | Skip fingerprint scraping and token type detection |

</details>

### Commands

```sh
cord-mcp serve [options]                         # Start the MCP server (default)
cord-mcp tools [--json]                          # List all tools, resources, and prompts
cord-mcp stats [--db-path ...]                   # Show search index statistics
cord-mcp check-token [--token ...] [--token-type ...]  # Check a token and list its servers
```

---

<div align="center">
  <sub>
    <a href="CONTRIBUTING.md">Contributing</a> ·
    <a href="SECURITY.md">Security Policy</a> ·
    <a href="CHANGELOG.md">Changelog</a> ·
    Licensed under <a href="LICENSE">MIT</a> (incorporating derived components from <a href="https://github.com/hikari-py/hikari">hikari</a>)
  </sub>
</div>
