Skip to main content
Glama
carddav-contacts

carddav-contacts

by albertklein
README.md
# CardDAV Contacts (`carddav-contacts`)

A Cursor / Agent Plugin with an MCP server and skill for contacts on any CardDAV server. It can list address books, search contacts, and create, update, or delete them. Authentication is HTTP Basic (username plus password or, preferably, an app password).

Requires [Node.js](https://nodejs.org/) 18 or newer (uses global `fetch`). There are no runtime npm dependencies.

Repository: https://github.com/albertklein/carddav-plugin

## Install

### Cursor plugin

Clone this repository (or use it as a plugin repo in Cursor):

```sh
git clone https://github.com/albertklein/carddav-plugin.git
```

For a local Cursor install, copy or symlink the folder to `~/.cursor/plugins/local/carddav-contacts`, then restart Cursor. Set the three variables under **Plugins → Configure** (or at install time). Never put those values in the repo or in chat.

You can also point Cursor at this GitHub repository from a team marketplace (Teams or Enterprise): [Dashboard → Plugins & MCPs](https://cursor.com/dashboard/plugins).

The plugin manifest is `.cursor-plugin/plugin.json`. Cursor expands `${CURSOR_PLUGIN_ROOT}` in `mcp.json` to the plugin install path. It does not expand the Agent Plugins `${PLUGIN_ROOT}` placeholder. See the [Plugins reference](https://cursor.com/docs/reference/plugins).

### Plain `mcp.json`

If you install this as a Cursor plugin, the repo already ships this `mcp.json` (use it as-is):

```json
{
  "mcpServers": {
    "carddav": {
      "type": "stdio",
      "command": "node",
      "args": ["server/index.mjs"],
      "cwd": "${CURSOR_PLUGIN_ROOT}",
      "env": {
        "CARDDAV_URL": "${CARDDAV_URL}",
        "CARDDAV_USERNAME": "${CARDDAV_USERNAME}",
        "CARDDAV_PASSWORD": "${CARDDAV_PASSWORD}"
      }
    }
  }
}
```

For a manual user-level MCP config (`~/.cursor/mcp.json`) that is not loaded as a plugin, replace `${CURSOR_PLUGIN_ROOT}` with the absolute path to your local clone, and set the three `CARDDAV_*` values in that server's `env` (or in the environment of the process that starts Cursor). Do not commit real credentials.

## Variables

| Variable | Example | Notes |
| --- | --- | --- |
| `CARDDAV_URL` | `https://contacts.example.com/` | Base URL of the CardDAV server or an address book |
| `CARDDAV_USERNAME` | your account name or email | |
| `CARDDAV_PASSWORD` | an app-specific password | Secret. Prefer an app password you can revoke. |

The server discovers address books from the URL: it tries the URL, then `/.well-known/carddav`, then follows `current-user-principal` → `addressbook-home-set`. A URL that already points at an address book works too.

### App passwords

Use a dedicated app password (or equivalent) instead of your main account password. You can revoke it without changing the account password. Typical places to create one (UIs change, so check the provider's current help):

- **iCloud**: generate an app-specific password at [account.apple.com](https://account.apple.com); do not use your Apple ID password. URL `https://contacts.icloud.com/`. Username is your Apple ID email.
- **Fastmail**: create an app password with Contacts access. URL `https://carddav.fastmail.com/`.
- **Nextcloud**: Settings → Security → app password. URL `https://<host>/remote.php/dav/`. Username is your Nextcloud login.

## Usage

Once the MCP server is running, the agent can use these tools:

| Tool | What it does |
| --- | --- |
| `carddav_list_address_books` | Discover and list address books |
| `carddav_list_contacts` | List contacts, optionally filtered by `query` (name, org, email, phone) |
| `carddav_get_contact` | Get one contact by `href`, including the raw vCard |
| `carddav_create_contact` | Create a contact (`PUT` with `If-None-Match: *`) |
| `carddav_update_contact` | Patch fields of a contact (`PUT` with `If-Match: <etag>`), other vCard properties preserved |
| `carddav_delete_contact` | Delete a contact (`DELETE` with `If-Match: <etag>` when given) |

All tools return the same shape:

```ts
type Contact = {
  uid: string | null;
  fullName: string;
  emails: { value: string; type?: string }[];
  phones: { value: string; type?: string }[];
  org: string | null;
  etag: string | null;
  href: string;
  vcard?: string; // only on carddav_get_contact
};
```

Updates and deletes are protected by `etag`, so a stale copy is refused instead of overwriting a newer change. Fields the tools do not touch (addresses, notes, photos, and other vCard properties) are kept as they are.

Search downloads the address book and filters it locally, so it may be slow on very large address books.

## Tested servers

- **Radicale**: full create, read, update, and delete are covered by the local end-to-end suite (`test/e2e.mjs`).
- Other CardDAV servers (Nextcloud, iCloud, Fastmail, Baikal, SOGo, and similar) follow the same protocol. The provider URLs above are general guidance only; this plugin has not been verified against those hosted services in this repository.

## Layout

```
.cursor-plugin/plugin.json   Cursor Plugin manifest (name, variables schema)
.cursor-plugin/marketplace.json  Optional team marketplace catalog (plugin at repo root)
plugin.json                  Agent Plugins manifest
mcp.json                     stdio MCP server: node server/index.mjs  (cwd: ${CURSOR_PLUGIN_ROOT})
server/                      MCP server source
skills/carddav-contacts/     skill: which tool to use, safety rules
test/e2e.mjs                 end-to-end test against a local Radicale
test/e2e-remote.mjs          same CRUD steps against a real server (env credentials)
test/unit.mjs                unit tests for vCard/Contact functions
```

## Test

```sh
python3 -m venv .venv-radicale && .venv-radicale/bin/pip install radicale
node test/unit.mjs
node test/e2e.mjs          # starts a throwaway Radicale with a random test password
CARDDAV_URL=... CARDDAV_USERNAME=... CARDDAV_PASSWORD=... node test/e2e-remote.mjs
```

## License

MIT, copyright Albert Klein. See [LICENSE](LICENSE).