English | 中文
miloco-bot is a TypeScript-based middleware that acts as a Model Context Protocol (MCP) server for Xiaomi Miloco. It bridges Miloco with Telegram, enabling bi-directional communication and remote management capabilities.
- MCP Server Implementation: Implements the Model Context Protocol using Streamable HTTP for seamless integration with Miloco.
- Telegram Integration:
- Send Messages & Photos: Exposes MCP Tools allowing Miloco agents to send text messages and photos to Telegram.
- Broadcast Capability: Automatically broadcasts messages to all allowed users if no specific chat ID is provided.
- Smart Formatting: Parses
<reflect>tags in messages to render them as collapsible blockquotes (using Telegram's HTML format), keeping the chat clean.
- Rule Management:
- View Rules: List all Miloco trigger rules via Telegram command or MCP tool.
- Control Rules: Enable or disable specific rules remotely.
- Secure:
- Access Control: Restricts access to a whitelist of Telegram User IDs (
TELEGRAM_ALLOWED_USER_IDS). Unauthorized messages are ignored. - Token Authentication: Supports Token-based authentication for the MCP server.
- Access Control: Restricts access to a whitelist of Telegram User IDs (
- Single Executable: Builds into a standalone Linux binary (using Node.js SEA) for easy deployment without external dependencies.
- A Telegram Bot Token (obtained from @BotFather)
- Miloco instance running and accessible.
We provide a single-command installation script that downloads the latest binary release and sets up the systemd service.
Run the following command as root:
wget -O - https://raw.githubusercontent.com/AkarinServer/miloco-bot/main/scripts/install.sh | sudo bashWhat this script does:
- Downloads the latest
miloco-bot-linuxbinary from GitHub Releases. - Installs it to
/opt/miloco-bot/. - Sets up a systemd service named
miloco-bot. - Creates a
.envconfiguration file if one doesn't exist.
After installation, you must configure the bot:
- Edit the configuration file:
sudo nano /opt/miloco-bot/.env
- Fill in your details (Telegram Token, User IDs, Miloco URL, etc.):
# Telegram Configuration TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz TELEGRAM_ALLOWED_USER_IDS=123456789,987654321 # Comma-separated list of allowed user IDs # Miloco Configuration MILOCO_WS_URL=wss://localhost:8000/api/chat/ws/query MILOCO_ADMIN_USERNAME=admin MILOCO_PASSWORD=your_miloco_password
- Start the service:
sudo systemctl start miloco-bot
sudo systemctl status miloco-bot
sudo systemctl restart miloco-bot
sudo journalctl -u miloco-bot -f # View logs- Open your Miloco dashboard.
- Navigate to MCP Services -> Add Service.
- Select Streamable HTTP.
- Fill in the details:
- URL:
http://<your-server-ip>:3000/mcp - Request Header (Token):
Authorization: Bearer <your-secret-token>(ifMCP_API_KEYis set).
- URL:
- Click Add.
/start: Check if the bot is running and you are authorized./help: Show available commands./ping: Check connection to Miloco./rules: View and manage Miloco trigger rules (Interactive UI)./status: Show system status.
The following tools are exposed to Miloco:
-
send_telegram_message:- Description: Sends a text message.
- Inputs:
message(string),chat_id(optional). - Behavior: If
chat_idis omitted, broadcasts to allTELEGRAM_ALLOWED_USER_IDS.
-
send_telegram_photo:- Description: Sends a photo.
- Inputs:
photo_path(string),caption(optional),chat_id(optional). - Behavior: Sends a local file. Broadcasts if
chat_idis omitted.
-
list_rules:- Description: Lists all configured rules in Miloco.
- Inputs:
enabled_only(boolean, default false).
-
toggle_rule:- Description: Enables or disables a specific rule.
- Inputs:
rule_id(string),enabled(boolean).
For contributors who want to build from source:
- Clone and install dependencies:
git clone https://github.com/AkarinServer/miloco-bot.git cd miloco-bot npm install - Run in dev mode:
npm run dev
- Build binary:
npm run build:linux
MIT