Skip to main content
Glama
dhinojosac

TypeScript MCP Server Template

by dhinojosac

Get Weather Forecast

getWeatherForecast

Retrieve weather forecast data for any location using geographic coordinates to support planning and decision-making.

Instructions

Get weather forecast for a specific location using coordinates

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the getWeatherForecast tool. Validates input arguments using WeatherForecastSchema and simulates a weather API call to return formatted forecast data.
    async (args: { [x: string]: any }) => {
      const { latitude, longitude }: WeatherForecastArgs = validateToolArgs(
        WeatherForecastSchema,
        args
      );
    
      // Simulate weather API call (replace with actual API)
      const forecast = await simulateWeatherAPI(latitude, longitude);
    
      return {
        content: [
          {
            type: 'text',
            text: `Weather forecast for coordinates (${latitude}, ${longitude}):\n${forecast}`,
          },
        ],
      };
    }
  • Zod schema defining the input parameters for getWeatherForecast: latitude and longitude numbers (referencing common schemas).
    export const WeatherForecastSchema = z.object({
      latitude: LatitudeSchema,
      longitude: LongitudeSchema,
    });
  • Tool registration call within registerWeatherTools function, including name, metadata, and inline handler. Called from src/server.ts.
    server.registerTool(
      'getWeatherForecast',
      {
        title: 'Get Weather Forecast',
        description:
          'Get weather forecast for a specific location using coordinates',
      },
      async (args: { [x: string]: any }) => {
        const { latitude, longitude }: WeatherForecastArgs = validateToolArgs(
          WeatherForecastSchema,
          args
        );
    
        // Simulate weather API call (replace with actual API)
        const forecast = await simulateWeatherAPI(latitude, longitude);
    
        return {
          content: [
            {
              type: 'text',
              text: `Weather forecast for coordinates (${latitude}, ${longitude}):\n${forecast}`,
            },
          ],
        };
      }
    );
  • Helper function simulating a weather API call, generating mock forecast data including temperature, conditions, and location info.
    async function simulateWeatherAPI(
      latitude: number,
      longitude: number
    ): Promise<string> {
      // Simulate API delay
      await new Promise(resolve => setTimeout(resolve, 100));
    
      // Generate mock forecast based on coordinates
      const temperature = Math.round(
        20 + latitude * 0.5 + (Math.random() * 10 - 5)
      );
      const conditions = ['Sunny', 'Cloudy', 'Rainy', 'Partly Cloudy'];
      const condition = conditions[Math.floor(Math.random() * conditions.length)];
    
      return `
    🌤️  Current Conditions: ${condition}
    🌡️  Temperature: ${temperature}°C
            Location: ${latitude.toFixed(4)}, ${longitude.toFixed(4)}
    ⏰ Updated: ${new Date().toLocaleString()}
      `.trim();
    }
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 the tool does but lacks details on traits such as rate limits, authentication needs, error handling, or what the forecast includes (e.g., time range, metrics). This leaves significant gaps in understanding the tool's behavior.

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 directly states the tool's function and input requirement without any wasted words. It is appropriately sized and front-loaded, making it easy for an agent to parse quickly.

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 moderate complexity (weather forecasting), lack of annotations, and no output schema, the description is minimally adequate. It covers the basic purpose and input but misses details like output format, error cases, or behavioral constraints, leaving room for improvement in completeness.

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

Parameters4/5

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

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description adds value by specifying that coordinates are required for location, which clarifies the input expectation beyond the empty schema, justifying a score above the baseline of 3.

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 tool's purpose with a specific verb ('Get') and resource ('weather forecast'), and specifies the required input ('for a specific location using coordinates'). However, it doesn't differentiate from sibling tools like 'getWeatherAlerts' or 'calculate', which would require explicit comparison to earn a 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 'getWeatherAlerts' or 'calculate'. It mentions the input requirement (coordinates) but offers no context about appropriate use cases, exclusions, or prerequisites, leaving the agent without usage direction.

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/dhinojosac/calendar-mcp'

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