import { ToolMetadata, InferSchema } from "xmcp";
import { z } from "zod";
import { getCurrentWeather, temperatureUnitSchema } from "../lib/weather-api";
export const schema = {
city: z.string().describe("the name of the city you want to get the weather details"),
unit: temperatureUnitSchema.optional().describe("Temperature unit (default: celsius)"),
}
export const metadata: ToolMetadata = {
name: "get-current-weather",
description: "get the current weather of selected city",
annotations: {
// Human-readable title displayed in UIs
title: "Get current weather",
// true = tool only reads data, doesn't modify anything (safe to retry)
readOnlyHint: true,
// true = tool may perform destructive actions like deleting data
destructiveHint: false,
// true = calling multiple times with same args has no additional effect (doesn't change anything on the server or create duplicate records)
idempotentHint: true,
// true = tool interacts with external systems (APIs, databases)
openWorldHint: true,
},
}
export default async function getCurrentWeatherTool({ city, unit = "celsius" }: InferSchema<typeof schema>) {
const weather = await getCurrentWeather(city, unit);
return `Current weather in ${weather.city}, ${weather.country}:
• Temperature: ${weather.temperature}°${unit === "celsius" ? "C" : "F"}
• Humidity: ${weather.humidity}%
• Wind Speed: ${weather.windSpeed} km/h`;
}