get_current_time
Retrieve the current time in various formats and timezones for accurate timestamping and scheduling.
Instructions
what time|current time|time now|get time - Get current time
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Time format | |
| timezone | No | Timezone (e.g., America/New_York, Asia/Seoul) |
Implementation Reference
- src/tools/time/getCurrentTime.ts:22-69 (handler)The main handler function that executes the tool logic: computes current time based on optional format ('iso', 'local', 'utc', 'timestamp', 'human') and timezone parameters, formats it accordingly, and returns a ToolResult with the time information.export async function getCurrentTime(args: { format?: string; timezone?: string }): Promise<ToolResult> { const { format = 'iso', timezone } = args; const now = new Date(); let timeResult: string; switch (format) { case 'iso': timeResult = now.toISOString(); break; case 'local': timeResult = now.toLocaleString(); break; case 'utc': timeResult = now.toUTCString(); break; case 'timestamp': timeResult = Math.floor(now.getTime() / 1000).toString(); break; case 'human': const options: Intl.DateTimeFormatOptions = { year: 'numeric', month: 'long', day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: timezone }; timeResult = now.toLocaleString('en-US', options); break; default: timeResult = now.toISOString(); } const currentTimeResult = { action: 'get_current_time', format, timezone: timezone || 'local', result: timeResult, timestamp: now.getTime(), status: 'success' }; return { content: [{ type: 'text', text: `Time: ${timeResult}\nFormat: ${format}\nTimezone: ${timezone || 'local'}\nTimestamp: ${now.getTime()}` }] }; }
- ToolDefinition object defining the tool's name, description, input schema (format and timezone parameters), and annotations.export const getCurrentTimeDefinition: ToolDefinition = { name: 'get_current_time', description: 'what time|current time|time now|get time - Get current time', inputSchema: { type: 'object', properties: { format: { type: 'string', description: 'Time format', enum: ['iso', 'local', 'utc', 'timestamp', 'human'] }, timezone: { type: 'string', description: 'Timezone (e.g., America/New_York, Asia/Seoul)' } }, required: [] }, annotations: { title: 'Get Current Time', audience: ['user', 'assistant'] } };
- src/index.ts:106-106 (registration)Registers the tool definition in the 'tools' array used for listing available tools in MCP.getCurrentTimeDefinition,
- src/index.ts:606-607 (registration)Registers the handler dispatch in the executeToolCall switch statement, mapping 'get_current_time' calls to the getCurrentTime function.case 'get_current_time': return await getCurrentTime(args as any) as CallToolResult;