get_current_time
Retrieve the current time in ISO8601 format, timestamp, and timezone. Customize output by including milliseconds and specifying the desired timezone for accurate time data.
Instructions
Get the current time with detailed information including ISO8601 format, timestamp, and timezone
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| includeMilliseconds | No | Include milliseconds in the ISO8601 format (default: true) | |
| timezone | No | Timezone for the time (default: UTC). Examples: "UTC", "America/New_York", "Asia/Tokyo" | UTC |
Implementation Reference
- src/infrastructure/mcp/time.server.ts:47-65 (registration)Registration of the 'get_current_time' MCP tool, including name, description, and input schema.{ name: 'get_current_time', description: 'Get the current time with detailed information including ISO8601 format, timestamp, and timezone', inputSchema: { type: 'object', properties: { includeMilliseconds: { type: 'boolean', description: 'Include milliseconds in the ISO8601 format (default: true)', default: true, }, timezone: { type: 'string', description: 'Timezone for the time (default: UTC). Examples: "UTC", "America/New_York", "Asia/Tokyo"', default: 'UTC', }, }, }, } as Tool,
- MCP tool handler: parses arguments, executes the getCurrentTimeUseCase, and returns formatted result or error.private async handleGetCurrentTime(args: unknown): Promise<CallToolResult> { const input = this.parseTimeArguments(args); const result = await this.dependencies.getCurrentTimeUseCase.execute(input); if (!result.success || !result.data) { return { content: [ { type: 'text', text: `Error: ${result.error || 'Failed to get current time'}`, } as TextContent, ], isError: true, }; } return { content: [ { type: 'text', text: JSON.stringify(result.data, null, 2), } as TextContent, ], }; }
- TypeScript interfaces defining the input schema, output structure, and use case contract for the tool.import type { ITimeData } from '../../shared/types/time.types.js'; export interface IGetCurrentTimeUseCaseInput { includeMilliseconds?: boolean; timezone?: string; } export interface IGetCurrentTimeUseCaseOutput { success: boolean; data?: ITimeData; error?: string; } export interface IGetCurrentTimeUseCase { execute(input?: IGetCurrentTimeUseCaseInput): Promise<IGetCurrentTimeUseCaseOutput>; }
- Use case helper: handles execution, input mapping to time service, and error handling.export class GetCurrentTimeUseCase implements IGetCurrentTimeUseCase { constructor(private readonly timeService: ITimeService) {} async execute(input?: IGetCurrentTimeUseCaseInput): Promise<IGetCurrentTimeUseCaseOutput> { try { const timeData = this.timeService.getCurrentTime({ includeMilliseconds: input?.includeMilliseconds, timezone: input?.timezone, }); return { success: true, data: timeData, }; } catch (error) { if (error instanceof TimeServiceError) { return { success: false, error: error.message, }; } return { success: false, error: 'An unexpected error occurred while retrieving the current time', }; } } }
- Core handler logic: retrieves current Date, formats ISO8601 string, computes timestamp and timezone.getCurrentTime(options?: ITimeFormatOptions): ITimeData { const mergedOptions = { ...this.defaultOptions, ...options }; const now = new Date(); return { iso8601: this.formatToISO8601(now, mergedOptions), timestamp: now.getTime(), timezone: mergedOptions.timezone || this.getTimeZone(), }; }