Skip to main content
Glama
prem-research

Telegram MCP Server

get_messages

Retrieve a specified number of messages from a Telegram entity to monitor conversations or extract information for analysis.

Instructions

Get messages limited by a count from an entity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes
countNo

Implementation Reference

  • Registration of the MCP tool 'get_messages' using FastMCP decorator.
    @mcp.tool(
        name="get_messages", description="Get messages limited by a count from an entity"
    )
  • Handler function for the 'get_messages' MCP tool, which proxies the request to the HTTP API endpoint.
    async def get_messages(id: int, count: int = 0) -> list[dict]:
        return get(f"{api_endpoint}get_messages/{id}", params={"count": count}).json()
  • Backend HTTP API endpoint that implements the core logic for fetching and formatting Telegram messages using Telethon client.
    @app.get("/get_messages/{chat_id}")
    async def get_messages(chat_id: int, count: int = 0):
        entities = {}
        messages = []
    
        e: Entity = await get_entity(entity=chat_id, raw=True)
    
        async for message in client.iter_messages(entity=e, reverse=False, limit=count):
            e_id: int = None
            if message.from_id is not None:
                e_id = message.from_id.user_id
            elif message.peer_id is not None:
                e_id = message.peer_id.user_id
    
            if e_id not in entities:
                entity = await client.get_entity(e_id)
                entities[e_id] = entity
    
            # Handle message text that might be binary
            message_text = message.message
            if isinstance(message_text, bytes):
                try:
                    message_text = message_text.decode('utf-8', errors='replace')
                except Exception:
                    message_text = '[Binary content]'
    
            messages += [
                {
                    "text": message_text,
                    "date": message.date,
                    "id": message.id,
                    "from": await format_entity(entity=entities[e_id]),
                }
            ]
    
            await client.send_read_acknowledge(entity=chat_id, message=message)
    
        return messages
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'limited by a count' but doesn't explain what happens if count is 0 (default), whether this is a read-only operation, how results are returned, or any rate limits or permissions required. The description adds minimal behavioral context beyond the basic action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words. It's appropriately sized for a simple tool, though it could be more front-loaded with key details. The structure is clear but minimal.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (2 parameters, no output schema, no annotations), the description is incomplete. It lacks details on return values, error handling, behavioral traits, and parameter specifics. For a tool with zero schema coverage and no annotations, this description leaves significant gaps in understanding how to use it effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'limited by a count' and 'from an entity', which loosely maps to the 'count' and 'id' parameters, but doesn't clarify what 'entity' means (e.g., user, channel, group) or provide format details. The description adds some meaning but insufficiently compensates for the coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool 'Get messages limited by a count from an entity', which provides a basic verb+resource combination ('get messages'). However, it's vague about what 'entity' refers to and doesn't distinguish this tool from sibling tools like 'get_unread_messages'. The purpose is understandable but lacks specificity and differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'get_unread_messages' or 'get_entities', nor does it specify prerequisites, exclusions, or appropriate contexts. Usage is implied but not explicitly defined.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/prem-research/telegram-mcp'

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