Skip to main content
Glama

relative_time

Convert a specified timestamp into relative time (e.g., '2 hours ago') to add time awareness to your applications. Ideal for enhancing workflows with precise time-related functionalities.

Instructions

Get the relative time from now.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timeYesThe time to get the relative time from now. Format: YYYY-MM-DD HH:mm:ss

Implementation Reference

  • Core handler function that computes the relative time from the provided time string using dayjs.fromNow().
    function getRelativeTime(time: string) { return dayjs(time).fromNow(); }
  • Defines the input schema for the relative_time tool, specifying the required 'time' parameter.
    export const RELATIVE_TIME: Tool = { name: 'relative_time', description: 'Get the relative time from now.', inputSchema: { type: 'object', properties: { time: { type: 'string', description: 'The time to get the relative time from now. Format: YYYY-MM-DD HH:mm:ss', }, }, required: ['time'], }, };
  • src/index.ts:30-34 (registration)
    Registers the RELATIVE_TIME tool in the list returned for tool discovery.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [CURRENT_TIME, RELATIVE_TIME, DAYS_IN_MONTH, GET_TIMESTAMP, CONVERT_TIME, GET_WEEK_YEAR], }; });
  • Dispatch handler in the main tool call switch that validates args and invokes getRelativeTime.
    case 'relative_time': { if (!checkRelativeTimeArgs(args)) { throw new Error(`Invalid arguments for tool: [${name}]`); } const time = args.time; const result = getRelativeTime(time); return { success: true, content: [ { type: 'text', text: result, }, ], }; }
  • Runtime type guard for validating relative_time tool arguments.
    function checkRelativeTimeArgs(args: unknown): args is { time: string } { return ( typeof args === 'object' && args !== null && '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/yokingma/time-mcp'

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