rocketchat-mcp
README.md
# rocketchat-mcp
An [MCP](https://modelcontextprotocol.io) server that lets AI coding assistants **read, search and send Rocket.Chat messages and files** on your behalf.
- Uses the public Rocket.Chat REST API, so it works with the free **Community Edition** (no Enterprise subscription needed)
- Authenticates with a **Personal Access Token**, including tokens created with **Require Two Factor Authentication**
- Runs locally over **stdio** and works with **Claude Code**, **OpenCode** and any other MCP client
- Has a **read-only mode** and is designed for "ask before sending" permission setups
> Built against the Rocket.Chat 8.x REST API (developed with 8.9). Older versions that have the same endpoints should work too.
---
## Contents
- [Tools](#tools)
- [Requirements](#requirements)
- [Installation](#installation)
- [Creating a Personal Access Token](#creating-a-personal-access-token)
- [Configuration](#configuration)
- [Using with Claude Code](#using-with-claude-code)
- [Using with OpenCode](#using-with-opencode)
- [Example prompts](#example-prompts)
- [Two-factor authentication](#two-factor-authentication)
- [Search and rate limits](#search-and-rate-limits)
- [Security notes](#security-notes)
- [Troubleshooting](#troubleshooting)
- [Development](#development)
- [License](#license)
---
## Tools
| Tool | Description | Rocket.Chat endpoint(s) |
|---|---|---|
| `whoami` | Connection check: current user and server version | `me`, `/api/info` |
| `list_rooms` | Your rooms with unread counters; filter by type or name | `subscriptions.get` |
| `find` | Find users and rooms you have **not** joined yet | `spotlight` |
| `read_messages` | Room / direct-message history, paging via `latest`, `oldest`, `offset` | `channels.history`, `groups.history`, `im.history` |
| `read_thread` | Thread root message and its replies | `chat.getThreadMessages`, `chat.getMessage` |
| `get_message` | A single message by ID, with a permalink | `chat.getMessage` |
| `get_unread` | Unread overview, optionally with the unread messages. **Does not mark anything as read** | `subscriptions.get`, `*.history` |
| `search_messages` | Search in one room or across your rooms | `chat.search`, `method.call/messageSearch` |
| `send_message` | Send to a room, a direct message (`@user`) or a thread | `chat.sendMessage`, `im.create` |
| `send_file` | Upload a local file to a room, DM or thread, optionally with a message text and description | `rooms.media`, `rooms.mediaConfirm` |
| `download_file` | Download a message's attachments (or a single file link) to a local folder | file URLs on the server, `chat.getMessage` |
Rooms can be referenced as `#channel`, `@username`, a room ID, a room title, or a room link (`https://chat.example.com/channel/general`).
### Files
- `send_file` takes a local `filePath` plus `room` (or `threadId`), and optional `text`, `description` and `fileName`.
The server's own limits apply (*Administration → Settings → File Upload*: max size, allowed types).
- `download_file` takes a `messageId` (downloads all files of the message) or a `fileUrl` from the `read_messages` output.
Files are saved to `destinationDir`, or to `ROCKETCHAT_DOWNLOAD_DIR`, or to `~/Downloads/rocketchat-mcp` by default.
Existing files are kept, and new ones get a ` (1)` suffix unless `overwrite=true`.
The auth token is sent only to the configured Rocket.Chat server, never to other hosts.
Messages are returned in a compact, LLM-friendly format:
```
[2026-12-01 10:22:33] @jane (Jane Doe): Can someone review the release notes?
id=Xk2p9... replies=3
```
## Requirements
- Node.js **18.17** or newer
- A Rocket.Chat account that is allowed to create Personal Access Tokens
## Installation
```bash
git clone https://github.com/petr-iakovenko-01/rocketchat-mcp.git
cd rocketchat-mcp
npm install
npm run build
```
This produces `dist/index.js`. You will point your MCP client to the **absolute path** of that file.
## Creating a Personal Access Token
1. In Rocket.Chat open your avatar → **My Account → Personal Access Tokens**.
If the section is missing, ask an admin to grant you the `create-personal-access-tokens` permission.
2. Enter a token name and choose **Require Two Factor Authentication** (recommended, see [below](#two-factor-authentication)).
3. Click **Add** and confirm with your password or 2FA code.
4. Copy the **Token** and **Your user Id** from the dialog. The token is shown **only once**.
### Where do I find my User ID?
- **In the token dialog** from step 4. The "Your user Id" value is `ROCKETCHAT_USER_ID`.
If you closed the dialog, click **Regenerate** next to the token. The dialog appears again, but the old token stops working.
- **In the browser**, without regenerating the token. Open Rocket.Chat while logged in, open DevTools (F12) → **Console**, and run:
```js
localStorage.getItem('Meteor.userId')
```
If the browser blocks pasting into the console, it tells you what to type to allow it (usually `allow pasting`).
The User ID belongs to your user, not to the token, and never changes.
## Configuration
The server is configured with environment variables:
| Variable | Required | Description |
|---|---|---|
| `ROCKETCHAT_URL` | yes | Server URL, e.g. `https://chat.example.com` (a sub-path is allowed) |
| `ROCKETCHAT_USER_ID` | yes | Your User ID |
| `ROCKETCHAT_AUTH_TOKEN` | yes | Your Personal Access Token |
| `ROCKETCHAT_READ_ONLY` | no | `true` disables sending: `send_message` and `send_file` are not registered at all |
| `ROCKETCHAT_DOWNLOAD_DIR` | no | Default folder for `download_file` (default `~/Downloads/rocketchat-mcp`) |
| `ROCKETCHAT_TIMEOUT_MS` | no | Request timeout in milliseconds (default `30000`) |
| `NODE_EXTRA_CA_CERTS` | no | Path to a PEM CA bundle if your server uses a corporate or self-signed certificate |
Keep the token out of config files you might commit. Store it as a user environment variable instead:
**macOS / Linux** (`~/.bashrc`, `~/.zshrc`, ...):
```bash
export ROCKETCHAT_URL="https://chat.example.com"
export ROCKETCHAT_USER_ID="<your user id>"
export ROCKETCHAT_AUTH_TOKEN="<your token>"
```
**Windows** (PowerShell, persists for your user):
```powershell
[Environment]::SetEnvironmentVariable('ROCKETCHAT_URL', 'https://chat.example.com', 'User')
[Environment]::SetEnvironmentVariable('ROCKETCHAT_USER_ID', '<your user id>', 'User')
[Environment]::SetEnvironmentVariable('ROCKETCHAT_AUTH_TOKEN', '<your token>', 'User')
```
Restart your terminal or app afterwards so it picks up the variables.
> On Windows, use forward slashes in paths inside JSON configs, e.g. `C:/tools/rocketchat-mcp/dist/index.js`.
## Using with Claude Code
**Option A: CLI.** Values are stored in plain text in `~/.claude.json`.
```bash
claude mcp add rocketchat --scope user \
-e ROCKETCHAT_URL=https://chat.example.com \
-e ROCKETCHAT_USER_ID=<your user id> \
-e ROCKETCHAT_AUTH_TOKEN=<your token> \
-- node /absolute/path/to/rocketchat-mcp/dist/index.js
```
(In PowerShell, use a backtick `` ` `` instead of `\` for line continuation.)
**Option B: `.mcp.json`.** Secrets are read from environment variables, so the file is safe to commit.
```json
{
"mcpServers": {
"rocketchat": {
"command": "node",
"args": ["/absolute/path/to/rocketchat-mcp/dist/index.js"],
"env": {
"ROCKETCHAT_URL": "${ROCKETCHAT_URL}",
"ROCKETCHAT_USER_ID": "${ROCKETCHAT_USER_ID}",
"ROCKETCHAT_AUTH_TOKEN": "${ROCKETCHAT_AUTH_TOKEN}"
}
}
}
}
```
Verify with `claude mcp list`, or run `/mcp` inside a session.
**Recommended permissions** (`~/.claude/settings.json` or `.claude/settings.json`): reading runs without prompts, sending always asks.
```json
{
"permissions": {
"allow": [
"mcp__rocketchat__whoami",
"mcp__rocketchat__list_rooms",
"mcp__rocketchat__find",
"mcp__rocketchat__read_messages",
"mcp__rocketchat__read_thread",
"mcp__rocketchat__get_message",
"mcp__rocketchat__get_unread",
"mcp__rocketchat__search_messages",
"mcp__rocketchat__download_file"
],
"ask": ["mcp__rocketchat__send_message", "mcp__rocketchat__send_file"]
}
}
```
## Using with OpenCode
Add the server to `~/.config/opencode/opencode.json` (global) or `opencode.json` in a project (OpenCode V2 format):
```jsonc
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"servers": {
"rocketchat": {
"type": "local",
"command": ["node", "/absolute/path/to/rocketchat-mcp/dist/index.js"],
"environment": {
"ROCKETCHAT_URL": "{env:ROCKETCHAT_URL}",
"ROCKETCHAT_USER_ID": "{env:ROCKETCHAT_USER_ID}",
"ROCKETCHAT_AUTH_TOKEN": "{env:ROCKETCHAT_AUTH_TOKEN}"
}
}
}
},
"permissions": [
{ "action": "rocketchat_send_message", "resource": "*", "effect": "ask" },
{ "action": "rocketchat_send_file", "resource": "*", "effect": "ask" }
]
}
```
> **Important:** OpenCode allows all tools without prompting by default. Keep the `ask` rules for
> `rocketchat_send_message` and `rocketchat_send_file` so nothing is posted without your confirmation.
Verify with `opencode mcp list`.
## Example prompts
- "What did I miss in Rocket.Chat today?"
- "Read the last 50 messages in #backend and summarize the decisions."
- "Find messages from @jane about the release in the last week."
- "Open the thread about the deployment in #ops and tell me if anyone is blocked."
- "Draft a reply to Jane's last DM saying I'll review it tomorrow." Review the text, then confirm sending.
- "Download the log files from the last message in #ops and find the error."
- "Send `./reports/smoke.html` to the release thread in #qa with a short summary."
## Two-factor authentication
Personal Access Tokens can be created with **Ignore Two Factor Authentication** or **Require Two Factor Authentication**.
With *Require*, a leaked token cannot be used for sensitive operations without your 2FA code, so it is the safer choice.
How this server handles it:
- Reading, searching and sending messages normally **do not** require a 2FA code. The token behaves like a regular user session.
- If Rocket.Chat answers with `totp-required`, the tool returns `TWO-FACTOR CODE REQUIRED (method: totp|email)` to the assistant.
The assistant asks you for the code and repeats the call with `twoFactorCode`. The server sends it in the `x-2fa-code` / `x-2fa-method` headers.
- With the `email` method, Rocket.Chat emails you the code itself.
- Codes are never stored. TOTP secrets and passwords are **intentionally not supported**.
## Search and rate limits
**Search**
- With `room`, the search runs in a single room (`chat.search`). This is the most reliable option.
- Without `room`, the server first tries Rocket.Chat's server-wide search. It works only if an admin enabled
*Administration → Settings → Search → Default provider → Global Search*.
If that returns nothing, it searches your `maxRooms` (default 10) most recently active rooms one by one.
- Rocket.Chat search syntax is supported: `from:@user`, `mention:@user`, `has:url`, `has:star`, `is:pinned`,
`before:dd/mm/yyyy`, `after:dd/mm/yyyy`, `on:dd/mm/yyyy`, `order:asc`, `/regex/`.
**Rate limits**
Rocket.Chat limits API calls per endpoint by default (often 10 calls per minute). On HTTP 429 the server
waits once for the window to reset (up to 15 s) and retries. If the limit is still hit, it returns a clear error.
`get_unread` and search without `room` return partial results with a note instead of failing.
## Security notes
- The server acts **as you**. Anything sent through `send_message` or `send_file` is posted under your name and cannot be undone by the tool.
- `send_file` can upload any file the MCP process can read. Configure your client to **ask before `send_message` and `send_file`**
(see the permission examples above), or set `ROCKETCHAT_READ_ONLY=true`.
- Message content returned by the tools is untrusted input for the assistant. Keep confirmation prompts enabled for sending.
- Keep `ROCKETCHAT_AUTH_TOKEN` in environment variables, not in committed files. Revoke the token in *My Account → Personal Access Tokens* if it leaks.
- Use `https://`. The server warns on stderr if a non-local `http://` URL is configured.
## Troubleshooting
| Symptom | Fix |
|---|---|
| `Rocket.Chat MCP is not configured: missing environment variable(s)` | The variables are not visible to the MCP process. Set them in the client config or restart the client after setting them. |
| `Authentication failed (HTTP 401)` | Wrong User ID / token pair, or the token was revoked or regenerated. |
| `Cannot reach Rocket.Chat ... certificate is not trusted` | Set `NODE_EXTRA_CA_CERTS` to your corporate CA bundle (PEM). |
| `Non-JSON response` | `ROCKETCHAT_URL` does not point to the Rocket.Chat server (e.g. an SSO or proxy page). |
| `Rate limit reached` | Wait, pass `room` to searches, or lower `maxRooms`. Admins can tune *Settings → Rate Limiter*. |
| Global search finds nothing | Enable *Global Search* on the server, or pass `room`. |
Call `whoami` first. It confirms the URL, the user and the server version.
## Development
```bash
npm install
npm run build # compile TypeScript to dist/
npm run inspect # open the MCP Inspector (env variables must be set)
```
Project layout:
```
src/
├─ index.ts # entry point: config, stdio transport, server instructions
├─ config.ts # environment variable parsing
├─ client.ts # REST client: auth headers, 2FA, rate-limit retry, error mapping
├─ rooms.ts # room resolution (#channel / @user / ID / title / link), subscriptions cache
├─ format.ts # compact message formatting
├─ files.ts # attachment discovery, MIME types, streaming downloads to disk
└─ tools.ts # MCP tool definitions
```
Logs go to **stderr**. stdout is reserved for the MCP protocol.
## License
[MIT](LICENSE)
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues