Skip to main content
Glama
viraatdas

iMessage MCP Server

by viraatdas

get_messages

Retrieve recent messages from a specific iMessage conversation using a phone number, email, or group chat identifier to access message history.

Instructions

Get messages from a specific conversation.

Args: chat_identifier: Phone number (e.g. +15551234567), email, or group chat identifier limit: Max messages to return (default 50, most recent first)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_identifierYes
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The `get_messages` function is implemented here, which queries the iMessage `chat.db` database to retrieve messages for a given chat identifier.
    @mcp.tool()
    async def get_messages(
        chat_identifier: str,
        limit: int = 50,
    ) -> str:
        """Get messages from a specific conversation.
    
        Args:
            chat_identifier: Phone number (e.g. +15551234567), email, or group chat identifier
            limit: Max messages to return (default 50, most recent first)
        """
        db = _get_db()
        rows = db.execute(
            """
            SELECT
                m.text,
                m.date as apple_date,
                m.is_from_me,
                COALESCE(h.id, 'me') as sender,
                m.associated_message_type,
                m.balloon_bundle_id
            FROM message m
            LEFT JOIN handle h ON h.ROWID = m.handle_id
            LEFT JOIN chat_message_join cmj ON cmj.message_id = m.ROWID
            LEFT JOIN chat c ON c.ROWID = cmj.chat_id
            WHERE (c.chat_identifier = ? OR h.id = ?)
              AND m.text IS NOT NULL
              AND m.text != ''
            ORDER BY m.date DESC
            LIMIT ?
            """,
            (chat_identifier, chat_identifier, limit),
        ).fetchall()
        db.close()
    
        messages = []
        for r in rows:
            messages.append(
                {
                    "text": r["text"],
                    "date": _apple_ts_to_iso(r["apple_date"]),
                    "from_me": bool(r["is_from_me"]),
                    "sender": r["sender"] if not r["is_from_me"] else "me",
                }
            )
        # Return in chronological order
        messages.reverse()
        return json.dumps(messages, indent=2)
Behavior3/5

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

No annotations provided, so description carries full burden. It adds valuable behavioral context: 'most recent first' ordering and default 50. However, it lacks explicit read-only safety confirmation, error handling details (what happens if chat_identifier not found), and pagination behavior.

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?

Front-loaded purpose statement followed by Args section. Information density is high with minimal waste. The Args format slightly deviates from natural language but remains scannable and functional.

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

Completeness4/5

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

Appropriately complete given the presence of an output schema (covering return values) and simple flat parameter structure. Both parameters are documented. Minor gap: could mention error cases (invalid identifier) or if additional pagination exists beyond the limit parameter.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by documenting both parameters: chat_identifier includes format examples (+15551234567) and allowed types (phone, email, group), while limit includes default value and semantics. This exceeds the burden for low-coverage schemas.

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

Purpose5/5

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

Clear specific verb 'Get' with resource 'messages' and scope 'from a specific conversation'. Implicitly distinguishes from sibling search_messages (specific vs search) and send_message (read vs write).

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

Usage Guidelines3/5

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

Provides implied usage via 'specific conversation' which suggests using this when the chat identifier is known, but lacks explicit guidance like 'Use search_messages to find messages across conversations' or prerequisites such as needing the chat_identifier from list_conversations.

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/viraatdas/imessage-mcp'

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