We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/pepedd864/agent-sense'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
import { getLocationInfo } from "./location.js";
export async function getWeatherInfo(
city?: string,
includeForecast: boolean = false
) {
try {
// 获取坐标
let lat: number, lon: number, locationName: string;
if (!city) {
const location = await getLocationInfo();
lat = location.latitude;
lon = location.longitude;
locationName = location.city || location.region || "当前位置";
} else {
const geoUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(city)}&count=1&language=zh`;
const geoRes = await fetch(geoUrl);
const geoData: any = await geoRes.json();
if (!geoData.results?.[0]) {
throw new Error(`未找到城市: ${city}`);
}
lat = geoData.results[0].latitude;
lon = geoData.results[0].longitude;
locationName = geoData.results[0].name;
}
// 获取天气
const params = new URLSearchParams({
latitude: lat.toString(),
longitude: lon.toString(),
current: "temperature_2m,apparent_temperature,relative_humidity_2m,weather_code,wind_speed_10m,wind_direction_10m",
timezone: "auto",
});
if (includeForecast) {
params.append("daily", "weather_code,temperature_2m_max,temperature_2m_min");
params.append("forecast_days", "7");
}
const weatherRes = await fetch(`https://api.open-meteo.com/v1/forecast?${params}`);
const data: any = await weatherRes.json();
const result: any = {
location: locationName,
temperature: Math.round(data.current.temperature_2m),
feelsLike: Math.round(data.current.apparent_temperature),
humidity: data.current.relative_humidity_2m,
windSpeed: Math.round(data.current.wind_speed_10m),
description: getWeatherDesc(data.current.weather_code),
icon: getWeatherIcon(data.current.weather_code),
};
if (includeForecast && data.daily) {
result.forecast = data.daily.time.map((date: string, i: number) => ({
date,
tempMax: Math.round(data.daily.temperature_2m_max[i]),
tempMin: Math.round(data.daily.temperature_2m_min[i]),
description: getWeatherDesc(data.daily.weather_code[i]),
}));
}
return result;
} catch (error) {
throw new Error(`获取天气失败: ${error instanceof Error ? error.message : String(error)}`);
}
}
function getWeatherDesc(code: number): string {
const map: Record<number, string> = {
0: "晴", 1: "晴", 2: "多云", 3: "阴",
45: "雾", 48: "雾", 51: "小雨", 53: "小雨", 55: "小雨",
61: "雨", 63: "中雨", 65: "大雨",
71: "小雪", 73: "中雪", 75: "大雪",
80: "阵雨", 81: "阵雨", 82: "暴雨",
95: "雷暴", 96: "雷暴", 99: "雷暴",
};
return map[code] || "未知";
}
function getWeatherIcon(code: number): string {
if (code === 0) return "☀️";
if (code <= 3) return "⛅";
if (code <= 48) return "🌫️";
if (code <= 67) return "🌧️";
if (code <= 77) return "🌨️";
if (code <= 82) return "🌧️";
if (code <= 86) return "🌨️";
return "⛈️";
}