Skip to main content
Glama

get_timestamp

Convert a specified date and time into a precise timestamp using the format YYYY-MM-DD HH:mm:ss.SSS. Ideal for applications requiring accurate time-based calculations in LLM workflows.

Instructions

Get the timestamp for the time.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timeNoThe time to get the timestamp. Format: YYYY-MM-DD HH:mm:ss.SSS

Implementation Reference

  • Core handler function that computes the Unix timestamp (milliseconds) for the given time string parsed as UTC or the current time if no time provided.
    function getTimestamp(time?: string) { return time ? dayjs.utc(time).valueOf() : dayjs().valueOf(); }
  • Tool dispatch handler in the CallToolRequestSchema that validates arguments, calls getTimestamp, and formats the response.
    case 'get_timestamp': { if (!checkTimestampArgs(args)) { throw new Error(`Invalid arguments for tool: [${name}]`); } const time = args.time; const result = getTimestamp(time); return { success: true, content: [ { type: 'text', text: time ? `The timestamp of ${time} (parsed as UTC) is ${result} ms.` : `The current timestamp is ${result} ms.`, }, ], };
  • Tool schema definition including name, description, and input schema for optional 'time' parameter.
    export const GET_TIMESTAMP: Tool = { name: 'get_timestamp', description: 'Get the timestamp for the time.', inputSchema: { type: 'object', properties: { time: { type: 'string', description: 'The time to get the timestamp. Format: YYYY-MM-DD HH:mm:ss.SSS', }, }, }, };
  • src/index.ts:30-34 (registration)
    Registers the get_timestamp tool (via GET_TIMESTAMP) in the list of available tools for ListToolsRequest.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [CURRENT_TIME, RELATIVE_TIME, DAYS_IN_MONTH, GET_TIMESTAMP, CONVERT_TIME, GET_WEEK_YEAR], }; });
  • Helper function to validate input arguments for the get_timestamp tool.
    function checkTimestampArgs(args: unknown): args is { time?: string } { if (args === undefined || args === null) { return true; } return ( typeof args === 'object' && (!('time' in (args as Record<string, unknown>)) || typeof (args as { time?: unknown }).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