Skip to main content
Glama
ctermiii

HeFeng Weather MCP Server

by ctermiii

get_datetime

Retrieve current date and time with an optional timezone parameter, defaulting to 'Asia/Shanghai'. Ideal for synchronizing timestamps in weather forecasts or applications requiring precise time data.

Instructions

获取当前的日期和时间。可以提供一个可选的时区参数,默认为 'Asia/Shanghai'。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timezoneNo可选的时区,例如 'America/New_York', 'Europe/London'。如果未提供,默认为 'Asia/Shanghai'。

Implementation Reference

  • Handler implementation for the 'get_datetime' tool. Parses input arguments using the schema, retrieves current date/time using JavaScript Date object adjusted for the specified timezone (defaults to 'Asia/Shanghai'), handles invalid timezone errors with fallback, and returns a formatted string response.
    } else if (name === "get_datetime") {
        const { timezone } = getDatetimeSchema.parse(args);
        const currentDateTime = new Date();
        let dateTimeString: string;
        const targetTimezone = timezone || 'Asia/Shanghai'; // Default to Asia/Shanghai
    
        try {
            // Use toLocaleString with options to get time in the target timezone
            dateTimeString = currentDateTime.toLocaleString('zh-CN', { timeZone: targetTimezone });
        } catch (error) {
            // Fallback to a known good default if specific timezone fails
            logger.warn(`无效的时区 "${targetTimezone}" 或格式化错误:`, error);
            const fallbackTimezone = 'Asia/Shanghai';
            dateTimeString = currentDateTime.toLocaleString('zh-CN', { timeZone: fallbackTimezone });
            dateTimeString += ` (无法识别提供的时区 "${timezone}", 已回退到 ${fallbackTimezone})`;
        }
    
        return {
            content: [{ type: "text", text: `当前日期时间 (${targetTimezone}): ${dateTimeString}` }],
        };
    }
  • Zod schema definition for the 'get_datetime' tool input: optional 'timezone' string parameter with description.
    const getDatetimeSchema = z.object({
        timezone: z.string().optional().describe("可选的时区,例如 'America/New_York', 'Europe/London'。如果未提供,默认为 'Asia/Shanghai'。"),
    });
  • src/index.ts:183-186 (registration)
    Registration of the 'get_datetime' tool within the 'tools' object, specifying its description and referencing the schema.
    get_datetime: {
        description: "获取当前的日期和时间。可以提供一个可选的时区参数(如 'America/New_York', 'Europe/London'),默认为 'Asia/Shanghai'。",
        schema: getDatetimeSchema,
    },
Install Server

Other Tools

Related 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/ctermiii/hefeng-mcp-server'

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