Skip to main content
Glama

get-current-weather

Retrieve real-time weather data by specifying a city and country code. Integrates with the MCP Servers for accurate and instant weather updates using a straightforward API.

Instructions

Get current weather for a location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesCity name (e.g. Beijing, London)
countryNoCountry code (e.g. CN, GB)

Implementation Reference

  • Registration of the 'get-current-weather' MCP tool using server.tool(), including description, input schema, and handler function.
      "get-current-weather",
      "Get current weather for a location",
      {
        city: z.string().describe("City name (e.g. Beijing, London)"),
        country: z.string().optional().describe("Country code (e.g. CN, GB)")
      },
      async ({ city, country }) => {
        const weatherText = await weatherController.getCurrentWeather(city, country);
        return {
          content: [
            {
              type: "text",
              text: weatherText,
            },
          ],
        };
      }
    );
  • Zod schema for tool inputs: city (required string), country (optional string).
    {
      city: z.string().describe("City name (e.g. Beijing, London)"),
      country: z.string().optional().describe("Country code (e.g. CN, GB)")
    },
  • Inline handler function for the tool: extracts parameters, calls WeatherController.getCurrentWeather(), and returns formatted MCP content response.
    async ({ city, country }) => {
      const weatherText = await weatherController.getCurrentWeather(city, country);
      return {
        content: [
          {
            type: "text",
            text: weatherText,
          },
        ],
      };
    }
  • WeatherController.getCurrentWeather(): fetches raw weather data from service and formats it into a human-readable string with temperature, conditions, humidity, etc.
    async getCurrentWeather(city: string, country?: string): Promise<string> {
      const weatherData = await this.weatherService.getCurrentWeather(city, country);
    
      if (!weatherData) {
        return `Failed to retrieve weather data for ${country ? `${city}, ${country}` : city}`;
      }
    
      return [
        `Current weather in ${weatherData.name}, ${weatherData.sys.country}:`,
        `Temperature: ${weatherData.main.temp}°C (Feels like: ${weatherData.main.feels_like}°C)`,
        `Conditions: ${weatherData.weather[0].main} - ${weatherData.weather[0].description}`,
        `Humidity: ${weatherData.main.humidity}%`,
        `Wind Speed: ${weatherData.wind.speed} m/s`,
        `Pressure: ${weatherData.main.pressure} hPa`,
      ].join("\n");
    }
  • WeatherService.getCurrentWeather(): builds location query and calls makeRequest to fetch current weather data from OpenWeatherMap API.
    async getCurrentWeather(city: string, country?: string): Promise<WeatherData | null> {
      const query = country ? `${city},${country}` : city;
      return this.makeRequest<WeatherData>("weather", { q: query });
    }
Install Server

Other Tools

Related 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/fist-maestro/mcp-servers'

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