unban_user
Restore access to a Telegram chat by removing a user's ban status. Provide chat and user IDs to reverse previous moderation actions.
Instructions
Unban a previously banned user.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chat_id | Yes | ||
| user_id | Yes | ||
| only_if_banned | No |
Implementation Reference
- aiogram_mcp/tools/chats.py:156-191 (handler)Implementation of the unban_user MCP tool handler.
async def unban_user( chat_id: int, user_id: int, only_if_banned: bool = True, ) -> UnbanUserResult: """Unban a previously banned user.""" if not ctx.is_chat_allowed(chat_id): result = UnbanUserResult(ok=False, error=f"Chat {chat_id} is not allowed.") if ctx.audit_logger: ctx.audit_logger.log( "unban_user", {"chat_id": chat_id, "user_id": user_id}, result.ok, result.error, ) return result try: if ctx.rate_limiter: await ctx.rate_limiter.acquire() await ctx.bot.unban_chat_member( chat_id=chat_id, user_id=user_id, only_if_banned=only_if_banned, ) result = UnbanUserResult(ok=True, user_id=user_id) except (TelegramBadRequest, TelegramForbiddenError) as exc: result = UnbanUserResult(ok=False, error=str(exc)) if ctx.audit_logger: ctx.audit_logger.log( "unban_user", {"chat_id": chat_id, "user_id": user_id}, result.ok, result.error, ) - aiogram_mcp/tools/chats.py:34-35 (schema)Result schema for unban_user tool.
class UnbanUserResult(ToolResponse): user_id: int | None = None - aiogram_mcp/tools/chats.py:153-153 (registration)Registration logic for unban_user tool within register_chat_tools.
if allowed_tools is None or "unban_user" in allowed_tools: