Skip to main content
Glama
dhinojosac

TypeScript MCP Server Template

by dhinojosac

Get Weather Alerts

getWeatherAlerts

Retrieve active weather alerts for US states to monitor severe conditions and plan accordingly.

Instructions

Get active weather alerts for a US state

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the getWeatherAlerts tool. Validates the state input using WeatherAlertsSchema, fetches simulated alerts, and returns formatted text response.
    async (args: { [x: string]: any }) => {
      const { state }: WeatherAlertsArgs = validateToolArgs(
        WeatherAlertsSchema,
        args
      );
    
      // Simulate alerts API call (replace with actual API)
      const alerts = await simulateAlertsAPI();
    
      return {
        content: [
          {
            type: 'text',
            text: `Weather alerts for ${state}:\n${alerts}`,
          },
        ],
      };
    }
  • Registration of the getWeatherAlerts MCP tool using server.registerTool, including metadata and handler reference.
    server.registerTool(
      'getWeatherAlerts',
      {
        title: 'Get Weather Alerts',
        description: 'Get active weather alerts for a US state',
      },
      async (args: { [x: string]: any }) => {
        const { state }: WeatherAlertsArgs = validateToolArgs(
          WeatherAlertsSchema,
          args
        );
    
        // Simulate alerts API call (replace with actual API)
        const alerts = await simulateAlertsAPI();
    
        return {
          content: [
            {
              type: 'text',
              text: `Weather alerts for ${state}:\n${alerts}`,
            },
          ],
        };
      }
    );
  • Zod schema defining the input structure for getWeatherAlerts: requires a 'state' field validated by StateSchema.
    export const WeatherAlertsSchema = z.object({
      state: StateSchema,
    });
  • Supporting function that simulates a weather alerts API call, generating mock active alerts or no alerts message.
    async function simulateAlertsAPI(): Promise<string> {
      // Simulate API delay
      await new Promise(resolve => setTimeout(resolve, 100));
    
      // Generate mock alerts based on state
      const alerts = [
        'Severe Thunderstorm Warning',
        'Flash Flood Watch',
        'Heat Advisory',
        'Winter Weather Advisory',
      ];
    
      const hasAlerts = Math.random() > 0.5;
    
      if (!hasAlerts) {
        return '✅ No active weather alerts for this state.';
      }
    
      const activeAlerts = alerts.filter(() => Math.random() > 0.7).slice(0, 2);
    
      if (activeAlerts.length === 0) {
        return '✅ No active weather alerts for this state.';
      }
    
      return activeAlerts.map(alert => `⚠️  ${alert}`).join('\n');
    }
  • Reusable StateSchema Zod validator used in WeatherAlertsSchema for two-letter uppercase US state codes.
    export const StateSchema = z
      .string()
      .length(2, 'State code must be exactly 2 characters')
      .regex(/^[A-Z]{2}$/, 'State code must be 2 uppercase letters')
      .describe('Two-letter US state code (e.g., CA, NY, TX)');
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 retrieves alerts but does not mention critical details like rate limits, authentication needs, error handling, or what constitutes an 'active' alert. This leaves significant gaps in understanding the tool's operational 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 purpose without unnecessary words. It is front-loaded and wastes no space, making it easy to parse quickly.

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 tool's complexity (retrieving dynamic data like weather alerts) and the absence of annotations and an output schema, the description is insufficient. It does not explain return values, error conditions, or behavioral constraints, leaving the agent with incomplete information for reliable use.

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 appropriately does not add parameter details, and it implicitly clarifies that no inputs are required by specifying 'for a US state' without listing parameters, which aligns with the schema.

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 action ('Get') and resource ('active weather alerts for a US state'), making the tool's purpose immediately understandable. However, it does not explicitly differentiate from sibling tools like 'getWeatherForecast', which might offer related but distinct functionality.

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, such as 'getWeatherForecast' or 'calculate'. It lacks context about prerequisites, exclusions, or specific scenarios where this tool is preferred, leaving usage decisions ambiguous.

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