Skip to main content
Glama
bensinclair

Weather MCP Server

by bensinclair

getWeather

Retrieve current weather conditions for any city using the OpenWeatherMap API. Provide a city name to get temperature, humidity, and other weather data.

Instructions

Get current weather for a city

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesName of the city

Implementation Reference

  • index.js:12-41 (handler)
    Core handler logic for fetching weather data from OpenWeatherMap API, formatting response as MCP content, and handling errors.
    async getWeather(city) {
      if (!this.apiKey) {
        throw new Error('OPENWEATHER_API_KEY environment variable is not set');
      }
      
      try {
        const response = await axios.get(
          `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${this.apiKey}&units=metric`
        );
        const data = response.data;
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({
              city: data.name,
              temperature: data.main.temp,
              description: data.weather[0].description,
            }, null, 2),
          }],
        };
      } catch (error) {
        return {
          content: [{
            type: 'text',
            text: `Error: ${error.message}`,
          }],
          isError: true,
        };
      }
    }
  • index.js:52-57 (registration)
    Registers the 'getWeather' tool with the MCP server, including description, input schema, and an inline handler that delegates to WeatherService.getWeather.
    server.registerTool('getWeather', {
      description: 'Get current weather for a city',
      inputSchema: {
        city: z.string().describe('Name of the city'),
      },
    }, async ({ city }) => await weatherService.getWeather(city));
  • Zod input schema defining the 'city' parameter as a required string.
    inputSchema: {
      city: z.string().describe('Name of the city'),
    },
  • index.js:7-42 (helper)
    WeatherService class providing the getWeather method and managing the OpenWeather API key.
    class WeatherService {
      constructor(apiKey = process.env.OPENWEATHER_API_KEY) {
        this.apiKey = apiKey;
      }
    
      async getWeather(city) {
        if (!this.apiKey) {
          throw new Error('OPENWEATHER_API_KEY environment variable is not set');
        }
        
        try {
          const response = await axios.get(
            `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${this.apiKey}&units=metric`
          );
          const data = response.data;
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({
                city: data.name,
                temperature: data.main.temp,
                description: data.weather[0].description,
              }, null, 2),
            }],
          };
        } catch (error) {
          return {
            content: [{
              type: 'text',
              text: `Error: ${error.message}`,
            }],
            isError: true,
          };
        }
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool gets current weather but doesn't mention any behavioral traits like rate limits, authentication requirements, data freshness, error conditions, or response format. This leaves significant gaps for an agent to understand how to use it effectively.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise (5 words) and front-loaded with the essential information. Every word earns its place, and there's no wasted verbiage or unnecessary complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what weather data is returned, how current 'current' is, or any operational constraints. For a tool that presumably returns structured data, more context about the response would be helpful for an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the 'city' parameter clearly documented. The description doesn't add any meaningful parameter semantics beyond what the schema already provides, so it meets the baseline score of 3 for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('current weather for a city'), making the purpose immediately understandable. It doesn't need to distinguish from siblings since there are none, but it could be more specific about what weather data is returned (e.g., temperature, conditions).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or limitations. It simply states what the tool does without any context about appropriate usage scenarios or constraints.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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