UNPKG

it-tools-mcp

Version:

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

69 lines (68 loc) 2.45 kB
import { z } from "zod"; export function registerConvertTemperature(server) { server.registerTool("convert_temperature", { description: "Convert temperatures between Celsius, Fahrenheit, and Kelvin", inputSchema: { temperature: z.number().describe("Temperature value to convert"), from: z.enum(["celsius", "fahrenheit", "kelvin"]).describe("Source temperature unit"), to: z.enum(["celsius", "fahrenheit", "kelvin"]).describe("Target temperature unit") }, // VS Code compliance annotations annotations: { title: "Convert Temperature", description: "Convert temperatures between Celsius, Fahrenheit, and Kelvin", readOnlyHint: false } }, async ({ temperature, from, to }) => { try { // Convert to Celsius first let celsius; switch (from) { case "celsius": celsius = temperature; break; case "fahrenheit": celsius = (temperature - 32) * 5 / 9; break; case "kelvin": celsius = temperature - 273.15; break; default: throw new Error("Invalid source unit"); } // Convert from Celsius to target unit let result; switch (to) { case "celsius": result = celsius; break; case "fahrenheit": result = celsius * 9 / 5 + 32; break; case "kelvin": result = celsius + 273.15; break; default: throw new Error("Invalid target unit"); } return { content: [ { type: "text", text: `${temperature}° ${from} = ${result.toFixed(2)}° ${to}` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error converting temperature: ${error instanceof Error ? error.message : 'Unknown error'}` } ] }; } }); }