Skip to main content
Glama
aminmadaniofficial

Bale MCP Server

README.md
# Bale MCP Server ๐Ÿš€

<div align="center">

[![CI Test Suite](https://github.com/aminmadaniofficial/bale-mcp-server/actions/workflows/ci.yml/badge.svg)](https://github.com/aminmadaniofficial/bale-mcp-server/actions/workflows/ci.yml)
[![Tools](https://img.shields.io/badge/Tools-32%20Ready-success.svg)](#-complete-mcp-tools-catalog-32-tools)
[![Powered by aiobale](https://img.shields.io/badge/Powered%20by-aiobale--py-3b82f6.svg)](https://github.com/aminmadaniofficial/aiobale)
[![Model Context Protocol](https://img.shields.io/badge/MCP-Standard-purple.svg)](https://modelcontextprotocol.io/)
[![Python Version](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://www.python.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![GitHub Stars](https://img.shields.io/github/stars/aminmadaniofficial/bale-mcp-server?style=social)](https://github.com/aminmadaniofficial/bale-mcp-server)

**Production-grade Model Context Protocol (MCP) server for Bale Messenger.**  
Empowers Large Language Models (LLMs) to authenticate, inspect dialogs, read histories, send messages, interact with groups, and manage contacts on Bale user accounts.

</div>

---

## ๐ŸŒŸ Key Highlights

- โšก **Native Async Performance:** Powered by [`aiobale-py`](https://github.com/aminmadaniofficial/aiobale) and official Python MCP SDK (`mcp.server.mcpserver`).
- ๐Ÿ” **Multi-Account Sessions:** Auto-discovers and switches between `.bale` sessions on disk with zero credentials re-prompting.
- ๐Ÿ“ฑ **Interactive & Tool-based Auth:** Support for interactive phone SMS login via CLI (`bale-mcp login`) or programmatically via MCP tools (`bale_auth_request_code`, `bale_auth_verify_code`, `bale_auth_verify_password`).
- ๐Ÿ’ฌ **Complete Messaging Ecosystem:** Send, reply, edit, delete, forward, pin, and mark read across private chats, groups, and channels.
- ๐Ÿ‘ฅ **Contacts & Profile Search:** Query users by `@username` or phone number, fetch full profiles, manage contacts, and block/unblock.
- ๐Ÿ“ข **Groups & Channels Management:** Inspect settings, member counts, invite users, generate invite URLs, and manage participant states.
- โšก **Reactions & Presence:** Send and remove emoji reactions (`๐Ÿ‘`, `โค๏ธ`, `๐Ÿ”ฅ`) and broadcast typing indicators.
- ๐Ÿ›ก๏ธ **Zero Data Leakage:** Session keys and `.bale` tokens remain strictly local and are protected by `.gitignore`.

---

## ๐Ÿ“ฆ Architecture

```
LLM Client (Claude Desktop / Cursor / Antigravity / Cline)
                        โ”‚
                        โ”‚ JSON-RPC (STDIO / SSE / Streamable HTTP)
                        โ–ผ
                Bale MCP Server
                        โ”‚
               Session Connection Pool
                        โ”‚
           aiobale Async Client (WebSockets / Protobuf)
                        โ–ผ
              Bale Messenger Network
```

---

## ๐Ÿ› ๏ธ Complete MCP Tools Catalog (34 Tools)

### ๐Ÿ” Authentication & Session Management
| Tool Name | Description |
| :--- | :--- |
| `bale_list_sessions` | List all available Bale user sessions/accounts stored locally on disk. |
| `bale_connect_session` | Connect or switch to a specific Bale account using session name or phone. |
| `bale_get_me` | Get profile information and connection status of the active account. |
| `bale_auth_request_code` | Request an SMS/Bale verification code for a new account login. |
| `bale_auth_verify_code` | Verify SMS/Bale authentication code to save a new `.bale` session. |
| `bale_auth_verify_password` | Submit Two-Factor Authentication (2FA) cloud password if required. |
| `bale_disconnect` | Disconnect the active account session. |

### ๐Ÿ’ฌ Messaging & Dialogs
| Tool Name | Description |
| :--- | :--- |
| `bale_get_dialogs` | Retrieve recent chats, groups, and channels with resolved titles/names, unread counts, and last messages. |
| `bale_search_dialogs` | Search dialogs and groups by title/name (in Persian or English) or chat ID. |
| `bale_get_chat_history` | Fetch recent message history from a chat, group, or channel. |
| `bale_send_message` | Send a text message to a user, group, or channel with optional reply support. |
| `bale_edit_message` | Edit an existing text message or media caption (automatic media fallback). |
| `bale_edit_media_caption` | Update caption of existing media (photos, videos, GIFs, docs) with metadata sanitization. |
| `bale_batch_edit_messages`| Batch edit multiple messages/captions in a single call with anti-flood throttling. |
| `bale_delete_message` | Delete a message from a chat (for self or everyone). |
| `bale_forward_message` | Forward an existing message to another chat or user. |
| `bale_mark_chat_read` | Mark all messages in a chat or group as read. |
| `bale_pin_message` | Pin a message in a private chat or group. |

### ๐Ÿ‘ฅ Contacts & Users
| Tool Name | Description |
| :--- | :--- |
| `bale_get_contacts` | Retrieve the saved contact list from the active account. |
| `bale_search_user` | Search for a user, bot, group, or channel by username or phone number. |
| `bale_get_user_info` | Get detailed profile information (name, about, username) by user ID. |
| `bale_import_contacts` | Import one or more contacts by phone number and name into the address book. |
| `bale_block_user` | Block a user by user ID. |
| `bale_unblock_user` | Unblock a previously blocked user by user ID. |
| `bale_get_blocked_users` | List all users currently blocked by the active account. |

### ๐Ÿ“ข Groups & Channels
| Tool Name | Description |
| :--- | :--- |
| `bale_get_group_info` | Retrieve full information, settings, member count, and permissions for a group. |
| `bale_get_group_members` | Retrieve the list of members in a group or channel. |
| `bale_create_group` | Create a new group or broadcast channel with initial members. |
| `bale_invite_to_group` | Invite one or more users to an existing group or channel. |
| `bale_get_group_invite_url`| Get the permanent invitation link (URL) for a group or channel. |
| `bale_leave_group` | Leave a group or channel. |

### โšก Reactions & Presence
| Tool Name | Description |
| :--- | :--- |
| `bale_send_reaction` | Add an emoji reaction (`๐Ÿ‘`, `โค๏ธ`, `๐Ÿ”ฅ`) to a specific message. |
| `bale_remove_reaction` | Remove an emoji reaction from a message. |
| `bale_send_typing` | Send a typing indicator to a chat or group. |

---

## ๐Ÿš€ Installation & Setup

### 1. Prerequisites
- Python 3.10 or higher
- [`uv`](https://docs.astral.sh/uv/) (recommended) or standard `pip`

### 2. Install from Repository
```bash
git clone https://github.com/aminmadaniofficial/bale-mcp-server.git
cd bale-mcp-server

uv venv
source .venv/bin/activate
uv pip install -e .
```

### 3. Log In to Your Bale Account

You can authenticate directly using the built-in CLI:

```bash
bale-mcp login --phone 989XXXXXXXXX
```
This requests an SMS code and saves the session securely in `./sessions/<phone>.bale`.

To view existing sessions:
```bash
bale-mcp list-sessions
```

---

## ๐Ÿ”Œ MCP Client Configuration

### Claude Desktop (`claude_desktop_config.json`)
```json
{
  "mcpServers": {
    "bale": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/bale-mcp-server",
        "run",
        "bale-mcp",
        "run"
      ],
      "env": {
        "BALE_SESSIONS_DIR": "/absolute/path/to/bale-mcp-server/sessions"
      }
    }
  }
}
```

### Antigravity IDE (`mcp_config.json`)
```json
{
  "mcpServers": {
    "bale": {
      "command": "/absolute/path/to/bale-mcp-server/.venv/bin/bale-mcp",
      "args": ["run"],
      "env": {
        "BALE_SESSIONS_DIR": "/absolute/path/to/bale-mcp-server/sessions"
      }
    }
  }
}
```

---

## ๐Ÿงช Testing

Run the automated test suite:
```bash
pytest -v
```

---

## ๐Ÿ“„ License

This project is licensed under the [MIT License](LICENSE).

TDQS

B3/5.0

Scored across 32 tools

Disambiguation4/5

Most tools have clearly distinct purposes (send vs edit vs delete, block vs unblock), but a few pairs like search_dialogs vs search_user and get_me vs get_user_info could be confused. Descriptions help clarify the boundaries, but the overlap is not fully eliminated.

Naming Consistency5/5

All tools use the bale_ prefix and snake_case, following a consistent verb_noun pattern (list_sessions, send_message, block_user). Minor variations like auth_ prefix are still predictable and readable.

Tool Count2/5

32 tools exceeds the recommended 3-15 range and falls into the 25+ category, which the rubric marks as too many for the apparent scope. While each operation serves a purpose, the surface is heavy and could be consolidated.

Completeness3/5

Core text messaging, contacts, groups, and authentication are covered, but notable gaps exist: no media/file sending, no message search, no group member removal, no join-by-invite, and no unpin message. These omissions limit full messenger workflows.

Maintenance

ActivityMaintained
ResponsivenessNo issues