get_current_date_time
Retrieve the current date and time in a standard format, optionally specifying a timezone for accurate local or global time display.
Instructions
Get the current date and time (e.g. 2025-01-01 01:01:01)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timezone | No |
Implementation Reference
- src/index.ts:97-109 (handler)The handler function for the 'get_current_date_time' tool. It uses dayjs to get the current date and time in the specified (or default) timezone, formats it using DEFAULT_TIME_FORMAT, and returns it as text content.async ({ timezone }) => { const currentDateTime = dayjs() .tz(getTZ(timezone)) .format(DEFAULT_TIME_FORMAT); return { content: [ { type: "text", text: currentDateTime, }, ], }; },
- src/index.ts:94-96 (schema)Input schema for the 'get_current_date_time' tool, defining an optional 'timezone' string parameter.{ timezone: z.string().optional(), },
- src/index.ts:91-110 (registration)Registration of the 'get_current_date_time' tool on the MCP server, including name, description, input schema, and handler function.server.tool( "get_current_date_time", "Get the current date and time (e.g. 2025-01-01 01:01:01)", { timezone: z.string().optional(), }, async ({ timezone }) => { const currentDateTime = dayjs() .tz(getTZ(timezone)) .format(DEFAULT_TIME_FORMAT); return { content: [ { type: "text", text: currentDateTime, }, ], }; }, );
- src/index.ts:13-15 (helper)Helper function 'getTZ' used by the handler to determine the timezone, defaulting to guessed timezone if not provided.const getTZ = (timezon?: string) => { return timezon || dayjs.tz.guess(); };
- src/index.ts:11-12 (helper)Constant defining the default time format string used in the handler.const DEFAULT_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";