Metadata-Version: 2.5
Name: langchain-dnsdoctor
Version: 0.6.4
Summary: LangChain tools for DNS Doctor: find out why a domain's email lands in spam, get the exact DNS record to fix it and check the change is live everywhere. SPF, DMARC, DKIM, MX, propagation, blacklists and expiry. Records come from dnsdoctor.dev's validating engine, never a guessed record.
Project-URL: Homepage, https://dnsdoctor.dev
Project-URL: Repository, https://github.com/dnsdoctor/langchain-dnsdoctor
Project-URL: API reference, https://dnsdoctor.dev/api/v1/docs
Project-URL: Changelog, https://github.com/dnsdoctor/langchain-dnsdoctor/releases
Author-email: DNS Doctor <hello@dnsdoctor.dev>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agent-tools,dkim,dmarc,dns,email-security,langchain,spf,x402
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Communications :: Email
Classifier: Topic :: Internet :: Name Service (DNS)
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: langchain-core<2,>=1.0
Provides-Extra: test
Requires-Dist: langchain-tests>=1.0; extra == 'test'
Requires-Dist: pytest-asyncio>=0.24; extra == 'test'
Requires-Dist: pytest>=8; extra == 'test'
Description-Content-Type: text/markdown

# langchain-dnsdoctor

[![PyPI](https://img.shields.io/pypi/v/langchain-dnsdoctor)](https://pypi.org/project/langchain-dnsdoctor/) [![Glama](https://glama.ai/mcp/servers/dnsdoctor/mcp/badges/score.svg)](https://glama.ai/mcp/servers/dnsdoctor/mcp) [![mcptry](https://mcptry.com/badge/dev.dnsdoctor/dns-doctor)](https://mcptry.com/servers/dev.dnsdoctor/dns-doctor) [![mcprush](https://mcprush.com/badge/dns-doctor-mcp/score.svg)](https://mcprush.com/to/dns-doctor-mcp?ref=badge)

**Get your domain's email working, and know it stays that way.** See why mail lands in spam, get the exact DNS record to fix it, and check the change is live everywhere.

LangChain tools for [DNS Doctor](https://dnsdoctor.dev): scan, diagnose and fix a domain's
email authentication (SPF, DMARC, DKIM), check a DNS change from six locations on four
continents, audit an SPF include chain, test how a real email authenticates, and read
monitoring alerts. Every verdict is
deterministic and every record comes from a validating engine, never from a language model.

Twenty-seven tools, the same set the hosted MCP server exposes. Tool names, descriptions and
input schemas are generated from that server and shipped in `tools.json`; this package
restates none of them.

## Install

```bash
pip install langchain-dnsdoctor
```

Python 3.10+, `langchain-core` 1.x. No API key is needed for the twenty anonymous tools.

## Use

```python
from langchain.agents import create_agent
from langchain_dnsdoctor import DnsDoctorToolkit

toolkit = DnsDoctorToolkit()
agent = create_agent(
    model="claude-sonnet-4-6",
    tools=toolkit.get_tools(),
    system_prompt=toolkit.instructions,
)
agent.invoke({"messages": [{"role": "user", "content": "Is example.com spoofable? Fix it."}]})
```

`toolkit.instructions` is the hosted server's own guidance and belongs in the system prompt:
present records verbatim, a `temperror` status is transient and not a failure,
`not_registered: true` is not health, SPF is diagnose-only, a human approves every DNS
change. Two tool descriptions are longer than OpenAI's 1024-character limit for function
descriptions; those are cut at a sentence boundary on the tool and carried in full in the
instructions.

A subset, or a single tool:

```python
from langchain_dnsdoctor import dnsdoctor_tools

scan, upgrade = dnsdoctor_tools(["scan_domain", "build_dmarc_upgrade"])
print(scan.invoke({"domain": "example.com"}))
```

## Tools

| Tool | What it answers |
| --- | --- |
| `scan_domain`, `get_report` | The full report: SPF, DKIM, DMARC, MX, DNS health, blacklists, domain and TLS expiry, with copy-paste fix records |
| `build_dmarc_upgrade`, `generate_dmarc_record`, `validate_dmarc_record` | The next safe DMARC rung for a domain, a record from scratch, or a check of one you have |
| `count_spf_lookups`, `audit_spf_includes` | The 10-lookup budget, and who can transitively send as the domain |
| `check_dkim_selector`, `check_record`, `check_reverse_dns`, `check_propagation` | One selector, one record, one IP, or whether a change has gone global |
| `parse_dmarc_report` | An aggregate report (XML, gzip or zip, base64-encoded) as a source table |
| `build_parked_domain_records` | The three records that stop a non-sending domain being spoofed |
| `lookup_registration` | Who a domain is registered with, when it expires, its nameservers and locks (RDAP) |
| `check_lookalikes` | Which close look-alike names of a domain resolve or accept mail (DNS-only facts, never a verdict) |
| `check_bimi` | Whether a domain can show its logo in the inbox (BIMI): eligibility per mailbox, never a promise, plus the engine's record for a candidate logo |
| `start_email_test`, `get_email_test` | How one real message authenticated: a single-use address to send to, then the SPF, DKIM, DMARC and blacklist verdicts and an itemized score |
| `start_monitoring_signup` | A signup link that carries the domain into paid monitoring, for a human to open |
| `get_alerts`, `get_readiness`, `get_lookalikes` | Monitoring reads: alerts, enforcement readiness, watched lookalikes with a threat %; need `DNSDOCTOR_API_TOKEN` |
| `add_monitored_domain`, `check_domain_verification`, `get_domain_records` | Add a domain to the account's monitoring and read the records it still needs; need `DNSDOCTOR_API_TOKEN` |
| `list_email_tests` | The account's recent email tests, newest first; needs `DNSDOCTOR_API_TOKEN` |
| `list_my_domains` | Every domain on the account with its state and next step; needs `DNSDOCTOR_API_TOKEN` |
| `check_domain_names` | Which of 1-20 candidate names the registry already holds (registered / not registered / unknown); premium status is not checked |
| `watch_record_change` | Reads one record and, on wait or edit, starts a free 48-hour watch that emails the token's account once when the change is finished; needs `DNSDOCTOR_API_TOKEN` |

## Environment

| Variable | Effect |
| --- | --- |
| `DNSDOCTOR_API_TOKEN` | Optional bearer token. Raises the anonymous rate limit and unlocks the eight account tools. Never prompted for. |
| `DNSDOCTOR_API_BASE` | Override the API origin (default `https://dnsdoctor.dev`). |

Past the free per-caller allowance the API answers `402` with an [x402](https://x402.org)
offer (USDC on Base). This package does not pay; the tool returns the offer text so an
agent with an x402 client can retry with payment, or wait.

## Rules the tools follow

- A transport failure (rate limit, 402, 503, 5xx, network) is returned as text that says it is
  not a verdict about the domain. It never raises.
- Responses are relayed byte-for-byte. The package composes no record and no URL.
- SPF is diagnose-only. The one SPF record the API ever emits is the constant `-all` inside the
  parked-domain pack, for a domain the server verified sends no mail.

## Development

```bash
pip install -e ".[test]"
pytest                      # unit tests, offline
pytest tests/integration_tests -m integration   # one live call against dnsdoctor.dev
```

Apache-2.0.
