get_current_date_time
Retrieve the current date and time in a specified timezone for accurate timestamping and time-based calculations with the 'Time Tools MCP Server'.
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)Handler function that retrieves the current date and time in the specified (or default) timezone using dayjs, formats it with 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 tool, defining an optional 'timezone' string parameter validated with Zod.{ 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 inline 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 to determine the timezone, using provided value or guessing with dayjs.tz.guess(). Used by the tool handler.const getTZ = (timezon?: string) => { return timezon || dayjs.tz.guess(); };