get_timestamp
Convert a given date and time into a timestamp using the format YYYY-MM-DD HH:mm:ss. Ideal for integrating time awareness in applications or systems through the Time MCP Server.
Instructions
Get the timestamp for the time.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| time | No | The time to get the timestamp. Format: YYYY-MM-DD HH:mm:ss |
Implementation Reference
- src/index.ts:175-177 (handler)The core handler function that computes and returns the Unix timestamp (milliseconds) for the given UTC time string or the current time.function getTimestamp(time?: string) { return time ? dayjs.utc(time).valueOf() : dayjs().valueOf(); }
- src/tools.ts:64-76 (schema)Defines the tool's metadata: name, description, and input schema (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', }, }, }, };
- src/index.ts:32-33 (registration)Registers the get_timestamp tool (via GET_TIMESTAMP export) in the list returned by ListToolsRequestHandler.tools: [CURRENT_TIME, RELATIVE_TIME, DAYS_IN_MONTH, GET_TIMESTAMP, CONVERT_TIME, GET_WEEK_YEAR], };
- src/index.ts:91-107 (handler)Dispatcher case in CallToolRequestHandler that validates args, 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.`, }, ], };
- src/index.ts:231-237 (helper)Input validation helper for get_timestamp tool arguments.function checkTimestampArgs(args: unknown): args is { time?: string } { return ( typeof args === 'object' && args !== null && 'time' in args && (typeof args.time === 'string' || args.time === undefined) );