Skip to main content
Glama

get_weather

Retrieve current weather data including temperature, conditions, humidity, wind speed, and atmospheric pressure for any specified city worldwide.

Instructions

Get current weather for a city

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesName of the city to get weather for

Implementation Reference

  • index.js:85-113 (handler)
    The main handler function for the get_weather tool. It fetches current weather data for the given city using the OpenWeatherMap API via axios, formats the response as MCP content, and handles errors.
    async getWeather(city) { if (!API_KEY) { throw new Error("OpenWeatherMap API key not found. Set OPENWEATHER_API_KEY environment variable."); } try { const response = await axios.get( `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${API_KEY}&units=metric` ); const weather = response.data; return { content: [ { type: "text", text: `Weather in ${weather.name}, ${weather.sys.country}: Temperature: ${weather.main.temp}°C (feels like ${weather.main.feels_like}°C) Condition: ${weather.weather[0].description} Humidity: ${weather.main.humidity}% Wind: ${weather.wind.speed} m/s Pressure: ${weather.main.pressure} hPa`, }, ], }; } catch (error) { throw new Error(`Failed to get weather for ${city}: ${error.message}`); } }
  • The input schema for the get_weather tool, defining the required 'city' parameter as a string.
    inputSchema: { type: "object", properties: { city: { type: "string", description: "Name of the city to get weather for", }, }, required: ["city"], },
  • index.js:73-75 (registration)
    Dispatch logic in the CallToolRequest handler that routes 'get_weather' calls to the getWeather method.
    if (name === "get_weather") { return await this.getWeather(args.city); }
  • index.js:34-47 (registration)
    Tool registration in the ListToolsRequest handler, providing name, description, and schema.
    { name: "get_weather", description: "Get current weather for a city", inputSchema: { type: "object", properties: { city: { type: "string", description: "Name of the city to get weather for", }, }, required: ["city"], }, },

Other Tools

Latest Blog Posts

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/shtansky-bikeleasing/weather-mcp-server'

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