cert_check
Check SSL certificate details including expiry date, issuer, and days remaining for a specified host.
Instructions
Check the SSL certificate on a host — expiry, issuer, days remaining.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host | Yes | ||
| port | No |
Implementation Reference
- src/mcp_nettools/server.py:83-107 (handler)The core handler function for the cert_check tool. It uses SSL/TLS to connect to a host, retrieves the peer certificate, and returns expiry date, issuer, subject, and days remaining.
@mcp.tool() def cert_check(host: str, port: int = 443) -> dict: """Check the SSL certificate on a host — expiry, issuer, days remaining.""" try: ctx = ssl.create_default_context() raw = socket.socket() raw.settimeout(10) with ctx.wrap_socket(raw, server_hostname=host) as s: s.connect((host, port)) cert = s.getpeercert() not_after = datetime.strptime(cert["notAfter"], "%b %d %H:%M:%S %Y %Z").replace( tzinfo=timezone.utc ) days_remaining = (not_after - datetime.now(timezone.utc)).days return { "host": host, "port": port, "subject": dict(x[0] for x in cert["subject"]), "issuer": dict(x[0] for x in cert["issuer"]), "expires": cert["notAfter"], "days_remaining": days_remaining, "valid": days_remaining > 0, } except Exception as e: return {"error": str(e), "tool": "cert_check", "host": host} - src/mcp_nettools/server.py:83-83 (registration)The @mcp.tool() decorator registers cert_check as an MCP tool with FastMCP.
@mcp.tool() - src/mcp_nettools/server.py:93-95 (helper)Helper logic to parse the certificate expiry date and compute days remaining until expiration.
not_after = datetime.strptime(cert["notAfter"], "%b %d %H:%M:%S %Y %Z").replace( tzinfo=timezone.utc )