From 3a677f3bc540d6b61e280e37de790a762e173d5b Mon Sep 17 00:00:00 2001 From: Ryan Malloy Date: Wed, 16 Jul 2025 19:02:46 -0600 Subject: [PATCH] Add DNS automation orchestration tool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Implement prepare_dns_automation tool that generates comprehensive DNS records - Tool creates structured DNS plan with CRITICAL, HIGH, MEDIUM, LOW priority records - Generates completion request for LLM to use its available DNS management MCP tools - Automatically generates DKIM keys if missing - Includes MX, A, SPF, DMARC, DKIM, autoconfig, autodiscover, and SRV records - Provides step-by-step automation instructions and verification commands - Version bump to 0.5.0 for major DNS automation feature This creates powerful orchestration where Mailu MCP generates the records and instructs the LLM to use other MCP tools (Cloudflare, Route53, etc.) to actually configure DNS - a brilliant multi-tool workflow\! Tool usage: prepare_dns_automation(domain="example.com", mail_server_ip="1.2.3.4") 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- pyproject.toml | 2 +- src/mcp_mailu/server.py | 194 ++++++++++++++++++++++++++++++++++++++++ uv.lock | 2 +- 3 files changed, 196 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ffd50fe..820836e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "mcp-mailu" -version = "0.4.2" +version = "0.5.0" description = "FastMCP server for Mailu email server API integration" authors = [ {name = "Ryan Malloy", email = "ryan@supported.systems"} diff --git a/src/mcp_mailu/server.py b/src/mcp_mailu/server.py index e0976a2..8d38304 100644 --- a/src/mcp_mailu/server.py +++ b/src/mcp_mailu/server.py @@ -879,6 +879,200 @@ def create_mcp_server() -> FastMCP: except Exception as e: return f"Error analyzing domain security: {e}" + # DNS Automation Tool - Orchestrates with LLM's other MCP tools + @mcp.tool() + async def prepare_dns_automation(domain: str, mail_server_ip: str = "", mail_server_hostname: str = "") -> str: + """Generate DNS records for domain and provide instructions for automated DNS configuration via other MCP tools.""" + try: + async with get_mailu_client() as mailu_client: + # Get domain info and generate DKIM if needed + domain_response = await mailu_client.get(f"/domain/{domain}") + if domain_response.status_code == 404: + return f"Domain {domain} not found in Mailu. Please create the domain first." + + domain_response.raise_for_status() + domain_data = domain_response.json() + + # Ensure DKIM keys exist + dkim_public_key = domain_data.get("dkim_public_key", "") + if not dkim_public_key: + # Generate DKIM keys + dkim_response = await mailu_client.post(f"/domain/{domain}/dkim") + dkim_response.raise_for_status() + + # Fetch updated domain data + domain_response = await mailu_client.get(f"/domain/{domain}") + domain_response.raise_for_status() + domain_data = domain_response.json() + dkim_public_key = domain_data.get("dkim_public_key", "") + + # Set defaults if not provided + if not mail_server_hostname: + mail_server_hostname = f"mail.{domain}" + if not mail_server_ip: + mail_server_ip = "YOUR_SERVER_IP_HERE" + + # Generate comprehensive DNS records + dns_automation_plan = { + "domain": domain, + "mail_server": { + "hostname": mail_server_hostname, + "ip": mail_server_ip + }, + "dns_records": [ + { + "type": "MX", + "name": domain, + "value": f"10 {mail_server_hostname}", + "priority": "CRITICAL", + "description": "Mail exchange record - required for email delivery" + }, + { + "type": "A", + "name": mail_server_hostname, + "value": mail_server_ip, + "priority": "CRITICAL", + "description": "IPv4 address for mail server hostname" + }, + { + "type": "TXT", + "name": domain, + "value": f"v=spf1 mx a:{mail_server_hostname} -all", + "priority": "HIGH", + "description": "SPF record - prevents email spoofing" + }, + { + "type": "TXT", + "name": f"_dmarc.{domain}", + "value": f"v=DMARC1; p=quarantine; rua=mailto:dmarc@{domain}; ruf=mailto:dmarc@{domain}; fo=1", + "priority": "HIGH", + "description": "DMARC policy - email authentication and reporting" + } + ], + "conditional_records": [ + { + "type": "TXT", + "name": f"dkim._domainkey.{domain}", + "value": dkim_public_key, + "priority": "HIGH", + "description": "DKIM public key - email authentication", + "condition": "DKIM key available" + } + ], + "optional_records": [ + { + "type": "CNAME", + "name": f"autoconfig.{domain}", + "value": mail_server_hostname, + "priority": "MEDIUM", + "description": "Email client auto-configuration (Thunderbird, etc.)" + }, + { + "type": "CNAME", + "name": f"autodiscover.{domain}", + "value": mail_server_hostname, + "priority": "MEDIUM", + "description": "Email client auto-discovery (Outlook, etc.)" + }, + { + "type": "SRV", + "name": f"_submission._tcp.{domain}", + "value": f"0 1 587 {mail_server_hostname}", + "priority": "LOW", + "description": "SMTP submission service record" + }, + { + "type": "SRV", + "name": f"_imaps._tcp.{domain}", + "value": f"0 1 993 {mail_server_hostname}", + "priority": "LOW", + "description": "IMAP over SSL service record" + } + ], + "automation_instructions": { + "overview": "Use your available DNS management MCP tools to configure these records", + "steps": [ + "1. Identify available DNS management tools (e.g., Cloudflare, Route53, etc.)", + "2. Start with CRITICAL priority records (MX and A records)", + "3. Add HIGH priority records (SPF, DMARC, DKIM)", + "4. Optionally add MEDIUM/LOW priority records for enhanced functionality", + "5. Verify DNS propagation using DNS lookup tools" + ], + "verification_commands": [ + f"dig MX {domain}", + f"dig TXT {domain}", + f"dig TXT _dmarc.{domain}", + f"dig TXT dkim._domainkey.{domain}" + ] + } + } + + # Add DKIM record to main records if available + if dkim_public_key: + dns_automation_plan["dns_records"].append({ + "type": "TXT", + "name": f"dkim._domainkey.{domain}", + "value": dkim_public_key, + "priority": "HIGH", + "description": "DKIM public key - email authentication signature" + }) + + # Create completion request for the LLM + completion_request = f""" +🚀 **DNS AUTOMATION REQUEST FOR {domain.upper()}** + +I have prepared the complete DNS configuration for the domain `{domain}`. Please use your available DNS management MCP tools to automatically configure these records. + +**CRITICAL RECORDS (Configure First):** +""" + + for record in dns_automation_plan["dns_records"]: + if record["priority"] == "CRITICAL": + completion_request += f"- **{record['type']}** `{record['name']}` → `{record['value']}`\n" + + completion_request += f""" +**HIGH PRIORITY RECORDS (Security):** +""" + + for record in dns_automation_plan["dns_records"]: + if record["priority"] == "HIGH": + completion_request += f"- **{record['type']}** `{record['name']}` → `{record['value']}`\n" + + completion_request += f""" +**OPTIONAL ENHANCEMENTS:** +""" + + for record in dns_automation_plan["optional_records"]: + completion_request += f"- **{record['type']}** `{record['name']}` → `{record['value']}` ({record['description']})\n" + + completion_request += f""" + +**AUTOMATION STEPS:** +1. Use your DNS management tools to create the above records +2. For each record, use the exact values provided +3. Verify the records are created successfully +4. Report back with the results + +**VERIFICATION:** +After creating records, please verify with: +- `dig MX {domain}` +- `dig TXT {domain}` (SPF) +- `dig TXT _dmarc.{domain}` (DMARC) +- `dig TXT dkim._domainkey.{domain}` (DKIM) + +Please proceed with the DNS automation using your available MCP tools! +""" + + # Return both the structured data and the completion request + return json.dumps({ + "dns_plan": dns_automation_plan, + "completion_request": completion_request, + "summary": f"Generated DNS automation plan for {domain} with {len(dns_automation_plan['dns_records'])} critical/high priority records and {len(dns_automation_plan['optional_records'])} optional enhancements" + }, indent=2) + + except Exception as e: + return f"Error preparing DNS automation: {e}" + logger.info("Created comprehensive MCP server with manual tools and resources") return mcp diff --git a/uv.lock b/uv.lock index 466cd52..e5db3bd 100644 --- a/uv.lock +++ b/uv.lock @@ -613,7 +613,7 @@ wheels = [ [[package]] name = "mcp-mailu" -version = "0.4.1" +version = "0.4.2" source = { editable = "." } dependencies = [ { name = "fastmcp" },