Skip to main content
Glama

ListDialogs

Retrieve and manage available Telegram dialogs, chats, and channels. Filter by unread, archived, or pinned status to streamline access to specific conversations.

Instructions

List available dialogs, chats and channels.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
archivedNo
ignore_pinnedNo
unreadNo

Implementation Reference

  • The main handler function for the 'ListDialogs' tool. It connects to Telegram using create_client, iterates over dialogs applying filters for unread, archived, and ignore_pinned, formats dialog info, and returns a list of TextContent.
    @tool_runner.register async def list_dialogs( args: ListDialogs, ) -> t.Sequence[TextContent | ImageContent | EmbeddedResource]: client: TelegramClient logger.info("method[ListDialogs] args[%s]", args) response: list[TextContent] = [] async with create_client() as client: dialog: custom.dialog.Dialog async for dialog in client.iter_dialogs(archived=args.archived, ignore_pinned=args.ignore_pinned): if args.unread and dialog.unread_count == 0: continue msg = ( f"name='{dialog.name}' id={dialog.id} " f"unread={dialog.unread_count} mentions={dialog.unread_mentions_count}" ) response.append(TextContent(type="text", text=msg)) return response
  • Pydantic BaseModel defining the input schema for the ListDialogs tool, including optional filters: unread, archived, ignore_pinned.
    class ListDialogs(ToolArgs): """List available dialogs, chats and channels.""" unread: bool = False archived: bool = False ignore_pinned: bool = False
  • Dynamically scans the tools module for subclasses of ToolArgs (including ListDialogs), generates Tool descriptions using tool_description, and populates the mapping dictionary used by MCP server's list_tools and call_tool endpoints.
    @cache def enumerate_available_tools() -> t.Generator[tuple[str, Tool], t.Any, None]: for _, tool_args in inspect.getmembers(tools, inspect.isclass): if issubclass(tool_args, tools.ToolArgs) and tool_args != tools.ToolArgs: logger.debug("Found tool: %s", tool_args) description = tools.tool_description(tool_args) yield description.name, description mapping: dict[str, Tool] = dict(enumerate_available_tools())
  • Utility function that converts a ToolArgs class (like ListDialogs) into an MCP Tool object with name, description (docstring), and inputSchema (JSON schema). Used during tool registration.
    def tool_description(args: type[ToolArgs]) -> Tool: return Tool( name=args.__name__, description=args.__doc__, inputSchema=args.model_json_schema(), )

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sparfenyuk/mcp-telegram'

If you have feedback or need assistance with the MCP directory API, please join our Discord server