# add_custom_domain

Source: https://modulify.ai/docs/mcp/domains/add-custom-domain

Adds a custom domain to a site, alongside any it already has.

- Title: Add a custom domain
- Scope: `config:write`
- Access: Destructive

A site can have up to 10 custom domains, and each one serves the same site alongside the others. Adding one requires a paid plan and the **Manage domains** permission, and is refused on a free workspace.

Pass a bare hostname. A value with `http://` or `https://`, a path, or fewer than 4 or more than 253 characters is refused with the same messages as the **Custom Domain** field, and so is a Modulify address. A domain longer than 230 characters is refused with `example.com is too long for the TXT record that proves you own it, so it cannot be added!`, because the name of its TXT record would not fit in DNS. A hostname belongs to one site only. A domain this site already has is refused, and so is one another site in this workspace has, with that site's name in the message, so remove it there first. Any domain is refused once the site has 10.

For a root domain the www companion is added too, unless that www hostname is already on this site or on another site in this workspace, and passing `www.example.com` adds `example.com` with `www.example.com` as its companion. When the domain it adds, or the companion added with it, is the domain waiting on verification, that pending verification is cleared.

The answer carries the new `domainId` and the full `domains` list. Adding does not make the domain live: read the records to add with `get_domain_status`, then call it again once they are in place, because that call re-checks DNS and flips the domain to connected.

Every new domain needs proof that you own it before it serves the site. It is added with `Verified` false, and the records `get_domain_status` lists for it include a TXT record at `_modulify-verification.<domain>`. It connects once that record and the others are in place, and a domain still unverified 14 days after it was added, or after `get_domain_status` last checked it, is removed on its own. A domain the workspace bought on its **Domains** page, or one a site in this workspace had verified and gave up in the last 30 days, starts verified and needs no TXT record. Adding a domain the site already has, while it still waits on its TXT record, verifies it when the workspace bought it or the record is in place, with `example.com was already on this site, and its ownership is now verified.`, and is refused otherwise. See [The ownership record](https://modulify.ai/docs/publish/custom-domains#the-ownership-record).

When a site in another workspace has the domain, as a domain or as its www companion, nothing is added yet. The answer carries `domainId` as `null` and a `verification` object with `domain`, `verificationTxtName`, `verificationTxtValue` and `reason`, which is `in-use`, and the domain becomes the site's pending verification. `verificationTxtName` is the full DNS name, such as `_modulify-verification.example.com`, while many DNS hosts expect only `_modulify-verification`, so the tool tells the client to say which form your host wants and never to let the zone appear twice. Add that TXT record at your DNS host, then call `verify_domain`, which adds the domain and moves it off the other site. Calling this again for the same domain keeps the same record, and once the other site has let the domain go, it adds the domain with that same record. Adding a domain the workspace bought on its **Domains** page takes it off a site in another workspace that has it, without a TXT record. See [One site per domain](https://modulify.ai/docs/publish/custom-domains#one-site-per-domain).

When the workspace bought the domain on its **Domains** page and it uses Modulify's nameservers, Modulify adds those records by itself as part of this call and you add nothing, which `get_domain_status` shows as `OwnedDomain` with `ManagedDns` true. On such a domain, the A, AAAA, ANAME and CNAME records already at each hostname it adds are replaced, so whatever they pointed at, such as a site on another host, stops answering there. That is why the tool is marked destructive and tells the client to confirm with you first. While the registration of a domain the workspace bought is not confirmed yet, adding it, or a name under it, is refused with status `409` and `example.com is still being registered, so connect it once its registration is confirmed!` See [Records Modulify manages](https://modulify.ai/docs/publish/manage-dns#records-modulify-manages).

The site keeps serving its free address and its other domains throughout. See [Connect a custom domain](https://modulify.ai/docs/publish/custom-domains).

## Inputs

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `projectId` | string | Yes | The site id. |
| `domain` | string | Yes | The bare hostname to attach, for example `example.com`. |