Managing Contacts via API and MCP

This guide explains Create, import, export, search, and organize contacts and groups in TrekMail through the message API and MCP tools — endpoints, scopes, and pagination. so you can complete the TrekMail task with confidence.

Article details

Type, difficulty, plans, and last updated info.

Type
Reference
Difficulty
Intermediate
Plans
Starter · Pro · Agency
Last updated
Jul 11, 2026

Your mailbox's address book is fully programmable. The message API and the MCP tools expose everything the webmail Contacts panel can do — create, edit, and delete contacts, import and export in bulk (CSV or vCard), search, page through a large address book, and organize people into groups. This is the same data your webmail and CardDAV clients see, so a contact added by an AI agent shows up on your phone, and one you added on your phone is visible to the API.

Before you start

  • Contacts use the message token surface (/api/v1/messages/...), authorized by a message token with the scopes below — not a dashboard API token.
  • Every call is scoped to the token's own mailbox. A token can only see and manage its own contacts and groups — never another mailbox's.
  • Contacts are keyed by email address within a mailbox. Importing or creating a contact whose email already exists updates that contact rather than making a duplicate.
  • List responses return a clean, human-readable set of fields (name, email, company, job title, phone, address, birthday, notes). The raw CardDAV card behind a synced contact is never returned — you always get the tidy version.
  • Import accepts CSV and vCard (.vcf) files up to 10 MB, and understands the export formats of Google Contacts, Outlook, Apple, and Roundcube (including UTF-8/UTF-16 and BOM quirks).

Scopes

Scope What it does
messages:read List and search contacts, list groups and their members, export
messages:write Create, update, delete, import contacts; create and manage groups

Managing contacts

Base path: /api/v1/messages/contacts

Method Path Scope Purpose
GET /contacts messages:read List contacts, with search and pagination
POST /contacts messages:write Create a contact
PATCH /contacts/{id} messages:write Update a contact
DELETE /contacts/{id} messages:write Delete a contact
POST /contacts/import messages:write Bulk-import a CSV or vCard file
GET /contacts/export messages:read Export all contacts as CSV or vCard

List and search

GET /api/v1/messages/contacts?q=alice&per_page=50&page=1
Scope: messages:read

q matches on name or email. Results come back paged (per_page 1–100, default 50) with a pagination block (total, per_page, current_page, last_page) so you can walk a large address book to the end instead of stopping at the first page.

Create a contact

POST /api/v1/messages/contacts
Scope: messages:write
{
  "email": "ada@example.com",
  "name": "Ada Lovelace",
  "company": "Analytical Engines",
  "job_title": "Mathematician",
  "phone": "+1 555 0100",
  "address": "London",
  "birthday": "1815-12-10",
  "notes": "Met at the conference"
}

Only email is required. If a contact with that email already exists, the existing one is returned unchanged — creation never makes a duplicate.

Import in bulk

POST /api/v1/messages/contacts/import
Scope: messages:write
{
  "content_base64": "<base64 of your .csv or .vcf file>",
  "format": "csv"
}

Send the file base64-encoded with format set to csv or vcf (max 10 MB decoded). The response tells you how many rows were applied and how many were skipped for lacking a usable email:

{ "imported": 128, "skipped": 3 }

Column headers from Google, Outlook, Apple, and Roundcube exports are recognized automatically, so most exports import without any editing.

Export

GET /api/v1/messages/contacts/export?format=vcard
Scope: messages:read

Returns the whole address book as a single file, base64-encoded:

{ "format": "vcard", "content_base64": "..." }

Use format=csv for a spreadsheet-friendly file or format=vcard for a .vcf you can load into another mail client.

Contact groups

Groups are distribution lists inside the address book. Base path: /api/v1/messages/contact-groups

Method Path Scope Purpose
GET /contact-groups messages:read List groups (each with its contact_count)
POST /contact-groups messages:write Create a group
PATCH /contact-groups/{id} messages:write Rename a group
DELETE /contact-groups/{id} messages:write Delete a group
GET /contact-groups/{id}/members messages:read List the contacts in a group
POST /contact-groups/{id}/members messages:write Add contacts to a group
DELETE /contact-groups/{id}/members messages:write Remove contacts from a group

List who is in a group

GET /api/v1/messages/contact-groups/42/members?per_page=50&page=1
Scope: messages:read

Returns the group's contacts (same tidy fields as the contacts list) plus a pagination block and the group's total contact_count, so you can read a group's membership, not just change it blindly.

Add or remove members

POST /api/v1/messages/contact-groups/42/members
Scope: messages:write
{ "contact_ids": [11, 12, 13] }

Adding is idempotent — a contact already in the group is left as-is. Only contacts that belong to the same mailbox can be added.

MCP tools

The same address book is available to AI agents over MCP (both the private stdio server and the public MCP server):

Tool Scope Purpose
list_contacts read List and search contacts (paged)
create_contact write Create a contact
update_contact write Update a contact
delete_contact write Delete a contact
import_contacts write Import a CSV/vCard file (base64)
export_contacts read Export all contacts as CSV/vCard
list_contact_groups read List groups with member counts
list_contact_group_members read List the contacts in a group
create_contact_group write Create a group
update_contact_group write Rename a group
delete_contact_group write Delete a group
add_contact_group_members write Add contacts to a group
remove_contact_group_members write Remove contacts from a group

Write tools follow the same safety posture as the rest of the MCP server: they run only when destructive operations are enabled on the server, so an agent can browse your contacts freely but can't change them unless you've allowed it.

Related articles

Jump to nearby guides that continue the workflow.

We use cookies for essential functionality. No ads, no ad tracking.

Sign in to TrekMail

Access your dashboard, mailboxes and DNS.

or
or

Reset email sent

If an account exists for this email, we've sent password reset instructions.

By continuing, you agree to TrekMail's Terms and Privacy Policy.