Skip to main content
Glama
dimonets

MCP Weather Server

by dimonets

get-air-quality

Retrieve air pollution data for any city, including European Air Quality Index and pollutant levels, to assess environmental conditions.

Instructions

Get air pollution data for any city including European Air Quality Index and pollutant levels

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYesThe name of the city to get air quality information for (e.g., 'New York', 'London', 'Tokyo')

Implementation Reference

  • main.ts:598-639 (handler)
    The MCP tool handler function. Calls getAirQualityForCity, handles result or error, and returns formatted MCP content (text error or JSON data).
    async({ city }) => {
      try {
        const result = await getAirQualityForCity(city);
        
        // If it's an error string, return it as text
        if (typeof result === 'string') {
          return {
            content: [
              {
                type: "text",
                text: result
              }
            ]
          };
        }
        
        // If it's processed data, return it as JSON string for structured access
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result, null, 2)
            }
          ]
        };
      } catch (error) {
        console.error('Air quality fetch error:', error);
        
        const errorMessage = error instanceof Error && error.message.includes('fetch') 
          ? `❌ Unable to fetch air quality data. Please check your internet connection and try again.`
          : `❌ Error: ${error instanceof Error ? error.message : 'Unknown error'}`;
        
        return {
          content: [
            {
              type: "text",
              text: errorMessage
            }
          ]
        };
      }
    }
  • Core helper function implementing the air quality tool logic: geocodes city, fetches current and hourly European AQI data from APIs, processes into structured format with location, current, hourly, and raw data.
    async function getAirQualityForCity(city: string): Promise<ProcessedAirQualityData | string> {
      // Step 1: Get coordinates for the city
      const geoUrl = `${CONFIG.GEOCODING_API}?name=${encodeURIComponent(city)}&count=1&language=en&format=json`;
      const geoResponse = await fetchWithRetry(geoUrl);
      const geoData: GeocodingResponse = await geoResponse.json();
    
      // Handle city not found
      if (!geoData.results || geoData.results.length === 0) {
        return `❌ Sorry, I couldn't find a city named "${city}". Please check the spelling and try again.`;
      }
    
      const location = geoData.results[0];
      
      // Step 2: Get air quality data
      const aqiUrl = `${CONFIG.AIR_QUALITY_API}?latitude=${location.latitude}&longitude=${location.longitude}&hourly=european_aqi,european_aqi_pm2_5,european_aqi_pm10,european_aqi_no2,european_aqi_o3,european_aqi_so2¤t=european_aqi,european_aqi_pm2_5,european_aqi_pm10,european_aqi_no2,european_aqi_o3,european_aqi_so2`;
      const aqiResponse = await fetchWithRetry(aqiUrl);
      const aqiData: AirQualityResponse = await aqiResponse.json();
    
      // Process and structure the air quality data
      const locationName = location.admin1 ? `${location.name}, ${location.admin1}, ${location.country}` : `${location.name}, ${location.country}`;
      const current = aqiData.current;
      const aqiInfo = getAqiLevel(current.european_aqi);
      
      const processedData: ProcessedAirQualityData = {
        location: {
          name: location.name,
          fullName: locationName,
          latitude: location.latitude,
          longitude: location.longitude,
          country: location.country,
          admin1: location.admin1
        },
        current: {
          time: current.time,
          formattedTime: formatTime(current.time),
          europeanAqi: current.european_aqi,
          aqiLevel: aqiInfo.level,
          aqiDescription: aqiInfo.description,
          pm25: current.european_aqi_pm2_5,
          pm10: current.european_aqi_pm10,
          no2: current.european_aqi_no2,
          o3: current.european_aqi_o3,
          so2: current.european_aqi_so2
        },
        hourly: aqiData.hourly.time.slice(0, 24).map((time, index) => {
          const aqi = aqiData.hourly.european_aqi[index];
          const aqiInfo = getAqiLevel(aqi);
          return {
            time: time,
            formattedTime: formatTime(time),
            europeanAqi: aqi,
            aqiLevel: aqiInfo.level,
            pm25: aqiData.hourly.european_aqi_pm2_5[index],
            pm10: aqiData.hourly.european_aqi_pm10[index],
            no2: aqiData.hourly.european_aqi_no2[index],
            o3: aqiData.hourly.european_aqi_o3[index],
            so2: aqiData.hourly.european_aqi_so2[index]
          };
        }),
        raw: aqiData
      };
    
      return processedData;
    }
  • main.ts:588-640 (registration)
    Registration of the 'get-air-quality' tool on the MCP server, specifying name, description, input schema, and handler.
    // Register the air quality tool
    server.tool(
      'get-air-quality',
      'Get air pollution data for any city including European Air Quality Index and pollutant levels',
      {
        city: z.string()
          .min(1, "City name cannot be empty")
          .max(100, "City name is too long")
          .describe("The name of the city to get air quality information for (e.g., 'New York', 'London', 'Tokyo')")
      },
      async({ city }) => {
        try {
          const result = await getAirQualityForCity(city);
          
          // If it's an error string, return it as text
          if (typeof result === 'string') {
            return {
              content: [
                {
                  type: "text",
                  text: result
                }
              ]
            };
          }
          
          // If it's processed data, return it as JSON string for structured access
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(result, null, 2)
              }
            ]
          };
        } catch (error) {
          console.error('Air quality fetch error:', error);
          
          const errorMessage = error instanceof Error && error.message.includes('fetch') 
            ? `❌ Unable to fetch air quality data. Please check your internet connection and try again.`
            : `❌ Error: ${error instanceof Error ? error.message : 'Unknown error'}`;
          
          return {
            content: [
              {
                type: "text",
                text: errorMessage
              }
            ]
          };
        }
      }
    );
  • Input schema using Zod for validating the 'city' parameter.
    {
      city: z.string()
        .min(1, "City name cannot be empty")
        .max(100, "City name is too long")
        .describe("The name of the city to get air quality information for (e.g., 'New York', 'London', 'Tokyo')")
    },
  • TypeScript interface defining the structure of processed air quality data returned by the tool.
    interface ProcessedAirQualityData {
      location: {
        name: string;
        fullName: string;
        latitude: number;
        longitude: number;
        country: string;
        admin1?: string;
      };
      current: {
        time: string;
        formattedTime: string;
        europeanAqi: number;
        aqiLevel: string;
        aqiDescription: string;
        pm25: number;
        pm10: number;
        no2: number;
        o3: number;
        so2: number;
      };
      hourly: Array<{
        time: string;
        formattedTime: string;
        europeanAqi: number;
        aqiLevel: string;
        pm25: number;
        pm10: number;
        no2: number;
        o3: number;
        so2: number;
      }>;
      raw: AirQualityResponse;
    }
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 what data is returned but doesn't cover critical aspects like rate limits, authentication needs, error handling, or data sources. For a tool with no annotations, this is a significant gap in transparency.

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 a single, efficient sentence that front-loads the core purpose. Every word earns its place, with no wasted text. It's appropriately sized for a simple tool with one parameter.

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

Completeness3/5

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

Given the tool's low complexity (1 parameter, no output schema, no annotations), the description is minimally adequate. It covers the purpose but lacks usage guidelines and behavioral details. Without annotations or output schema, it should do more to compensate, but the simplicity keeps it from being completely inadequate.

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 schema description coverage is 100%, with the city parameter well-documented in the schema. The description adds no additional parameter information beyond implying city scope. This meets the baseline of 3 since the schema does the heavy lifting, but the description doesn't compensate with extra context.

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 'air pollution data', specifying it includes 'European Air Quality Index and pollutant levels'. It distinguishes from sibling tools (get-forecast, get-weather) by focusing on pollution rather than weather. However, it doesn't explicitly mention the sibling differentiation, keeping it at 4 rather than 5.

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 like get-forecast or get-weather. It mentions 'any city' but doesn't specify limitations or prerequisites, such as city availability or data freshness. This leaves the agent without clear usage context.

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

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