Multi-account Telegram MCP and configuration
Startup configuration lives in config.toml (annotated template in config.example.toml) with GRAMCP_* environment overrides. Runtime chat lists, enabled tools, kill switch, and signatures live in SQLite state.db.
Safe defaults
| Setting | Default | Effect |
|---|---|---|
hard_ceiling | ["read", "organize", "send"] | Blocks moderate, destructive, account, and money tiers unconditionally. |
whitelist_mode | "strict" | Refuses every outbound destination until explicitly added via chats allow or /settings. |
safe_delete_only | true (60 min) | Even if destructive is enabled, only gramcp-sent messages within 60 minutes can be deleted. |
rate_limit | 60/hr global, 20/hr per chat | Rolling SQLite buckets counting every outgoing message (albums and forwards count per item). |
inbox_dir | Unset (None) | get_media stays in RAM (4 MiB cap) and refuses disk writes unless inbox_dir is explicitly configured. |
signature.enabled | true (— Sent by AI) | Appended after body entities finalize; [nosig] only works at the trailing end (or disable opt-out completely). |
Managing chat rules from the CLI
Every mutating CLI command writes a cli_chats entry into audit_log:
# Allow Saved Messages and a specific peer with username pinning
gramcp --config config.local.toml chats allow me --label "Saved Messages"
gramcp --config config.local.toml chats allow 123456789 --username @colleague --label "Colleague"
# Hide a private chat completely from every read, list, search, and forward
gramcp --config config.local.toml chats block -1001234567890 --label "Family"
# Inspect rules or flip the persistent sending kill switch
gramcp --config config.local.toml chats list
gramcp --config config.local.toml chats pause
gramcp --config config.local.toml chats resume
Multiple isolated accounts
Define [accounts.<alias>] blocks in config.toml (or add dynamic accounts via QR code in /settings). Each account gets its own session_<alias>.db (`0600`), isolated SQLite policy state, and optional per-account overrides:
default_account = "personal"
[accounts.personal]
label = "Personal"
[accounts.work]
label = "Work"
hard_ceiling = ["read", "organize", "send"]
whitelist_mode = "strict"
outbox_dir = "/srv/gramcp/outbox/work"
[accounts.work.rate_limit]
global_per_hour = 30
per_chat_per_hour = 10
| Routing mode | Endpoint | Account selection & isolation |
|---|---|---|
| Unpinned multi-account | /mcp (or stdio) |
Every tool except list_accounts accepts an explicit account argument (omitted uses default_account). Unknown aliases fail closed with invalid_input. No stateful switch_account tool exists. |
| Pinned single-account | /mcp/<alias> |
Hides account from tool schemas, rejects cross-account calls with invalid_input, accepts a per-account bearer_token (401 elsewhere), and publishes per-account OAuth metadata scoped strictly to account:<alias> (403 elsewhere). |
Hot-adding accounts via QR code in /settings
You can add or re-authenticate Telegram accounts live from the Accounts tab in /settings without restarting gramcp. The browser shows an inline SVG QR code (plus a 2FA prompt if enabled), writes the new alias to dynamic_accounts in SQLite, and immediately exposes its /mcp/<alias> endpoint and account:<alias> OAuth scope.
Dynamic accounts inherit the root hard_ceiling, sandbox directories, rate limits, and signature rules (with whitelist_mode and signature editable per account live in /settings without restart), derive session_<alias>.db server-side, and cannot overwrite or delete static [accounts.<alias>] TOML entries. Deleting a dynamic account disconnects its MTProto pool, revokes scoped OAuth grants, and deletes its session_<alias>.db files. On the CLI, pass --account work to login, doctor, and chats.
Full reference: docs/configuration.md and docs/deployment.md.