QuestionQ23
AI in AutomationAn engineer needs to give an AI agent reverse-DNS capability so it can map IP addresses to hostnames when summarizing incidents. The engineer must implement a FastMCP tool that resolves PTR records with socket.gethostbyaddr and expose it through stdio for MCP clients. Construct the artifact by dragging the code snippets into the boxes. Not all options are used.
Drag & Drop
from mcp.server.fastmcp import import socket mcp = FastMCP("dns-tools") @mcp.() def reverse_dns(ip: str) -> str: """Return primary hostname for an IP address (PTR).""" try: name, _, _ = socket.gethostbyaddr(ip) return name except Exception as e: return f"lookup failed: {e}" if __name__ == "__main__": mcp.(="stdio")
Community Discussion