Skip to main content
Glama

get-weather

Retrieve current weather conditions for any specified city to support planning and decision-making within ServiceNow workflows.

Instructions

Tool to get the weather of a city

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesThe name of the city to get the weather for

Implementation Reference

  • main.ts:43-59 (registration)
    Registration of the 'get-weather' tool using McpServer.tool, including name, description, input schema, and handler.
    server.tool( 'get-weather', 'Tool to get the weather of a city', { city: z.string().describe("The name of the city to get the weather for") }, async ({ city }) => { return { content: [ { type: "text", text: await getWeather({ city }) } ] } } );
  • main.ts:49-59 (handler)
    The MCP tool handler function that invokes the getWeather helper and returns formatted text content.
    async ({ city }) => { return { content: [ { type: "text", text: await getWeather({ city }) } ] } } );
  • main.ts:46-48 (schema)
    Zod input schema defining the 'city' parameter as a string.
    { city: z.string().describe("The name of the city to get the weather for") },
  • Helper function implementing the core weather fetching logic using Open-Meteo APIs for geocoding and forecast data.
    export default async ({ city }) => { try { const response = await fetch(`https://geocoding-api.open-meteo.com/v1/search?name=${city}&count=10&language=en&format=json`); const data = await response.json(); if (!data.results || data.results.length === 0) { return `No results found for city: ${city}`; } let firstResult = data.results[0]; const { latitude, longitude } = firstResult; //return `Coordinates for ${city}: Latitude: ${latitude}, Longitude: ${longitude}`; const weatherResponse = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&hourly=temperature_2m,precipitation,apparent_temperature,relative_humidity_2m&forecast_days=1`); if (!weatherResponse.ok) { return `Error fetching weather data: ${weatherResponse.statusText}`; } return `Weather data for ${city}:\n` + `Latitude: ${latitude}, Longitude: ${longitude}\n` + `Weather: ${JSON.stringify(await weatherResponse.json(), null, 2)}`; const weatherData = await weatherResponse.json(); return JSON.stringify(weatherData, null, 2); } catch (error) { return `Error fetching weather data: ${error.message}`; } }

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/jacebenson/ai-mcp-servicenow'

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