Skip to main content
Glama

get-weather-forecast

Retrieve weather forecasts by providing city names to access current conditions and predictions through structured API calls.

Instructions

根据经纬度获取天气信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityNo

Implementation Reference

  • The handler function that implements the core logic of the 'get-weather-forecast' tool. It constructs the API URL using the gaode endpoint and key, fetches the weather data for the given city, types it as Root, and returns a standardized content response with the JSON stringified data.
    async ({ city }) => { // 获取网格点数据的 URL const pointsUrl = `${gaode}?key=${key}&city=${city}`; const data: Root = await fetch(pointsUrl).then((response) => response.json(), ); return { content: [ { type: 'text', text: JSON.stringify(data), }, ], }; },
  • TypeScript interfaces defining the expected structure of the weather API response data, used for typing the 'data' variable in the handler.
    export interface Root { status: string; count: string; info: string; infocode: string; lives: Lfe[]; } export interface Lfe { province: string; city: string; adcode: string; weather: string; temperature: string; winddirection: string; windpower: string; humidity: string; reporttime: string; temperature_float: string; humidity_float: string; }
  • Zod validation schema for the tool's input parameters. Defines an optional 'city' string parameter.
    { city: z.string().optional(), }, // 工具的异步处理函数
  • src/index.ts:46-74 (registration)
    The MCP server.tool registration for the 'get-weather-forecast' tool, including name, description, input schema, and inline handler implementation.
    // 注册获取天气预报的工具 server.tool( // 工具名称 'get-weather-forecast', // 工具描述 '根据经纬度获取天气信息', // 工具参数 { city: z.string().optional(), }, // 工具的异步处理函数 async ({ city }) => { // 获取网格点数据的 URL const pointsUrl = `${gaode}?key=${key}&city=${city}`; const data: Root = await fetch(pointsUrl).then((response) => response.json(), ); return { content: [ { type: 'text', text: JSON.stringify(data), }, ], }; }, );
  • Constants defining the Amap (Gaode) weather API endpoint URL and the API key loaded from environment variables, used in the tool handler.
    const gaode = 'https://restapi.amap.com/v3/weather/weatherInfo'; const key = process.env.GAODE_KEY;

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

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