im-relay-mcp
README.md
# im-relay-mcp
English | [δΈζ](README_zh.md)
An MCP server that lets coding agents (Claude Code and the like) reach a human
over instant messaging: report progress, send files, and ask a question and
block until the human replies. Telegram and Slack are supported; each project
picks where its messages go.
## Design principles
1. **Minimal features.** Only the few features that are needed and used often;
more features would make it harder to use, not easier.
2. **Minimal interruption.** An agent can handle most things on its own most of
the time; human intervention is kept to a minimum.
3. **The agent need not know how.** Which platform or channel a message goes
through is invisible to the agent. All it knows is that what it sends this
way reaches Your Majesty.
4. **One interface.** Different IMs may implement the same feature in different
ways underneath, but the interface is the same for all of them. This follows
from principle 3.
## Typical use
You have many repos (projects). Which IM and which channel a project's messages
go to rarely changes, but differs from project to project. Most of the time the
traffic is one-way, agent to user (reports, `report_to_majesty`); now and then
the agent needs the user to reply (waiting for the user's decision,
`petition_majesty`). Hence each project sets its destination in its own
`.mcp.json` (see [Using it in a project](#using-it-in-a-project)).
## What the agent sees
Server instructions:
> Human-in-the-loop bridge to a real person over an instant-messaging chat.
Tools:
- **`report_to_majesty`**: Report a message to Your Majesty (you will not receive a reply from Your Majesty)
- `message` (required): The message to report to Your Majesty (max 400 characters)
- Result: `Notification sent successfully. This is a one-way channel β you will NOT receive a reply from Your Majesty through this tool. If you need a response, use petition_majesty instead.`
- **`petition_majesty`**: Petition Your Majesty with a question and wait for the imperial reply (blocks you until Your Majesty replies)
- `question` (required): The question to petition Your Majesty with (max 400 characters)
- Result: the reply text, verbatim.
- **`send_file`**: Send a file to Your Majesty (max 50 MB)
- `filePath` (required): The path to the file to send
- `caption`: Optional caption shown under the file (max 100 characters)
- Result: `File sent successfully`
A call over a limit sends nothing and returns an error such as:
```
"message" is 450 characters, over the limit of 400
too many messages: 5 in the last minute, limit 5
```
## What the user sees
A report is an ordinary message.
A question starts with `#needs_reply`. Only a reply to that message answers
it: Telegram's **Reply**, or a reply in the message's **thread** on Slack.
Anyone in the chat may answer, so others can handle questions while the user
is away. Other messages are ignored. Once the agent has the user's reply, that
reply gets a π.
## Setup
```sh
git clone https://github.com/WhymustIhaveaname/im-relay-mcp.git
cd im-relay-mcp
npm install
npm run build
cp .env.example .env # then fill it in; keep it chmod 600
```
All bot credentials live in this one `.env`. Projects only say where to send.
### Telegram
Create a bot with [@BotFather](https://t.me/botfather) and put its token in
`TELEGRAM_TOKEN`. To find a chat id, message the bot and run `npm run ids`.
### Slack
Create an app at <https://api.slack.com/apps> β **Create an App** β **Paste a
manifest**, with:
```yaml
display_information:
name: IM Relay
features:
app_home:
messages_tab_enabled: true
messages_tab_read_only_enabled: false
bot_user:
display_name: IM Relay
always_online: true
oauth_config:
scopes:
bot:
- chat:write
- files:write
- reactions:write
- im:history
- im:read
- im:write
- channels:history
- groups:history
- users:read
settings:
event_subscriptions:
bot_events:
- message.im
- message.channels
- message.groups
socket_mode_enabled: true
```
Then:
1. **Install App** β install to the workspace; copy the Bot User OAuth Token
(`xoxb-β¦`) into `SLACK_BOT_TOKEN`.
2. **Basic Information** β **App-Level Tokens** β generate one with the
`connections:write` scope; copy it (`xapp-β¦`) into `SLACK_APP_TOKEN`.
3. Run `npm run ids` to list destinations: the bot's direct message with each member,
and every channel the bot was invited to (`/invite @IM Relay`).
Socket Mode needs no public URL.
## Using it in a project
In the project's `.mcp.json`:
```json
{
"mcpServers": {
"im-relay": {
"type": "stdio",
"command": "/path/to/im-relay-mcp/bin/im-relay",
"args": ["--to", "slack:D0123456789"]
}
}
}
```
`--to` is `telegram:<chat_id>` or `slack:<channel_id>`. Without it the project
uses `DEFAULT_TO` from `.env`.
## How it runs
Each agent session starts its own `bin/im-relay`, which forwards to one shared
daemon per install, starting it on first use. Only the daemon talks to the bots:
Telegram allows one poller per bot token, and Slack spreads events across all
open Socket Mode connections, so per-session connections would lose replies.
- Sessions reach the daemon through `run/daemon.sock`; `run/` is accessible to
its owner only.
- Log: `daemon.log` in the install directory.
- Editing `.env` stops the daemon; the next request starts it with the new
settings. Unanswered petitions are lost when it stops.
- `bin/im-relay stop` stops it by hand, e.g. after `npm run build`.
## Credits
Started from [qpd-v/mcp-communicator-telegram](https://github.com/qpd-v/mcp-communicator-telegram) (ISC).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues