Bale Bot

io.github.sepehr071v0.1.0更新於 Oct 3, 2026

Private, local Bale bot for agents: read, search and answer messages, ask and wait, files.

概覽

AI 產生的概覽

讓助理透過你自己的 Bale 機器人讀取、搜尋、回覆訊息並傳送檔案,還能向你提問並等待你點擊確認。

功能
以本機 stdio MCP 伺服器執行,透過你自己的機器人呼叫 Bale 官方 Bot API。讀取類工具會把待處理更新拉進本機 SQLite 歷史,並提供新訊息、聊天清單、單一聊天歷史、支援波斯語的搜尋、帶內嵌按鈕的等待回覆,以及檔案下載。傳送類工具可送出帶 Markdown 與按鈕的文字、傳送檔案,並編輯或刪除機器人自己的訊息。機器人工具用來檢查權杖、聊天中繼資料與 webhook 狀態。
適用情境
適合長時間執行的助理需要通知你、在執行有風險的步驟前徵求同意,或在你離開鍵盤時接收新指令,並以 Bale 作為通道。也適合讀取與搜尋別人傳給機器人的內容,以及儲存他們送來的檔案。
執行需求
需要 uv(或 pip)在本機執行 bale-mcp 套件,以及來自 @botfather 的 Bale 機器人權杖,放在 BALE_BOT_TOKEN 中。建議設定 BALE_ALLOWED_CHATS 限制可讀取與傳送的聊天。選用 BALE_MCP_DB 指定本機歷史檔案,BALE_MCP_PROXY 指定 HTTP 代理。需要連線至 Bale API 的網路;僅支援桌面端。
安裝前請注意
BALE_BOT_TOKEN 中的機器人權杖屬於憑證,不應放入共用設定。傳送、編輯與刪除工具會變更資料並標記為破壞性操作,應先確認收件對象與內容。訊息文字來自他人,可能帶有提示注入;BALE_ALLOWED_CHATS 白名單可限制能觸及助理的對象。歷史預設存在 BALE_MCP_DB 指定的本機檔案,除非設為 :memory:。Bale 沒有端對端加密,Bale 伺服器可見機器人流量。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Bale Bot,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

💬 bale-mcp

Talk to your AI agents on Bale, privately.
Let Claude, Cursor or Copilot read what people send your Bale bot, keep a searchable history,
reply, send files, and ask you a question and wait for your tap, all from your own machine.

[PyPI] [Python] [CI] [MCP Registry] [License: MIT]

[Install in Cursor] [Install in VS Code]

Quick start · What it can do · Privacy · Tools · FAQ · فارسی


Why

Agents now run for minutes or hours: deploys, data jobs, research. You want them to tell you when they are done, ask before they do something risky, and take new instructions while you are away from the keyboard. For many people in Iran that phone is running Bale (بله). With bale-mcp the agent does it through your own Bale bot:

You: Run the migration on staging, but ask me on Bale before you touch the users table.

Agent: calls bot_send_message(chat_id=…, text="Migration step 3 alters users (2.1M rows). Go?", buttons=[["Go", "Stop"]]) → bot_wait_for_reply(chat_id=…, after_message_id=3)

(you tap Go on your phone)

json
{"messages": [{"kind": "button", "text": "Go", "from": "Sepehr", "message_id": 3}], "timed_out": false}

Agent: Got your approval. Running step 3 now; I'll message you when it's done.

The tool calls are real; the reply shape is from a live test against tapi.bale.ai on 2026-10-03.

What it can do

  • 📥 Read what people send your bot, from every chat, with sender, kind and chat id
  • 🗂️ Keep a history: the Bot API forgets messages after 24 hours; bale-mcp keeps them in a local SQLite file
  • 🔎 Search that history, Persian-aware: Arabic and Persian ی/ک, Persian and Latin digits and ZWNJ all match
  • 🙋 Ask and wait: send a question with inline buttons, then block until you answer or tap
  • 📤 Send text (Markdown), photos, documents, video, audio and voice; edit and delete the bot's messages
  • 📎 Download files people send (receipts, voice notes, documents) to your computer
  • 🔒 Private by design: runs on your machine, talks only to Bale, no telemetry, optional chat allowlist

Quick start

You need uv and a Bale bot.

  1. Create a bot. In Bale open @botfather, tap «ساخت بازوی جدید» (new bot), pick a name and a username ending in bot, and copy the token.
  2. Add the server to your MCP client (below).
  3. Find your chat id. Send /start to your bot, then ask the agent: "Check my new Bale messages." The chat_id it shows is yours. Put it in BALE_ALLOWED_CHATS so the bot ignores everyone else.
Claude Code
bash
claude mcp add bale -e BALE_BOT_TOKEN=123456789:your-token -e BALE_ALLOWED_CHATS=your-chat-id -- uvx bale-mcp
Claude Desktop

Settings → Developer → Edit Config, then add:

json
{  "mcpServers": {    "bale": {      "command": "uvx",      "args": ["bale-mcp"],      "env": {        "BALE_BOT_TOKEN": "123456789:your-token",        "BALE_ALLOWED_CHATS": "your-chat-id"      }    }  }}
Cursor

Click Install in Cursor above and fill in the two values, or add the Claude Desktop block to ~/.cursor/mcp.json.

VS Code (Copilot agent mode)

Add to .vscode/mcp.json. VS Code asks for the token once and stores it securely:

json
{  "inputs": [    { "type": "promptString", "id": "bale-token", "description": "Bale bot token", "password": true }  ],  "servers": {    "bale": {      "type": "stdio",      "command": "uvx",      "args": ["bale-mcp"],      "env": { "BALE_BOT_TOKEN": "${input:bale-token}", "BALE_ALLOWED_CHATS": "your-chat-id" }    }  }}
Anything else

It's a standard stdio MCP server: run uvx bale-mcp, or pip install bale-mcp and run bale-mcp, with BALE_BOT_TOKEN in the environment.

Then just ask:

  • "When the test suite finishes, send me the summary on Bale."
  • "Any new messages on Bale? Summarize them and draft replies, but ask me before sending."
  • "Ask me on Bale whether to deploy, with Yes/No buttons, and wait for my answer."
  • "Find the invoice photo someone sent the bot last week and save it to my Downloads."
  • پیام‌های جدید بله را بخوان و خلاصه‌شان را بگو.

How it works

text
  AI agent  (Claude, Cursor, Copilot, ...)      │      │  MCP over stdio      ▼  bale-mcp  (runs on your machine)  ──▶  ~/.bale-mcp/messages.db   local history (SQLite)      │      │  HTTPS, official Bot API      ▼  tapi.bale.ai  ◀──▶  your Bale app

Each reading tool first pulls pending updates from Bale (getUpdates) into the local store, then answers from it. Sent messages are stored too, so a chat's history shows both sides.

Privacy and security

  • Local only. bale-mcp runs on your machine. The only host it talks to is tapi.bale.ai. There is no relay server, no telemetry and no analytics.
  • Your history stays on your disk. Messages are kept in ~/.bale-mcp/messages.db (the folder is user-only on macOS/Linux). Set BALE_MCP_DB=:memory: to keep nothing on disk, or delete the file at any time.
  • Allowlist. With BALE_ALLOWED_CHATS set, messages from any other chat are dropped before they are stored or shown to the agent, so a stranger who finds your bot cannot feed your agent instructions. The server also refuses to send to any other chat.
  • Prompt-injection aware. The server tells the agent that message text is data from other people, never instructions to follow.
  • Confirm before sending. Tools that change something (send, edit, delete) are annotated destructiveHint, and their descriptions tell the agent to confirm the recipient and content with you first.
  • The token never leaks. It never appears in tool output, errors or logs.
  • Know the limits. Bale has no end-to-end encryption: Bale's servers see what goes through your bot, as with any Bale chat. bale-mcp adds no other party.

Tools

Chat ids are numbers (they can exceed 32 bits), or @username for public channels and groups when sending.

📥 Read (6)
ToolWhat it does
bot_get_new_messagesMessages people sent the bot since the last check, from every chat, oldest first
bot_list_chatsChats the bot has talked in, with unread count and last message
bot_read_chatA chat's recent history in both directions
bot_search_messagesSearch the stored history; Persian-aware
bot_wait_for_replyWait until someone writes in a chat or taps a button (up to 10 minutes)
bot_download_fileSave a photo, document, voice note, ... to this computer (max 20 MB)
📤 Send (4)
ToolWhat it does
bot_send_messageSend text, optionally as a reply and with inline buttons
bot_send_fileSend a photo, document, video, audio or voice file by URL or local path (max 50 MB)
bot_edit_messageReplace the text of a message the bot sent
bot_delete_messageDelete a message
🔧 Bot (3)
ToolWhat it does
bot_get_meCheck the token: bot id, username, name
bot_get_chatA chat's type, title or name, username and description
bot_get_webhook_infoWhether a webhook is set, pending updates and the last error

Good to know

  • Someone must message the bot first. A user has to send /start before the bot can message them; in groups and channels the bot must be a member.
  • History starts when bale-mcp first reads. Bale keeps undelivered updates for 24 hours (the last 2000), so anything older than that, or read by another program, is gone.
  • One reader per bot. Webhooks block getUpdates, and two programs polling the same token steal each other's updates. bot_get_webhook_info shows a webhook. Several bale-mcp processes may share one BALE_MCP_DB.
  • Text is Markdown. Bale formats every message: *bold*, _italic_.
  • Button presses come back as messages of kind button whose text is the label (cut to 64 bytes).

FAQ

Can it read my personal chats?

No. It uses the official Bot API, so it only sees what people send to your bot, and messages in groups and channels the bot is a member of. It cannot log in as you.

Do I need an Iranian IP?

No: in testing tapi.bale.ai answered from a foreign (Turkish) exit. If every call fails with "Could not reach tapi.bale.ai", set BALE_MCP_PROXY to an HTTP proxy that can reach it. Normal system proxy variables are ignored on purpose.

The tools say "Bale rejected the bot token"

The token is wrong or was revoked. Copy it again from @botfather. (Bale answers a bad token with HTTP 403 or 404.)

The agent waited and timed out

bot_wait_for_reply returns timed_out: true when nobody answered in time; the agent can call it again. Some MCP clients cancel tool calls after about a minute; use a shorter timeout_seconds there.

Claude Desktop says uvx is not found

Use the full path to uvx (where uvx on Windows, which uvx on macOS/Linux) as command.

How do I debug what the agent sees?
bash
npx @modelcontextprotocol/inspector -e BALE_BOT_TOKEN=123456789:your-token uvx bale-mcp

Configuration

VariableDefaultMeaning
BALE_BOT_TOKENrequiredBot token from @botfather
BALE_ALLOWED_CHATSunset (all chats)Comma-separated chat ids or @usernames; all other chats are ignored and never messaged
BALE_MCP_DB~/.bale-mcp/messages.dbLocal history file; :memory: keeps nothing on disk
BALE_MCP_PROXYunsetHTTP proxy for every request, e.g. http://user:pass@host:port

فارسی

bale-mcp به دستیار هوش مصنوعی شما (Claude، Cursor، Copilot و ...) اجازه می‌دهد از طریق بازوی (ربات) بله خودتان پیام‌ها را بخواند، در آن‌ها جستجو کند، پاسخ و فایل بفرستد، و از شما سؤال بپرسد و منتظر جوابتان بماند.

  • روی سیستم خود شما اجرا می‌شود و جز سرور بله به هیچ جای دیگری داده نمی‌فرستد.
  • تاریخچه پیام‌ها فقط روی دیسک خودتان ذخیره می‌شود (BALE_MCP_DB=:memory: یعنی هیچ ذخیره‌ای).
  • با BALE_ALLOWED_CHATS فقط چت‌های شما خوانده می‌شوند و پیام غریبه‌ها اصلاً به دستیار نمی‌رسد.
  • جستجو فارسی را می‌فهمد: «ی/ي»، «ک/ك»، اعداد فارسی و نیم‌فاصله فرقی نمی‌کنند.
  • بله رمزنگاری سرتاسری ندارد؛ این ابزار طرف سومی اضافه نمی‌کند.

نصب در Claude Code: توکن را از @botfather بگیرید و:

bash
claude mcp add bale -e BALE_BOT_TOKEN=123456789:your-token -- uvx bale-mcp

بعد به بازوی خود /start بفرستید و بپرسید: «پیام‌های جدید بله را بخوان.»

Development

bash
git clone https://github.com/sepehr071/bale-mcp && cd bale-mcpuv syncuv run pytest                 # offline, against a mocked Bot APIuv run pytest -m live         # read-only calls with BALE_BOT_TOKENuv run pytest -m live_send    # sends, edits and deletes one message in BALE_TEST_CHAT_IDuv run ruff check .

Tools live in src/bale_mcp/bot.py (sending, bot info) and inbox.py (reading, waiting, downloads); store.py is the local SQLite history. Each tool is a typed async function with a docstring that tells the agent when to use it. Issues and PRs are welcome.

Releases: bump the version in pyproject.toml and server.json, then push a v* tag. GitHub Actions tests, publishes to PyPI and the MCP Registry, and creates the GitHub Release.

Disclaimer

Unofficial and not affiliated with or endorsed by Bale. It uses Bale's official, public Bot API. Follow Bale's terms, and don't use it to spam people.

License

MIT

來源:README.md,提交 59dc856

工具

0
工具後設資料尚未被收錄。

版本歷史

1
  1. v0.1.0最新Oct 3, 2026