get_current_time
Retrieve the current date and time with timezone support and formatting options for accurate temporal information.
Instructions
Get the current date and time
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_current_time"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timezone | No | Timezone (optional, defaults to system timezone) | system |
| format | No | Time format: "12hour", "24hour", or "iso" (default: 12hour) | 12hour |
Implementation Reference
- src/index.ts:111-155 (handler)The handler logic for the 'get_current_time' tool, which retrieves the current date and time, applies optional timezone and format parameters, and returns a formatted text response.
if (name === 'get_current_time') { const timezone = args?.timezone || 'system'; const format = args?.format || '12hour'; log('INFO', `Getting current time - timezone: ${timezone}, format: ${format}`); const now = new Date(); let timeString: string; if (timezone !== 'system') { // For specific timezone const options: Intl.DateTimeFormatOptions = { timeZone: timezone as string, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: format === '12hour' }; timeString = now.toLocaleString('en-US', options); } else { // System timezone if (format === 'iso') { timeString = now.toISOString(); } else if (format === '24hour') { timeString = now.toLocaleString('en-US', { hour12: false }); } else { timeString = now.toLocaleString('en-US', { hour12: true }); } } const result = { content: [ { type: 'text', text: `Current time: ${timeString}`, }, ], }; log('INFO', `Returning time: ${timeString}`); return result; } - src/index.ts:62-82 (registration)Registration of the 'get_current_time' tool in the tools/list response, including its description and input schema definition.
{ name: 'get_current_time', description: 'Get the current date and time', inputSchema: { type: 'object', properties: { timezone: { type: 'string', description: 'Timezone (optional, defaults to system timezone)', default: 'system' }, format: { type: 'string', description: 'Time format: "12hour", "24hour", or "iso" (default: 12hour)', enum: ['12hour', '24hour', 'iso'], default: '12hour' } }, additionalProperties: false, }, },