Skip to content

CardDAV / iCloud compatibility

This document is Contacts-specific. Calendar uses the separate CalDAV client in caldav-compatibility.md.

Item Value
Protocol CardDAV over HTTPS
Endpoints contacts.icloud.com and p[0-9]{1,3}-contacts.icloud.com:443
Authentication HTTP Basic with ICLOUD_EMAIL and ICLOUD_PASSWORD
Reads vCard 3.0 and 4.0; PHOTO bytes omitted
Writes vCard 3.0 with strong If-Match; vCard 4.0 and groups are read-only
Search Server prefilter plus local re-filter; digit-normalized phone matching
Limits 100 books; 2,000 cards per search; 60 reads and 20 writes per minute
  • Entry URL: https://contacts.icloud.com/.
  • Authentication uses HTTP Basic over verified TLS. Contacts owns a copy of ICLOUD_EMAIL and ICLOUD_PASSWORD.
  • The allowlist uses case-sensitive equality. It accepts contacts.icloud.com:443 and lowercase p[0-9]{1,3}-contacts.icloud.com:443 shards only.
  • The client does not change host case before comparison.
  • TLS uses verified system roots and TLS 1.2 or later. The transport sets Proxy: nil.
  • The Contacts transport cannot attach Calendar credentials. A Contacts redirect cannot use the Calendar allowlist.

Apple documents third-party Contacts access through CardDAV and app-specific passwords. Exact shard and discovery behavior is an interoperability property. It does not prove that any iCloud regional authority is safe. The allowlist excludes host patterns that the project did not review.

The first Contacts call sends these requests:

  1. Depth 0 PROPFIND for current-user-principal.
  2. Depth 0 PROPFIND on the principal for addressbook-home-set.
  3. Send Depth 1 PROPFIND on each validated home set. Request address-book collections, display metadata, supported address data, and maximum resource size.

Discovery runs once for concurrent callers. Its limit is 10 seconds within the 25 second tool deadline. The client caches only a complete, validated success. A later call can retry after failure. Successful principal, home-set, collection, and shard authorities stay fixed for the process lifetime.

Zero home sets maps to not_found. Duplicate homes or books fail closed. Collection escape, unapproved authorities, and more than 100 books also fail closed. Tools receive only opaque book-... identifiers from validated collection URLs. Callers cannot supply a CardDAV URL.

The client disables automatic HTTP redirects. For reads, it manually follows 301, 302, 307, and 308 for at most three hops. It preserves the request method and body.

The client resolves relative Location and DAV href values against the exact response URL. It then validates HTTPS, the port, and collection containment. It also uses a case-sensitive host allowlist. Production hosts use lowercase.

The client rejects read-side 303 and all other redirect codes. It never follows a redirect after PUT or DELETE dispatch. Such a redirect returns outcome_unknown. This rule also applies to malformed or policy-violating redirects.

CardDAV resource hrefs are arbitrary. The client never assumes that a UID maps to UID.vcf. UID lookup uses an addressbook-query and requires exactly one match. The client keeps the returned href internally. It sends a full GET before it returns or changes the contact.

  • Reads accept vCard 3.0 and 4.0.
  • A vCard 4.0 contact can omit N. Version 3.0 requires exactly one N and one FN. Version 4.0 requires one or more FN and accepts zero or one N.
  • A present N must contain five components for both versions.
  • Multiple vCard 4.0 FN alternatives are valid. The client selects the lowest PREF value, then the first non-empty property in document order.
  • Writes encode only vCard 3.0. An address book is writable when it advertises 3.0 or does not include supported-address-data.
  • Create includes VERSION, PRODID, UID, FN, and N.
  • A caller can provide client_uid. Otherwise, the client generates a UUIDv4-compatible UID with crypto/rand.
  • Results do not contain PHOTO bytes, raw vCards, or raw extension values. Full contact reads set hasPhoto when a PHOTO property is present.
  • Thus, a caller can detect an avatar without image bytes.
  • A vCard 3.0 update modifies the full decoded object, preserving PHOTO and unknown properties that fit the resource limit.
  • vCard 4.0 objects are read-only. This rule prevents a silent downgrade through the 3.0 encoder.
  • Apple group cards are readable and excluded from search by default. The server rejects group mutation.
  • The result includes a birthday only when it is a valid YYYY-MM-DD value. Unsupported forms produce unsupportedFields: ["birthday"] without the raw value.

Modeled contact detail can include these fields:

  • Display and structured names
  • Organization, title, nickname, and birthday
  • Typed email addresses, phone numbers, and URLs
  • Postal addresses and notes
  • ETag and address-book identifier.

Search summaries omit notes, addresses, URLs, birthdays, raw cards, and photos.

search_contacts uses a bounded CardDAV server predicate when its text matching has the requested meaning. A general query sends one any-of FN/N/EMAIL/TEL/ORG contains filter. Without a general query, email uses an EMAIL contains filter.

The client then checks each returned card locally. It combines all supplied query, email, phone, and include_groups conditions. Thus, the server prefilter does not define the final result.

The client normalizes digits for local phone matching. It never sends phone as a TEL text predicate. Thus, a phone-only search sends the bounded VERSION-presence all-card query. A compatible query or email predicate can reduce the candidate set. The client then applies the phone condition locally.

Local matching is:

  • query: i;unicode-casemap-compatible substring across FN, N, EMAIL, TEL, and ORG. The local comparator applies per-code-point titlecase, a case-insensitive comparison, then NFKD compatibility decomposition. This treats Greek small sigma, final sigma, and capital sigma alike and keeps ligature equivalence.
  • email: case-insensitive EMAIL substring.
  • phone: digit-normalized TEL substring.
  • include_groups: false by default.

All selected books share total limits of 2,000 decoded cards and 32 MiB of REPORT responses. Results sort by normalized display name, then UID, then book. The default result limit is 50, and the maximum is 100. A call without cursor keeps that single-page result and returns no continuation.

The canonical sort key is strings.ToLower(strings.TrimSpace(displayName)), then UID, then address book. The same key is used by the single-book service, the scoped multi-book merge, and cursor continuation.

cursor="start" opts into bounded continuation. The first page runs the same aggregate 2,000-card and 32 MiB scan budget, keeps the complete bounded match set, and returns one page of at most limit summaries. Every later page reads that retained result set and issues no CardDAV request, so page navigation does not repeat a REPORT, vCard decode, or sort per book.

nextCursor is a signed c3 token that expires after 300 seconds and binds the address book, every filter, and the effective contacts.read scope. limit is not bound and may change between pages. The token carries only a random entry identifier and the filter digest; the result set stays in a bounded per-registration, process-local cache. A forged, expired, cross-filter, cross-scope, or cross-registration token fails before any backend call.

Cursor snapshot retention is bounded in two dimensions: at most 4 snapshots and at most 32 MiB of retained summary bytes, with at most 128 cursor entries. The byte budget equals the existing REPORT scan budget, so a result set that the scan budget admitted always fits and pagination never fails for size alone. A snapshot is evicted only with every entry that points into it, so an evicted generation cannot silently advance inside newer results. A token whose snapshot left the cache fails closed with a validation error and never rebases onto a later scan of the same filters. The codec refuses a result set that is empty or unordered, and then the walk ends without a token.

Snapshot semantics:

  • The snapshot is immutable. Contact edits, deletes, and new contacts that happen after the first page stay invisible to that walk; a new walk started with cursor=start observes them.
  • All pages of one walk share the snapshot deadline, so a page chain cannot extend the 5-minute lifetime.
  • A process restart drops every snapshot and every token. A later page of an interrupted walk fails closed with a validation error, and the caller restarts with cursor=start.
  • A scanLimitReached first page issues no token, because rows beyond the budget are not reachable. The same rule applies when the byte budget truncated the match set.
  • The cache is per registration and per process. Two sessions with different filters hold separate snapshots, and a scope change rejects the token.

Decoding a token reveals no contact name, UID, book, or filter value. Snapshot rows are never written to disk, never logged, and never placed in an error message. The retained set is a bounded search result, not an address-book mirror.

The complete bounded match set backs the 256 KiB MCP page budget. Each page reserves room for the token, and a page byte cut still points to the next unemitted row.

truncated means that the result count or byte limit removed matches. scanLimitReached means that the scan limit excluded selected cards or books. Narrow the book or filters when either field is true.

truncatedFields reports per-contact field completeness without exposing the omitted values. Each entry names a field (emails, phones, addresses, or urls), counts omitted items, and sets valueTruncated when one value reached its byte budget. matchedFieldOmitted is true when the search matched a raw value that the bounded output did not include, for example the eleventh email. These markers describe one contact. They are independent of truncated and scanLimitReached, which describe result and scan bounds.

Structured N, ADR, and ORG values decode escaped semicolons, commas, backslashes, and newlines before the client models them. An escaped semicolon stays inside its component instead of splitting the value. A patch preserves the original raw structured property byte for byte, and a targeted name or address edit escapes embedded separators before the conditional PUT.

Apple grouped properties keep their itemN association during a partial update. When an edited repeated value is byte-identical to an original grouped value, the client keeps that group and its itemN.X-ABLabel companion. When the value is removed, the client removes the group companion as well instead of leaving an orphan label. An ambiguous group-to-value correspondence fails before any PUT.

UID lookup uses the mandatory i;unicode-casemap equality filter, which is case-insensitive, then selects the single byte-exact UID locally. Distinct UIDs such as ClientA and clienta therefore resolve correctly. Duplicate exact UIDs, a truncated result, or a result with no exact match fail closed.

Create:

  • Generates a random .vcf child resource name independently of the contact UID.
  • Sends Content-Type: text/vcard; charset=utf-8 and If-None-Match: *.
  • Does not repeat PUT after a transport failure. An ambiguous transport outcome returns outcome_unknown with an instruction to read again.
  • Sends another GET after definitive success to obtain normalized data and a fresh ETag. If GET fails, create stays successful with resultIncomplete.

Update/delete:

  1. Query the exact UID and get the full returned resource.
  2. Require a usable specific strong server ETag.
  3. Use a valid caller ETag when supplied. Otherwise, use the GET ETag.
  4. Reject wildcard, weak, malformed, and missing ETags.
  5. Send a specific If-Match on every real PUT/DELETE.
  6. Map HTTP 412 to concurrent_modification.
  7. Re-GET after successful update for normalized data and ETag.

delete_contact dry run runs lookup and validation. It sends no DELETE. DAV no-uid-conflict, valid-address-data, and max-resource-size preconditions map to conflict, validation, and payload_too_large. Unknown or malformed preconditions map to protocol_error. Results never contain raw XML.

MCP update_contact can return a cached result for idempotency_key. This path sends no new CardDAV mutation. See the update idempotency contract.

Resource Limit
Address books 100
Search summaries 100, default 50
Cards scanned per search 2,000
Aggregate search REPORT 32 MiB
One vCard 1 MiB and 10,000 properties
PROPFIND response 8 MiB
DAV XML parser Depth 32; 100,000 tokens; 8,192 propstats; 16,384 properties
Serialized result 256 KiB
Query/email/phone 256/320/64 bytes
Display name/general text/notes 500/500/4,000 bytes
Emails/phones/URLs/addresses 10/10/5/5
Concurrent DAV requests 4
Read/write rates 60/20 per minute, bursts 10/3

To detect overflow, byte-limited reads read at most one byte above the limit. The client truncates remote names and fields only at valid UTF-8 boundaries. Truncation occurs only where the modeled read contract permits it.

The real-iCloud Contacts integration suite requires the integration build tag and ICLOUD_MCP_ENABLE_CONTACTS=true. It tests discovery, bounded search, and get.

A separate write gate controls its disposable CRUD fixture. The fixture tests general query matches through FN, N, EMAIL, and ORG. It also tests exact email search, digit-normalized phone search, UID lookup, update, and exact fixture cleanup.

The suite is optional and never runs in CI. It does not run without credentials.