Skip to main content
Glama

Weather MCP Server

by alesanabv
main.ts1.72 kB
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { z } from "zod"; const server = new McpServer({ name: "weather", version: "1.0.0", }); function getWeatherCondition(temperature: number): string { if (temperature < 0) return "freezing ❄️"; if (temperature < 10) return "cold 🥶"; if (temperature < 15) return "cool 🌤️"; if (temperature < 20) return "mild 😊"; if (temperature < 25) return "warm ☀️"; if (temperature < 30) return "hot 🔥"; return "very hot 🌡️"; } server.tool( 'fetch-Weather', 'Get the weather for a given location', { city: z.string().describe("city name like 'Bogotá'") }, async (params) => { const info = await fetch(`https://geocoding-api.open-meteo.com/v1/search?name=${params.city}`); const data = await info.json(); const latitude = data.results[0].latitude; const longitude = data.results[0].longitude; const weather = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current_weather=true`); const weatherData = await weather.json(); const temperature = weatherData.current_weather.temperature; const condition = getWeatherCondition(temperature); return { content: [ { type: "text", text: `The weather in ${params.city} is ${condition} with a temperature of ${temperature}°C`, } ] } } ); const transport = new StdioServerTransport(); await server.connect(transport);

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/alesanabv/mcpWeather'

If you have feedback or need assistance with the MCP directory API, please join our Discord server