get_ssl_cert_info
Retrieve SSL certificate details including validity periods, issuer information, and expiration dates for website security monitoring by specifying a domain and port.
Instructions
Get SSL certificate information for a host and port.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| domain | Yes | The domain to check SSL certificate for (e.g., www.sslmon.dev) | |
| port | No | Port number to check (default: 443) |
Implementation Reference
- src/index.ts:390-465 (handler)Core handler function that performs TLS connection to the specified domain and port, retrieves the peer SSL certificate, extracts validity dates, issuer, subject, checks current validity, calculates days until expiry, and returns structured JSON info.private async checkSSLCertificate(domain: string, port: number = 443): Promise<any> { return new Promise((resolve) => { const options = { host: domain, port: port, servername: domain, }; const socket = tls.connect(options, () => { const cert = socket.getPeerCertificate(); if (!cert || Object.keys(cert).length === 0) { resolve({ content: [ { type: "text", text: `No SSL certificate found for ${domain}:${port}`, }, ], }); socket.end(); return; } const validFrom = new Date(cert.valid_from); const validTo = new Date(cert.valid_to); const now = new Date(); const isValid = now >= validFrom && now <= validTo; const daysUntilExpiry = Math.ceil((validTo.getTime() - now.getTime()) / (1000 * 60 * 60 * 24)); const sslInfo: SSLInfo = { domain, validFrom: validFrom.toISOString(), validTo: validTo.toISOString(), issuer: cert.issuer?.CN || 'Unknown', subject: cert.subject?.CN || domain, isValid, daysUntilExpiry, }; resolve({ content: [ { type: "text", text: JSON.stringify(sslInfo, null, 2), }, ], }); socket.end(); }); socket.on('error', (error) => { resolve({ content: [ { type: "text", text: `SSL connection failed for ${domain}:${port}: ${error.message}`, }, ], }); }); socket.setTimeout(10000, () => { socket.destroy(); resolve({ content: [ { type: "text", text: `SSL connection timeout for ${domain}:${port}`, }, ], }); }); }); }
- src/index.ts:77-97 (registration)MCP tool registration, including title, description, Zod input schema for domain and port, and async handler that delegates to checkSSLCertificate with error handling.server.registerTool( "get_ssl_cert_info", { title: "Get SSL cert info", description: "Get SSL certificate information for a host and port.", inputSchema: { domain: z.string().describe("The domain to check SSL certificate for (e.g., www.sslmon.dev)"), port: z.number().int().positive().default(443).describe("Port number to check (default: 443)"), }, }, async ({ domain, port = 443 }) => { try { return await this.checkSSLCertificate(domain, port); } catch (error) { return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true, }; } } );
- src/index.ts:25-32 (schema)TypeScript interface defining the structure of the SSL certificate information returned by the tool.domain: string; validFrom: string; validTo: string; issuer: string; subject: string; isValid: boolean; daysUntilExpiry: number; }