Skip to main content
Glama
bobbyyng

Weather MCP Server

by bobbyyng

get_current_weather

Retrieve real-time weather data for any specified location using the Weather MCP Server. Input a location name to fetch current conditions instantly.

Instructions

Get current weather information for a specified location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
locationYesLocation name (e.g., Hong Kong, Tokyo, London)

Implementation Reference

  • Core handler function that implements the get_current_weather tool logic: normalizes the input location, fetches mock weather data if available, or generates random data, and adds a current timestamp.
    async getCurrentWeather(location: string): Promise<WeatherData> {
      // Normalize location name using location mapping
      const normalizedLocation = this.normalizeLocation(location);
      
      if (mockWeatherData[normalizedLocation]) {
        return {
          ...mockWeatherData[normalizedLocation],
          timestamp: new Date().toISOString()
        };
      }
      
      // If location not found, return random weather data
      const randomData = getRandomWeatherData();
      return {
        ...randomData,
        location: location,
        timestamp: new Date().toISOString()
      };
    }
  • TypeScript interface defining the structure of the WeatherData returned by the get_current_weather tool.
    export interface WeatherData {
      location: string;
      temperature: number;
      humidity: number;
      windSpeed: number;
      windDirection: string;
      condition: string;
      description: string;
      pressure: number;
      visibility: number;
      uvIndex: number;
      timestamp: string;
    }
  • src/index.ts:38-51 (registration)
    Tool registration in the stdio MCP server (index.ts): defines name, description, and input schema for list tools response.
    {
      name: 'get_current_weather',
      description: 'Get current weather information for a specified location',
      inputSchema: {
        type: 'object',
        properties: {
          location: {
            type: 'string',
            description: 'Location name (e.g., Hong Kong, Tokyo, London)',
          },
        },
        required: ['location'],
      },
    },
  • src/index.ts:117-128 (registration)
    Tool call handler dispatch in stdio MCP server: handles 'get_current_weather' case by calling the weather service and formatting response.
    case 'get_current_weather': {
      const { location } = args as { location: string };
      const weather = await this.weatherService.getCurrentWeather(location);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(weather, null, 2),
          },
        ],
      };
    }
  • Helper method used by the handler to normalize location strings for lookup in mock data.
    private normalizeLocation(location: string): string {
      const lowerLocation = location.toLowerCase().trim();
      
      // Check if location exists in mapping
      if (locationMapping[lowerLocation]) {
        return locationMapping[lowerLocation];
      }
      
      // Fallback to original normalization
      return lowerLocation
        .replace(/\s+/g, '-')
        .replace(/[^a-z0-9-]/g, '');
    }
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/bobbyyng/weather-mcp-ts'

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