Skip to main content
Glama
viraatdas

iMessage MCP Server

by viraatdas

get_contact_info

Retrieve contact details and conversation statistics from iMessage using a phone number or email address to identify message history and communication patterns.

Instructions

Look up a contact/handle by phone number or email and return conversation stats.

Args: identifier: Phone number (e.g. +15551234567) or email address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
identifierYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'get_contact_info' function is defined as an MCP tool. It queries the iMessage chat database to retrieve statistics about a contact, such as message counts and timestamps for their first and last messages.
    @mcp.tool()
    async def get_contact_info(identifier: str) -> str:
        """Look up a contact/handle by phone number or email and return conversation stats.
    
        Args:
            identifier: Phone number (e.g. +15551234567) or email address
        """
        db = _get_db()
        row = db.execute(
            """
            SELECT
                h.id,
                h.service,
                h.country,
                COUNT(m.ROWID) as total_messages,
                SUM(CASE WHEN m.is_from_me = 1 THEN 1 ELSE 0 END) as sent,
                SUM(CASE WHEN m.is_from_me = 0 THEN 1 ELSE 0 END) as received,
                MIN(m.date) as first_message,
                MAX(m.date) as last_message
            FROM handle h
            LEFT JOIN message m ON m.handle_id = h.ROWID
            WHERE h.id = ?
            GROUP BY h.ROWID
            """,
            (identifier,),
        ).fetchone()
        db.close()
    
        if not row:
            return json.dumps({"error": f"No contact found for {identifier}"})
    
        return json.dumps(
            {
                "identifier": row["id"],
                "service": row["service"],
                "country": row["country"] or "",
                "total_messages": row["total_messages"],
                "sent": row["sent"],
                "received": row["received"],
                "first_message": _apple_ts_to_iso(row["first_message"]),
                "last_message": _apple_ts_to_iso(row["last_message"]),
            },
            indent=2,
        )
Behavior3/5

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

With no annotations, description carries full burden. It discloses the read-only nature ('Look up') and mentions output ('conversation stats'), but lacks safety context (permissions required, rate limits) or side-effect warnings.

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?

Efficient two-part structure with front-loaded purpose and indented Args block. The Python-docstring style 'Args:' formatting is slightly informal but clear. No wasted words.

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?

Appropriate for complexity: single parameter, output schema exists (so return values needn't be detailed). Acknowledges output type ('conversation stats'). Could mention error cases (contact not found) but sufficient for selection.

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?

Excellent compensation for 0% schema coverage. The Args section provides semantic meaning (identifier = phone OR email) and crucial format guidance (e.g. +15551234567) that the schema lacks.

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

Purpose4/5

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

Clear specific verb ('Look up') and resource ('contact/handle'), and distinguishes from siblings by specifying it returns 'conversation stats' rather than message content. Slightly awkward phrasing ('contact/handle') prevents a 5.

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?

No guidance on when to use this versus siblings like 'search_messages' or 'list_conversations'. No mention that this requires an exact identifier (phone/email) versus partial matching.

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