bale-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bale_mcp-0.1.0/.github/workflows/ci.yml +21 -0
- bale_mcp-0.1.0/.github/workflows/publish.yml +51 -0
- bale_mcp-0.1.0/.gitignore +7 -0
- bale_mcp-0.1.0/LICENSE +21 -0
- bale_mcp-0.1.0/PKG-INFO +351 -0
- bale_mcp-0.1.0/README.md +326 -0
- bale_mcp-0.1.0/pyproject.toml +56 -0
- bale_mcp-0.1.0/server.json +50 -0
- bale_mcp-0.1.0/src/bale_mcp/__init__.py +5 -0
- bale_mcp-0.1.0/src/bale_mcp/bot.py +230 -0
- bale_mcp-0.1.0/src/bale_mcp/http.py +77 -0
- bale_mcp-0.1.0/src/bale_mcp/inbox.py +173 -0
- bale_mcp-0.1.0/src/bale_mcp/registry.py +17 -0
- bale_mcp-0.1.0/src/bale_mcp/server.py +48 -0
- bale_mcp-0.1.0/src/bale_mcp/store.py +177 -0
- bale_mcp-0.1.0/tests/conftest.py +70 -0
- bale_mcp-0.1.0/tests/test_bot.py +158 -0
- bale_mcp-0.1.0/tests/test_inbox.py +171 -0
- bale_mcp-0.1.0/tests/test_live.py +48 -0
- bale_mcp-0.1.0/uv.lock +1112 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python: ["3.10", "3.11", "3.12", "3.13"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v7
|
|
16
|
+
- uses: astral-sh/setup-uv@v10.2.0
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python }}
|
|
19
|
+
- run: uv sync --locked
|
|
20
|
+
- run: uv run ruff check .
|
|
21
|
+
- run: uv run pytest -q
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
# Tag a release (git tag v0.1.0 && git push --tags) after bumping the version in
|
|
4
|
+
# pyproject.toml and server.json.
|
|
5
|
+
on:
|
|
6
|
+
push:
|
|
7
|
+
tags: ["v*"]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
pypi:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment: pypi
|
|
13
|
+
permissions:
|
|
14
|
+
id-token: write # PyPI trusted publishing
|
|
15
|
+
contents: write # GitHub Release
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v7
|
|
18
|
+
- uses: astral-sh/setup-uv@v10.2.0
|
|
19
|
+
- name: Check versions match the tag
|
|
20
|
+
run: |
|
|
21
|
+
TAG=${GITHUB_REF_NAME#v}
|
|
22
|
+
grep -q "^version = \"$TAG\"" pyproject.toml
|
|
23
|
+
test "$(jq -r .version server.json)" = "$TAG"
|
|
24
|
+
test "$(jq -r '.packages[0].version' server.json)" = "$TAG"
|
|
25
|
+
- run: uv sync --locked && uv run pytest -q
|
|
26
|
+
- run: uv build
|
|
27
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
28
|
+
- run: gh release create "$GITHUB_REF_NAME" dist/* --generate-notes --title "$GITHUB_REF_NAME"
|
|
29
|
+
env:
|
|
30
|
+
GH_TOKEN: ${{ github.token }}
|
|
31
|
+
|
|
32
|
+
mcp-registry:
|
|
33
|
+
needs: pypi
|
|
34
|
+
runs-on: ubuntu-latest
|
|
35
|
+
permissions:
|
|
36
|
+
id-token: write # MCP Registry login via GitHub OIDC
|
|
37
|
+
contents: read
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v7
|
|
40
|
+
- name: Wait for PyPI to serve the new version
|
|
41
|
+
run: |
|
|
42
|
+
for i in $(seq 1 30); do
|
|
43
|
+
curl -sf "https://pypi.org/pypi/bale-mcp/${GITHUB_REF_NAME#v}/json" >/dev/null && exit 0
|
|
44
|
+
sleep 10
|
|
45
|
+
done
|
|
46
|
+
exit 1
|
|
47
|
+
- name: Install mcp-publisher
|
|
48
|
+
run: |
|
|
49
|
+
curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher
|
|
50
|
+
- run: ./mcp-publisher login github-oidc
|
|
51
|
+
- run: ./mcp-publisher publish
|
bale_mcp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sepehr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
bale_mcp-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: bale-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Private, local MCP server for Bale (bale.ai) bots: let AI agents read, search and answer messages, ask and wait for replies, and send or download files through the official Bot API.
|
|
5
|
+
Project-URL: Homepage, https://github.com/sepehr071/bale-mcp
|
|
6
|
+
Project-URL: Issues, https://github.com/sepehr071/bale-mcp/issues
|
|
7
|
+
Author-email: Sepehr <sepehr@nextofx.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: ai-agent,bale,bot,human-in-the-loop,iran,mcp,messenger,model-context-protocol,privacy
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Communications :: Chat
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: httpx>=0.27
|
|
23
|
+
Requires-Dist: mcp<3,>=2.2
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
<!-- mcp-name: io.github.sepehr071/bale-mcp -->
|
|
27
|
+
|
|
28
|
+
<div align="center">
|
|
29
|
+
|
|
30
|
+
# 💬 bale-mcp
|
|
31
|
+
|
|
32
|
+
**Talk to your AI agents on Bale, privately.**<br>
|
|
33
|
+
Let Claude, Cursor or Copilot read what people send your Bale bot, keep a searchable history,<br>
|
|
34
|
+
reply, send files, and ask you a question and wait for your tap, all from your own machine.
|
|
35
|
+
|
|
36
|
+
[](https://pypi.org/project/bale-mcp/)
|
|
37
|
+
[](https://pypi.org/project/bale-mcp/)
|
|
38
|
+
[](https://github.com/sepehr071/bale-mcp/actions/workflows/ci.yml)
|
|
39
|
+
[](https://registry.modelcontextprotocol.io/v0/servers?search=bale-mcp)
|
|
40
|
+
[](https://github.com/sepehr071/bale-mcp/blob/main/LICENSE)
|
|
41
|
+
|
|
42
|
+
[](https://cursor.com/en/install-mcp?name=bale&config=eyJjb21tYW5kIjoidXZ4IiwiYXJncyI6WyJiYWxlLW1jcCJdLCJlbnYiOnsiQkFMRV9CT1RfVE9LRU4iOiJ5b3VyLWJvdC10b2tlbiIsIkJBTEVfQUxMT1dFRF9DSEFUUyI6InlvdXItY2hhdC1pZCJ9fQ==)
|
|
43
|
+
[](https://vscode.dev/redirect/mcp/install?name=bale&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22bale-mcp%22%5D%2C%22env%22%3A%7B%22BALE_BOT_TOKEN%22%3A%22your-bot-token%22%2C%22BALE_ALLOWED_CHATS%22%3A%22your-chat-id%22%7D%7D)
|
|
44
|
+
|
|
45
|
+
[Quick start](#quick-start) · [What it can do](#what-it-can-do) · [Privacy](#privacy-and-security) · [Tools](#tools) · [FAQ](#faq) · [فارسی](#فارسی)
|
|
46
|
+
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Why
|
|
52
|
+
|
|
53
|
+
Agents now run for minutes or hours: deploys, data jobs, research. You want them to tell you when they are done,
|
|
54
|
+
ask before they do something risky, and take new instructions while you are away from the keyboard. For many
|
|
55
|
+
people in Iran that phone is running [Bale (بله)](https://bale.ai). With `bale-mcp` the agent does it through
|
|
56
|
+
your own Bale bot:
|
|
57
|
+
|
|
58
|
+
> **You:** Run the migration on staging, but ask me on Bale before you touch the users table.
|
|
59
|
+
>
|
|
60
|
+
> **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)`
|
|
61
|
+
>
|
|
62
|
+
> *(you tap **Go** on your phone)*
|
|
63
|
+
>
|
|
64
|
+
> ```json
|
|
65
|
+
> {"messages": [{"kind": "button", "text": "Go", "from": "Sepehr", "message_id": 3}], "timed_out": false}
|
|
66
|
+
> ```
|
|
67
|
+
>
|
|
68
|
+
> **Agent:** Got your approval. Running step 3 now; I'll message you when it's done.
|
|
69
|
+
|
|
70
|
+
<sub>The tool calls are real; the reply shape is from a live test against tapi.bale.ai on 2026-10-03.</sub>
|
|
71
|
+
|
|
72
|
+
## What it can do
|
|
73
|
+
|
|
74
|
+
- 📥 **Read** what people send your bot, from every chat, with sender, kind and chat id
|
|
75
|
+
- 🗂️ **Keep a history**: the Bot API forgets messages after 24 hours; `bale-mcp` keeps them in a local SQLite file
|
|
76
|
+
- 🔎 **Search** that history, Persian-aware: Arabic and Persian ی/ک, Persian and Latin digits and ZWNJ all match
|
|
77
|
+
- 🙋 **Ask and wait**: send a question with inline buttons, then block until you answer or tap
|
|
78
|
+
- 📤 **Send** text (Markdown), photos, documents, video, audio and voice; edit and delete the bot's messages
|
|
79
|
+
- 📎 **Download** files people send (receipts, voice notes, documents) to your computer
|
|
80
|
+
- 🔒 **Private by design**: runs on your machine, talks only to Bale, no telemetry, optional chat allowlist
|
|
81
|
+
|
|
82
|
+
## Quick start
|
|
83
|
+
|
|
84
|
+
You need [uv](https://docs.astral.sh/uv/getting-started/installation/) and a Bale bot.
|
|
85
|
+
|
|
86
|
+
1. **Create a bot.** In Bale open [@botfather](https://ble.ir/botfather), tap «ساخت بازوی جدید» (new bot), pick a
|
|
87
|
+
name and a username ending in `bot`, and copy the token.
|
|
88
|
+
2. **Add the server** to your MCP client (below).
|
|
89
|
+
3. **Find your chat id.** Send `/start` to your bot, then ask the agent: *"Check my new Bale messages."* The
|
|
90
|
+
`chat_id` it shows is yours. Put it in `BALE_ALLOWED_CHATS` so the bot ignores everyone else.
|
|
91
|
+
|
|
92
|
+
<details open>
|
|
93
|
+
<summary><b>Claude Code</b></summary>
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
claude mcp add bale -e BALE_BOT_TOKEN=123456789:your-token -e BALE_ALLOWED_CHATS=your-chat-id -- uvx bale-mcp
|
|
97
|
+
```
|
|
98
|
+
</details>
|
|
99
|
+
|
|
100
|
+
<details>
|
|
101
|
+
<summary><b>Claude Desktop</b></summary>
|
|
102
|
+
|
|
103
|
+
Settings → Developer → Edit Config, then add:
|
|
104
|
+
|
|
105
|
+
```json
|
|
106
|
+
{
|
|
107
|
+
"mcpServers": {
|
|
108
|
+
"bale": {
|
|
109
|
+
"command": "uvx",
|
|
110
|
+
"args": ["bale-mcp"],
|
|
111
|
+
"env": {
|
|
112
|
+
"BALE_BOT_TOKEN": "123456789:your-token",
|
|
113
|
+
"BALE_ALLOWED_CHATS": "your-chat-id"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
</details>
|
|
120
|
+
|
|
121
|
+
<details>
|
|
122
|
+
<summary><b>Cursor</b></summary>
|
|
123
|
+
|
|
124
|
+
Click **Install in Cursor** above and fill in the two values, or add the Claude Desktop block to `~/.cursor/mcp.json`.
|
|
125
|
+
</details>
|
|
126
|
+
|
|
127
|
+
<details>
|
|
128
|
+
<summary><b>VS Code (Copilot agent mode)</b></summary>
|
|
129
|
+
|
|
130
|
+
Add to `.vscode/mcp.json`. VS Code asks for the token once and stores it securely:
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"inputs": [
|
|
135
|
+
{ "type": "promptString", "id": "bale-token", "description": "Bale bot token", "password": true }
|
|
136
|
+
],
|
|
137
|
+
"servers": {
|
|
138
|
+
"bale": {
|
|
139
|
+
"type": "stdio",
|
|
140
|
+
"command": "uvx",
|
|
141
|
+
"args": ["bale-mcp"],
|
|
142
|
+
"env": { "BALE_BOT_TOKEN": "${input:bale-token}", "BALE_ALLOWED_CHATS": "your-chat-id" }
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
</details>
|
|
148
|
+
|
|
149
|
+
<details>
|
|
150
|
+
<summary><b>Anything else</b></summary>
|
|
151
|
+
|
|
152
|
+
It's a standard stdio MCP server: run `uvx bale-mcp`, or `pip install bale-mcp` and run `bale-mcp`, with
|
|
153
|
+
`BALE_BOT_TOKEN` in the environment.
|
|
154
|
+
</details>
|
|
155
|
+
|
|
156
|
+
Then just ask:
|
|
157
|
+
|
|
158
|
+
- "When the test suite finishes, send me the summary on Bale."
|
|
159
|
+
- "Any new messages on Bale? Summarize them and draft replies, but ask me before sending."
|
|
160
|
+
- "Ask me on Bale whether to deploy, with Yes/No buttons, and wait for my answer."
|
|
161
|
+
- "Find the invoice photo someone sent the bot last week and save it to my Downloads."
|
|
162
|
+
- <span dir="rtl">پیام‌های جدید بله را بخوان و خلاصه‌شان را بگو.</span>
|
|
163
|
+
|
|
164
|
+
## How it works
|
|
165
|
+
|
|
166
|
+
```text
|
|
167
|
+
AI agent (Claude, Cursor, Copilot, ...)
|
|
168
|
+
│
|
|
169
|
+
│ MCP over stdio
|
|
170
|
+
▼
|
|
171
|
+
bale-mcp (runs on your machine) ──▶ ~/.bale-mcp/messages.db local history (SQLite)
|
|
172
|
+
│
|
|
173
|
+
│ HTTPS, official Bot API
|
|
174
|
+
▼
|
|
175
|
+
tapi.bale.ai ◀──▶ your Bale app
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Each reading tool first pulls pending updates from Bale (`getUpdates`) into the local store, then answers from
|
|
179
|
+
it. Sent messages are stored too, so a chat's history shows both sides.
|
|
180
|
+
|
|
181
|
+
## Privacy and security
|
|
182
|
+
|
|
183
|
+
- **Local only.** `bale-mcp` runs on your machine. The only host it talks to is `tapi.bale.ai`. There is no relay
|
|
184
|
+
server, no telemetry and no analytics.
|
|
185
|
+
- **Your history stays on your disk.** Messages are kept in `~/.bale-mcp/messages.db` (the folder is user-only on
|
|
186
|
+
macOS/Linux). Set `BALE_MCP_DB=:memory:` to keep nothing on disk, or delete the file at any time.
|
|
187
|
+
- **Allowlist.** With `BALE_ALLOWED_CHATS` set, messages from any other chat are dropped before they are stored or
|
|
188
|
+
shown to the agent, so a stranger who finds your bot cannot feed your agent instructions. The server also
|
|
189
|
+
refuses to send to any other chat.
|
|
190
|
+
- **Prompt-injection aware.** The server tells the agent that message text is data from other people, never
|
|
191
|
+
instructions to follow.
|
|
192
|
+
- **Confirm before sending.** Tools that change something (send, edit, delete) are annotated `destructiveHint`, and
|
|
193
|
+
their descriptions tell the agent to confirm the recipient and content with you first.
|
|
194
|
+
- **The token never leaks.** It never appears in tool output, errors or logs.
|
|
195
|
+
- **Know the limits.** Bale has no end-to-end encryption: Bale's servers see what goes through your bot, as with any
|
|
196
|
+
Bale chat. `bale-mcp` adds no other party.
|
|
197
|
+
|
|
198
|
+
## Tools
|
|
199
|
+
|
|
200
|
+
Chat ids are numbers (they can exceed 32 bits), or `@username` for public channels and groups when sending.
|
|
201
|
+
|
|
202
|
+
<details open>
|
|
203
|
+
<summary><b>📥 Read</b> (6)</summary>
|
|
204
|
+
|
|
205
|
+
| Tool | What it does |
|
|
206
|
+
|---|---|
|
|
207
|
+
| `bot_get_new_messages` | Messages people sent the bot since the last check, from every chat, oldest first |
|
|
208
|
+
| `bot_list_chats` | Chats the bot has talked in, with unread count and last message |
|
|
209
|
+
| `bot_read_chat` | A chat's recent history in both directions |
|
|
210
|
+
| `bot_search_messages` | Search the stored history; Persian-aware |
|
|
211
|
+
| `bot_wait_for_reply` | Wait until someone writes in a chat or taps a button (up to 10 minutes) |
|
|
212
|
+
| `bot_download_file` | Save a photo, document, voice note, ... to this computer (max 20 MB) |
|
|
213
|
+
</details>
|
|
214
|
+
|
|
215
|
+
<details open>
|
|
216
|
+
<summary><b>📤 Send</b> (4)</summary>
|
|
217
|
+
|
|
218
|
+
| Tool | What it does |
|
|
219
|
+
|---|---|
|
|
220
|
+
| `bot_send_message` | Send text, optionally as a reply and with inline buttons |
|
|
221
|
+
| `bot_send_file` | Send a photo, document, video, audio or voice file by URL or local path (max 50 MB) |
|
|
222
|
+
| `bot_edit_message` | Replace the text of a message the bot sent |
|
|
223
|
+
| `bot_delete_message` | Delete a message |
|
|
224
|
+
</details>
|
|
225
|
+
|
|
226
|
+
<details open>
|
|
227
|
+
<summary><b>🔧 Bot</b> (3)</summary>
|
|
228
|
+
|
|
229
|
+
| Tool | What it does |
|
|
230
|
+
|---|---|
|
|
231
|
+
| `bot_get_me` | Check the token: bot id, username, name |
|
|
232
|
+
| `bot_get_chat` | A chat's type, title or name, username and description |
|
|
233
|
+
| `bot_get_webhook_info` | Whether a webhook is set, pending updates and the last error |
|
|
234
|
+
</details>
|
|
235
|
+
|
|
236
|
+
## Good to know
|
|
237
|
+
|
|
238
|
+
- **Someone must message the bot first.** A user has to send `/start` before the bot can message them; in groups and
|
|
239
|
+
channels the bot must be a member.
|
|
240
|
+
- **History starts when `bale-mcp` first reads.** Bale keeps undelivered updates for 24 hours (the last 2000), so
|
|
241
|
+
anything older than that, or read by another program, is gone.
|
|
242
|
+
- **One reader per bot.** Webhooks block `getUpdates`, and two programs polling the same token steal each other's
|
|
243
|
+
updates. `bot_get_webhook_info` shows a webhook. Several `bale-mcp` processes may share one `BALE_MCP_DB`.
|
|
244
|
+
- **Text is Markdown.** Bale formats every message: `*bold*`, `_italic_`.
|
|
245
|
+
- **Button presses** come back as messages of kind `button` whose text is the label (cut to 64 bytes).
|
|
246
|
+
|
|
247
|
+
## FAQ
|
|
248
|
+
|
|
249
|
+
<details>
|
|
250
|
+
<summary><b>Can it read my personal chats?</b></summary>
|
|
251
|
+
|
|
252
|
+
No. It uses the official Bot API, so it only sees what people send to your bot, and messages in groups and channels
|
|
253
|
+
the bot is a member of. It cannot log in as you.
|
|
254
|
+
</details>
|
|
255
|
+
|
|
256
|
+
<details>
|
|
257
|
+
<summary><b>Do I need an Iranian IP?</b></summary>
|
|
258
|
+
|
|
259
|
+
No: in testing `tapi.bale.ai` answered from a foreign (Turkish) exit. If every call fails with "Could not reach
|
|
260
|
+
tapi.bale.ai", set `BALE_MCP_PROXY` to an HTTP proxy that can reach it. Normal system proxy variables are ignored on purpose.
|
|
261
|
+
</details>
|
|
262
|
+
|
|
263
|
+
<details>
|
|
264
|
+
<summary><b>The tools say "Bale rejected the bot token"</b></summary>
|
|
265
|
+
|
|
266
|
+
The token is wrong or was revoked. Copy it again from @botfather. (Bale answers a bad token with HTTP 403 or 404.)
|
|
267
|
+
</details>
|
|
268
|
+
|
|
269
|
+
<details>
|
|
270
|
+
<summary><b>The agent waited and timed out</b></summary>
|
|
271
|
+
|
|
272
|
+
`bot_wait_for_reply` returns `timed_out: true` when nobody answered in time; the agent can call it again. Some MCP
|
|
273
|
+
clients cancel tool calls after about a minute; use a shorter `timeout_seconds` there.
|
|
274
|
+
</details>
|
|
275
|
+
|
|
276
|
+
<details>
|
|
277
|
+
<summary><b>Claude Desktop says <code>uvx</code> is not found</b></summary>
|
|
278
|
+
|
|
279
|
+
Use the full path to `uvx` (`where uvx` on Windows, `which uvx` on macOS/Linux) as `command`.
|
|
280
|
+
</details>
|
|
281
|
+
|
|
282
|
+
<details>
|
|
283
|
+
<summary><b>How do I debug what the agent sees?</b></summary>
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
npx @modelcontextprotocol/inspector -e BALE_BOT_TOKEN=123456789:your-token uvx bale-mcp
|
|
287
|
+
```
|
|
288
|
+
</details>
|
|
289
|
+
|
|
290
|
+
## Configuration
|
|
291
|
+
|
|
292
|
+
| Variable | Default | Meaning |
|
|
293
|
+
|---|---|---|
|
|
294
|
+
| `BALE_BOT_TOKEN` | required | Bot token from @botfather |
|
|
295
|
+
| `BALE_ALLOWED_CHATS` | unset (all chats) | Comma-separated chat ids or `@usernames`; all other chats are ignored and never messaged |
|
|
296
|
+
| `BALE_MCP_DB` | `~/.bale-mcp/messages.db` | Local history file; `:memory:` keeps nothing on disk |
|
|
297
|
+
| `BALE_MCP_PROXY` | unset | HTTP proxy for every request, e.g. `http://user:pass@host:port` |
|
|
298
|
+
|
|
299
|
+
## فارسی
|
|
300
|
+
|
|
301
|
+
<div dir="rtl">
|
|
302
|
+
|
|
303
|
+
**bale-mcp** به دستیار هوش مصنوعی شما (Claude، Cursor، Copilot و ...) اجازه می‌دهد از طریق بازوی (ربات) بله خودتان
|
|
304
|
+
پیام‌ها را بخواند، در آن‌ها جستجو کند، پاسخ و فایل بفرستد، و از شما سؤال بپرسد و منتظر جوابتان بماند.
|
|
305
|
+
|
|
306
|
+
- روی سیستم خود شما اجرا می‌شود و جز سرور بله به هیچ جای دیگری داده نمی‌فرستد.
|
|
307
|
+
- تاریخچه پیام‌ها فقط روی دیسک خودتان ذخیره می‌شود (`BALE_MCP_DB=:memory:` یعنی هیچ ذخیره‌ای).
|
|
308
|
+
- با `BALE_ALLOWED_CHATS` فقط چت‌های شما خوانده می‌شوند و پیام غریبه‌ها اصلاً به دستیار نمی‌رسد.
|
|
309
|
+
- جستجو فارسی را می‌فهمد: «ی/ي»، «ک/ك»، اعداد فارسی و نیم‌فاصله فرقی نمی‌کنند.
|
|
310
|
+
- بله رمزنگاری سرتاسری ندارد؛ این ابزار طرف سومی اضافه نمی‌کند.
|
|
311
|
+
|
|
312
|
+
**نصب در Claude Code:** توکن را از [@botfather](https://ble.ir/botfather) بگیرید و:
|
|
313
|
+
|
|
314
|
+
</div>
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
claude mcp add bale -e BALE_BOT_TOKEN=123456789:your-token -- uvx bale-mcp
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
<div dir="rtl">
|
|
321
|
+
|
|
322
|
+
بعد به بازوی خود `/start` بفرستید و بپرسید: «پیام‌های جدید بله را بخوان.»
|
|
323
|
+
|
|
324
|
+
</div>
|
|
325
|
+
|
|
326
|
+
## Development
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
git clone https://github.com/sepehr071/bale-mcp && cd bale-mcp
|
|
330
|
+
uv sync
|
|
331
|
+
uv run pytest # offline, against a mocked Bot API
|
|
332
|
+
uv run pytest -m live # read-only calls with BALE_BOT_TOKEN
|
|
333
|
+
uv run pytest -m live_send # sends, edits and deletes one message in BALE_TEST_CHAT_ID
|
|
334
|
+
uv run ruff check .
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Tools live in `src/bale_mcp/bot.py` (sending, bot info) and `inbox.py` (reading, waiting, downloads); `store.py`
|
|
338
|
+
is the local SQLite history. Each tool is a typed async function with a docstring that tells the agent when to use
|
|
339
|
+
it. Issues and PRs are welcome.
|
|
340
|
+
|
|
341
|
+
Releases: bump the version in `pyproject.toml` and `server.json`, then push a `v*` tag. GitHub Actions tests,
|
|
342
|
+
publishes to PyPI and the [MCP Registry](https://registry.modelcontextprotocol.io), and creates the GitHub Release.
|
|
343
|
+
|
|
344
|
+
## Disclaimer
|
|
345
|
+
|
|
346
|
+
Unofficial and not affiliated with or endorsed by Bale. It uses Bale's official, public
|
|
347
|
+
[Bot API](https://docs.bale.ai/). Follow Bale's terms, and don't use it to spam people.
|
|
348
|
+
|
|
349
|
+
## License
|
|
350
|
+
|
|
351
|
+
[MIT](https://github.com/sepehr071/bale-mcp/blob/main/LICENSE)
|