Skip to main content
Glama
dhinojosac

TypeScript MCP Server Template

by dhinojosac

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)');

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