get-timezone-info.tool.tsβ’1.11 kB
import { Injectable } from '@nestjs/common'
import { Tool } from '@rekog/mcp-nest'
import { z } from 'zod'
import { TimezoneService } from '../../timezone/timezone.service'
@Injectable()
export class GetTimezoneInfoTool {
constructor(private readonly timezoneService: TimezoneService) {}
@Tool({
name: 'get_timezone_info',
description:
'Get the current date and time in a specific timezone with ISO 8601 formatted timestamps',
parameters: z.object({
region: z.string().describe('Timezone region (e.g., America, Europe, Asia)'),
city: z.string().describe('City or location name (e.g., New_York, London, Tokyo)'),
}),
})
async execute(params: { region: string; city: string }) {
const { region, city } = params
if (!region || !city) {
throw new Error('Region and city parameters are required')
}
const timezone = `${region}/${city}`
const timeInfo = this.timezoneService.getTimeInTimezone(timezone)
return {
content: [
{
type: 'text',
text: JSON.stringify(timeInfo),
},
],
}
}
}