1
---
2
name: namecheap
3
description: 'Manage DNS records for domains registered with Namecheap via their API. List domains, view/add/update/remove DNS host entries (A, AAAA, CNAME, MX, TXT, etc.), and guide users through API setup including public IP detection and credential configuration. Use when the user mentions Namecheap, DNS records, domain management, or wants to add/change/remove A records, CNAME records, MX records, or TXT records for their domains.'
4
---
5
6
# Namecheap DNS Management
7
8
**UTILITY SKILL** — manages DNS records via the Namecheap API.
9
USE FOR: "add DNS record", "update A record", "manage Namecheap domains", "set CNAME", "add MX record", "add TXT record", "list my domains", "show DNS records", "namecheap setup", "configure namecheap API", "what is my public IP"
10
DO NOT USE FOR: domain registration/purchase, SSL certificate management, hosting configuration, non-Namecheap DNS providers
11
12
## Workflow
13
14
### First-time Setup
15
16
Before executing any API commands, verify credentials are configured:
17
18
1. **Check for existing config** — look for `~/.namecheap-api`
19
2. If not configured, guide the user through setup:
20
a. **Show public IP** — run `python3 namecheap.py public-ip` to display the user's public IP
21
b. **Instruct IP whitelisting** — tell the user to go to https://ap.www.namecheap.com/settings/tools/apiaccess/, enable API (select ON), and whitelist the displayed IP
22
c. **Have the user run setup themselves** — ask the user to run `python3 namecheap.py setup` directly **in their own terminal**. The script prompts for the username and reads the API key with a hidden prompt (`getpass`), writes `~/.namecheap-api` with `chmod 600`, and validates the connection. **Never ask the user to paste their API key into the chat, and never log, echo, or display the API key value.** If you cannot run an interactive terminal for the user, instruct them to run `setup` themselves, or to export `NAMECHEAP_API_USER` and `NAMECHEAP_API_KEY` as environment variables in their own shell — rather than collecting the secret via `ask_user`.
23
d. **Confirm** — once the user reports setup succeeded, proceed with DNS operations.
24
25
### DNS Operations
26
27
Use the `namecheap.py` script (bundled in this skill's directory) for all API interactions. It requires only Python 3 (standard library only — no `pip install` needed) and works the same on macOS, Linux, and Windows:
28
29
```bash
30
# Show public IP (for setup)
31
python3 namecheap.py public-ip
32
33
# Run setup flow
34
python3 namecheap.py setup
35
36
# List domains
37
python3 namecheap.py domains.getList
38
39
# Get nameservers for a domain (shows if using Namecheap DNS or custom)
40
python3 namecheap.py domains.dns.getList --domain example.com
41
42
# Get DNS records for a domain
43
python3 namecheap.py domains.dns.getHosts --domain example.com
44
45
# Add a single record (preserves existing records)
46
python3 namecheap.py dns.addHost --domain example.com --type A --name www --address 1.2.3.4 --ttl 1800
47
48
# Remove a single record
49
python3 namecheap.py dns.removeHost --domain example.com --type A --name www --address 1.2.3.4
50
51
# Replace all records from a JSON file
52
python3 namecheap.py domains.dns.setHosts --domain example.com --hosts records.json
53
54
# Switch to Namecheap default DNS
55
python3 namecheap.py domains.dns.setDefault --domain example.com
56
57
# Switch to custom nameservers
58
python3 namecheap.py domains.dns.setCustom --domain example.com --nameservers ns1.cloudflare.com,ns2.cloudflare.com
59
60
# Get email forwarding rules
61
python3 namecheap.py domains.dns.getEmailForwarding --domain example.com
62
63
# Set email forwarding (single rule)
64
python3 namecheap.py domains.dns.setEmailForwarding --domain example.com --mailbox info --forward-to user@gmail.com
65
66
# Set email forwarding (from JSON file)
67
python3 namecheap.py domains.dns.setEmailForwarding --domain example.com --forwards forwards.json
68
69
# Create a child nameserver (glue record)
70
python3 namecheap.py domains.ns.create --domain example.com --nameserver ns1.example.com --ip 1.2.3.4
71
72
# Delete a child nameserver
73
python3 namecheap.py domains.ns.delete --domain example.com --nameserver ns1.example.com
74
75
# Get nameserver info
76
python3 namecheap.py domains.ns.getInfo --domain example.com --nameserver ns1.example.com
77
78
# Update nameserver IP
79
python3 namecheap.py domains.ns.update --domain example.com --nameserver ns1.example.com --old-ip 1.2.3.4 --ip 5.6.7.8
80
```
81
82
### JSON file formats
83
84
`domains.dns.setHosts --hosts records.json` expects an array of objects with Namecheap API field names:
85
86
```json
87
[
88
{ "HostName": "@", "RecordType": "A", "Address": "1.2.3.4", "TTL": 1800 },
89
{ "HostName": "www", "RecordType": "CNAME", "Address": "@", "TTL": 1800 },
90
{ "HostName": "@", "RecordType": "MX", "Address": "mail.example.com.", "TTL": 1800, "MXPref": 10 }
91
]
92
```
93
94
`domains.dns.setEmailForwarding --forwards forwards.json` expects an array of mailbox rules:
95
96
```json
97
[
98
{ "MailBox": "info", "ForwardTo": "team@example.net" },
99
{ "MailBox": "sales", "ForwardTo": "owner@example.net" }
100
]
101
```
102
103
## Behavior
104
105
- **Always check credentials first.** Before any API operation, verify `~/.namecheap-api` exists and is readable. If not, run the setup flow.
106
- **Show current records before modifying.** Before adding or removing records, always fetch and display the current DNS records so the user can confirm the change.
107
- **Use `ask_user` to confirm destructive changes.** Before removing records or replacing all records with `setHosts`, confirm with the user.
108
- **The Namecheap `setHosts` API replaces ALL records.** Never call `domains.dns.setHosts` directly unless you have fetched all existing records first. Use `dns.addHost` and `dns.removeHost` for safe single-record operations — they handle the fetch-modify-write cycle internally.
109
- **Explain TTL in human terms.** When the user asks about TTL, explain that 1800 = 30 minutes, 3600 = 1 hour, etc.
110
- **Handle multi-part TLDs.** Domains like `example.co.uk` have SLD=example and TLD=co.uk. The script recognizes a built-in list of common second-level suffixes (e.g. `co.uk`, `com.au`, `co.jp`, `com.br`). This list is best-effort and not a full public-suffix database — if a domain with an unlisted multi-part suffix returns a `2019166` ("Domain not found") error, the SLD/TLD split was likely wrong. In that case, confirm the registered domain with the user and report the limitation.
111
112
## Credential Storage
113
114
Credentials are stored in `~/.namecheap-api`:
115
116
```bash
117
NAMECHEAP_API_USER="username"
118
NAMECHEAP_API_KEY="api-key-here"
119
```
120
121
This file must have `600` permissions (owner read/write only). Alternatively, the script reads credentials from the `NAMECHEAP_API_USER` and `NAMECHEAP_API_KEY` environment variables, which take precedence over the file when both are set.
122
123
## Supported Record Types
124
125
A, AAAA, CNAME, MX, MXE, TXT, URL, URL301, FRAME
126
127
## References
128
129
See `references/namecheap-api.md` for full API documentation including request/response formats.
130