import { ToolMetadata, InferSchema } from "xmcp";
import { z } from "zod";
import { getCurrentWeather, temperatureUnitSchema } from "../lib/weather-api";
export const schema = {
city1: z.string().describe("First city to compare"),
city2: z.string().describe("Second city to compare"),
unit: temperatureUnitSchema.optional().describe("Temperature unit (default: celsius)"),
};
export const metadata: ToolMetadata = {
name: "compare-weather",
description: "Compare current weather between two cities",
annotations: {
title: "Compare Weather",
readOnlyHint: true,
destructiveHint: false,
idempotentHint: true,
openWorldHint: true,
},
};
export default async function compareWeather({ city1, city2, unit = "celsius" }: InferSchema<typeof schema>) {
const [weather1, weather2] = await Promise.all([
getCurrentWeather(city1, unit),
getCurrentWeather(city2, unit),
]);
const tempDiff = Math.abs(weather1.temperature - weather2.temperature).toFixed(1);
const unitSymbol = unit === "celsius" ? "C" : "F";
return `Weather Comparison:
📍 ${weather1.city}, ${weather1.country}
• Temperature: ${weather1.temperature}°${unitSymbol}
• Humidity: ${weather1.humidity}%
• Wind Speed: ${weather1.windSpeed} km/h
📍 ${weather2.city}, ${weather2.country}
• Temperature: ${weather2.temperature}°${unitSymbol}
• Humidity: ${weather2.humidity}%
• Wind Speed: ${weather2.windSpeed} km/h
📊 Difference: ${tempDiff}°${unitSymbol} (${weather1.temperature > weather2.temperature ? weather1.city : weather2.city} is warmer)`;
}