it-tools-mcp
Version:
MCP-compliant server access to over 100 IT tools and utilities commonly used by developers, system administrators, and IT professionals.
67 lines (66 loc) • 2.27 kB
JavaScript
import { z } from "zod";
export function registerConvertTemperature(server) {
server.registerTool("convert_temperature", {
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",
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'}`
}
]
};
}
});
}