Skip to main content
Glama

resolve_contact

Resolve iMessage handles to names or names to handles by checking a local cache and macOS AddressBook.

Instructions

Resolve an iMessage handle to a name, or a name to handles.

Provide either handle (phone like +15551234567 or email) or name. Checks a local JSON cache first, then falls back to the macOS AddressBook SQLite. New hits are written back to the cache for future sessions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameNo
handleNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The @mcp.tool()-decorated handler that resolves contacts; delegates to contacts.resolve_handle() and contacts.resolve_name().
    @mcp.tool()
    def resolve_contact(
        name: str | None = None, handle: str | None = None
    ) -> dict[str, Any]:
        """Resolve an iMessage handle to a name, or a name to handles.
    
        Provide either `handle` (phone like +15551234567 or email) or `name`.
        Checks a local JSON cache first, then falls back to the macOS AddressBook
        SQLite. New hits are written back to the cache for future sessions.
        """
        if handle:
            return contacts.resolve_handle(handle)
        if name:
            return {"name": name, "matches": contacts.resolve_name(name)}
        raise ValueError("Provide 'name' or 'handle'")
  • Registration via @mcp.tool() decorator on FastMCP('imessage') instance.
    @mcp.tool()
    def resolve_contact(
        name: str | None = None, handle: str | None = None
  • Helper function that resolves a handle (phone/email) to a contact name, checking cache then AddressBook.
    def resolve_handle(handle: str) -> dict[str, Any]:
        """Resolve an iMessage handle (phone/email) to a contact name."""
        with _lock:
            cache = _load_cache()
            entry = cache.get(handle)
            if entry and entry.get("name"):
                return {"handle": handle, "name": entry["name"], "source": entry.get("source", "cache")}
            name = _ab_lookup_by_handle(handle)
            if name:
                cache.setdefault(handle, {})
                cache[handle].update({"handle": handle, "name": name, "source": "addressbook.sqlite"})
                _save_cache()
                return {"handle": handle, "name": name, "source": "addressbook.sqlite"}
            return {"handle": handle, "name": None, "source": None}
  • Helper function that resolves a contact name to handles, checking cache then AddressBook and normalizing phones to E.164.
    def resolve_name(name: str) -> list[dict[str, Any]]:
        """Resolve a contact name to iMessage handles (phones normalized to E.164)."""
        with _lock:
            cache = _load_cache()
            needle = name.strip().lower()
            cache_hits = [
                {"handle": h, "name": e.get("name"), "source": "cache"}
                for h, e in cache.items()
                if e.get("name") and needle in e["name"].lower()
            ]
            ab_hits = _ab_lookup_by_name(name)
            # Flatten AB hits into one entry per phone/email.
            ab_flat: list[dict[str, Any]] = []
            for hit in ab_hits:
                for p in hit.get("phones", []):
                    normalized = _normalize_phone_to_handle(p)
                    if normalized:
                        ab_flat.append({"handle": normalized, "name": hit["name"], "source": "addressbook.sqlite"})
                for e in hit.get("emails", []):
                    if e:
                        ab_flat.append({"handle": e.lower(), "name": hit["name"], "source": "addressbook.sqlite"})
    
            # Merge by handle, preferring cache source attribution.
            seen: dict[str, dict[str, Any]] = {}
            for item in cache_hits + ab_flat:
                seen.setdefault(item["handle"], item)
    
            # Write any new AB-only entries back to cache (no stats) so future sessions skip the AB lookup.
            dirty = False
            for item in ab_flat:
                h = item["handle"]
                if h not in cache or not cache[h].get("name"):
                    cache.setdefault(h, {})
                    cache[h].update({"handle": h, "name": item["name"], "source": "addressbook.sqlite"})
                    dirty = True
            if dirty:
                _save_cache()
    
            return list(seen.values())
Behavior5/5

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

Since no annotations are provided, the description fully covers behavioral traits: it checks a local JSON cache first, then falls back to macOS AddressBook SQLite, and writes new hits back to the cache. This is valuable for an agent to understand side effects and performance.

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

Conciseness5/5

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

The description is three sentences, each serving a clear purpose: defining the function, specifying input options with format hints, and explaining the cache behavior. No unnecessary 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?

The description provides sufficient information for using the tool given its two optional parameters, lack of annotations, and presence of an output schema. It covers purpose, input selection, and caching behavior, though it omits error cases or output details (covered by schema).

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

Parameters4/5

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

The input schema has 0% description coverage, but the description compensates by explaining the format for `handle` (phone or email) and that exactly one of `handle` or `name` should be provided. It adds value beyond the raw schema properties.

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?

The description clearly states it resolves iMessage handles to names and vice versa, using specific verbs and resources. It distinguishes itself from sibling tools (e.g., get_chat_messages, send_imessage) which deal with messaging rather than contact resolution.

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

Usage Guidelines4/5

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

The description explains that either `handle` or `name` must be provided, with format hints for handle (phone or email). It doesn't explicitly state when not to use it or list alternatives, but the context with sibling tools makes its unique role clear.

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

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