Skip to main content
Glama
ampcome-mcps

Time MCP Server

by ampcome-mcps

convert_time

Convert specific datetime between IANA timezones using source and target timezone inputs for accurate timezone translation.

Instructions

Convert time between timezones.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceTimezoneYesThe source timezone. IANA timezone name, e.g. Asia/Shanghai
targetTimezoneYesThe target timezone. IANA timezone name, e.g. Europe/London
timeYesDate and time in 24-hour format. e.g. 2025-03-23 12:30:00

Implementation Reference

  • Core implementation of the time conversion logic between source and target timezones using dayjs timezone plugins. Parses input time (or current), converts, formats output, and computes hour difference.
    function convertTime(sourceTimezone: string, targetTimezone: string, time?: string) { const sourceTime = time ? dayjs(time).tz(sourceTimezone) : dayjs().tz(sourceTimezone); const targetTime = sourceTime.tz(targetTimezone); const formatString = 'YYYY-MM-DD HH:mm:ss'; return { sourceTime: sourceTime.format(formatString), targetTime: targetTime.format(formatString), timeDiff: dayjs(targetTime).diff(dayjs(sourceTime), 'hours'), }; }
  • Tool schema definition including name, description, and inputSchema with properties and requirements for convert_time.
    export const CONVERT_TIME: Tool = { name: 'convert_time', description: 'Convert time between timezones.', inputSchema: { type: 'object', properties: { sourceTimezone: { type: 'string', description: 'The source timezone. IANA timezone name, e.g. Asia/Shanghai', }, targetTimezone: { type: 'string', description: 'The target timezone. IANA timezone name, e.g. Europe/London', }, time: { type: 'string', description: 'Date and time in 24-hour format. e.g. 2025-03-23 12:30:00', }, }, required: ['sourceTimezone', 'targetTimezone', 'time'], }, };
  • src/index.ts:32-32 (registration)
    Registers CONVERT_TIME in the list of available tools returned by ListToolsRequestHandler.
    tools: [CURRENT_TIME, RELATIVE_TIME, DAYS_IN_MONTH, GET_TIMESTAMP, CONVERT_TIME, GET_WEEK_YEAR],
  • Dispatcher handler for callToolRequest 'convert_time': validates arguments, invokes convertTime function, and formats the response.
    case 'convert_time': { if (!checkConvertTimeArgs(args)) { throw new Error(`Invalid arguments for tool: [${name}]`); } const { sourceTimezone, targetTimezone, time } = args; const { sourceTime, targetTime, timeDiff } = convertTime(sourceTimezone, targetTimezone, time); return { success: true, content: [ { type: 'text', text: `Current time in ${sourceTimezone} is ${sourceTime}, and the time in ${targetTimezone} is ${targetTime}. The time difference is ${timeDiff} hours.`, }, ], }; }
  • Type guard function to validate input arguments for the convert_time tool.
    function checkConvertTimeArgs(args: unknown): args is { sourceTimezone: string, targetTimezone: string, time: string } { return ( typeof args === 'object' && args !== null && 'sourceTimezone' in args && typeof args.sourceTimezone === 'string' && 'targetTimezone' in args && typeof args.targetTimezone === 'string' && 'time' in args && typeof args.time === 'string' ); }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ampcome-mcps/time-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server