get_chat_members_count
Retrieve the total number of participants in a Telegram chat using the chat ID to monitor group size and manage community engagement.
Instructions
Get the number of members in a chat.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chat_id | Yes |
Implementation Reference
- aiogram_mcp/tools/chats.py:82-99 (handler)Implementation of the 'get_chat_members_count' tool handler, which uses the bot context to fetch the chat member count and logs the outcome.
async def get_chat_members_count(chat_id: int) -> ChatMembersCountResult: """Get the number of members in a chat.""" try: if ctx.rate_limiter: await ctx.rate_limiter.acquire() count = await ctx.bot.get_chat_member_count(chat_id=chat_id) result = ChatMembersCountResult(ok=True, count=count) except (TelegramBadRequest, TelegramForbiddenError) as exc: result = ChatMembersCountResult(ok=False, error=str(exc)) if ctx.audit_logger: ctx.audit_logger.log( "get_chat_members_count", {"chat_id": chat_id}, result.ok, result.error, ) return result - aiogram_mcp/tools/chats.py:24-25 (schema)Definition of the response model 'ChatMembersCountResult' used by the tool.
class ChatMembersCountResult(ToolResponse): count: int | None = None - aiogram_mcp/tools/chats.py:79-79 (registration)Registration/conditional logic for the tool in the 'register_chat_tools' function.
if allowed_tools is None or "get_chat_members_count" in allowed_tools: