Skip to main content
Glama
ampcome-mcps

Time MCP Server

by ampcome-mcps

current_time

Retrieve the current date and time in a specified format and timezone. Designed to enable accurate time awareness for applications and large language models.

Instructions

Get the current date and time.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatYesThe format of the time, default is empty stringYYYY-MM-DD HH:mm:ss
timezoneNoThe timezone of the time, IANA timezone name, e.g. Asia/Shanghai

Implementation Reference

  • Defines the input schema, name, and description for the 'current_time' tool.
    export const CURRENT_TIME: Tool = { name: 'current_time', description: 'Get the current date and time.', inputSchema: { type: 'object', properties: { format: { type: 'string', description: 'The format of the time, default is empty string', enum: [ 'h:mm A', 'h:mm:ss A', 'YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD', 'YYYY-MM', 'MM/DD/YYYY', 'MM/DD/YY', 'YYYY/MM/DD', 'YYYY/MM', ], default: 'YYYY-MM-DD HH:mm:ss', }, timezone: { type: 'string', description: 'The timezone of the time, IANA timezone name, e.g. Asia/Shanghai', default: undefined, }, }, required: ['format'], }, };
  • src/index.ts:30-34 (registration)
    Registers the 'current_time' tool (via CURRENT_TIME) in the list of available tools.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [CURRENT_TIME, RELATIVE_TIME, DAYS_IN_MONTH, GET_TIMESTAMP, CONVERT_TIME, GET_WEEK_YEAR], }; });
  • Handles incoming calls to the 'current_time' tool, validates arguments, executes the logic, and returns the formatted response.
    case 'current_time': { if (!checkCurrentTimeArgs(args)) { throw new Error(`Invalid arguments for tool: [${name}]`); } const { format, timezone } = args; const result = getCurrentTime(format, timezone); return { success: true, content: [ { type: 'text', text: `Current UTC time is ${result.utc}, and the time in ${result.timezone} is ${result.local}.`, }, ], }; }
  • Core helper function that computes and formats the current time in UTC and specified/local timezone.
    function getCurrentTime(format: string, timezone?: string) { const utcTime = dayjs.utc(); const localTimezone = timezone ?? dayjs.tz.guess(); const localTime = dayjs().tz(localTimezone); return { utc: utcTime.format(format), local: localTime.format(format), timezone: localTimezone, }; }
  • Type guard function for validating input arguments to the 'current_time' tool.
    function checkCurrentTimeArgs(args: unknown): args is { format: string, timezone?: string } { return ( typeof args === 'object' && args !== null && 'format' in args && typeof args.format === 'string' && ('timezone' in args ? typeof args.timezone === 'string' : true) ); }

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