UNPKG

it-tools-mcp

Version:

Full MCP 2025-06-18 compliant server with 121+ IT tools, logging, ping, progress tracking, cancellation, and sampling utilities

65 lines (64 loc) 2.38 kB
import { z } from "zod"; export function registerUnixTimestampConverter(server) { server.registerTool("convert_unix_timestamp", { description: "Convert between Unix timestamps and human-readable dates", inputSchema: { input: z.string().describe("Unix timestamp (seconds) or ISO date string") }, // VS Code compliance annotations annotations: { title: "Unix-timestamp-converter", description: "Convert between Unix timestamps and human-readable dates", readOnlyHint: false } }, async ({ input }) => { try { // Auto-detect if input is a timestamp or date string const isTimestamp = /^\d+$/.test(input.trim()); if (isTimestamp) { // Convert timestamp to date const timestamp = parseInt(input); if (isNaN(timestamp)) { throw new Error("Invalid timestamp"); } const date = new Date(timestamp * 1000); const iso = date.toISOString(); const local = date.toLocaleString(); return { content: [ { type: "text", text: `Timestamp: ${timestamp}\nISO Date: ${iso}\nLocal Date: ${local}` } ] }; } else { // Convert date string to timestamp const date = new Date(input); if (isNaN(date.getTime())) { throw new Error("Invalid date string"); } const timestamp = Math.floor(date.getTime() / 1000); return { content: [ { type: "text", text: `Date: ${input}\nUnix Timestamp: ${timestamp}` } ] }; } } catch (error) { return { content: [ { type: "text", text: `Error converting timestamp: ${error instanceof Error ? error.message : 'Unknown error'}` } ] }; } }); }