timestamp
Generate and format timestamps in ISO, Unix, or readable formats to synchronize events or log data within the MCP Server Boilerplate framework.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | iso |
Implementation Reference
- src/tools/timestampTool.ts:14-39 (handler)The handler function for the 'timestamp' tool. It takes an optional 'format' parameter (iso, unix, readable) and returns the current timestamp in the specified format as a text content block.async ({ format }) => { const now = new Date(); let formattedTime: string; switch (format) { case 'unix': formattedTime = Math.floor(now.getTime() / 1000).toString(); break; case 'readable': formattedTime = now.toLocaleString(); break; case 'iso': default: formattedTime = now.toISOString(); break; } return { content: [ { type: 'text', text: `Current timestamp (${format}): ${formattedTime}`, }, ], }; }
- src/tools/timestampTool.ts:11-13 (schema)The input schema for the 'timestamp' tool using Zod, defining an optional 'format' parameter defaulting to 'iso'.{ format: z.enum(['iso', 'unix', 'readable']).optional().default('iso'), },
- src/tools/timestampTool.ts:8-41 (registration)The registration function that calls server.tool to register the 'timestamp' tool with its schema and handler.export function timestampTool(server: McpServer): void { server.tool( 'timestamp', { format: z.enum(['iso', 'unix', 'readable']).optional().default('iso'), }, async ({ format }) => { const now = new Date(); let formattedTime: string; switch (format) { case 'unix': formattedTime = Math.floor(now.getTime() / 1000).toString(); break; case 'readable': formattedTime = now.toLocaleString(); break; case 'iso': default: formattedTime = now.toISOString(); break; } return { content: [ { type: 'text', text: `Current timestamp (${format}): ${formattedTime}`, }, ], }; } ); }
- src/tools/index.ts:13-14 (registration)Call to register the timestamp tool within the tools index, which is invoked by the main server.// Register timestamp tool timestampTool(server);
- src/index.ts:34-34 (registration)Invocation of registerTools in the main server creation, which chains to timestamp tool registration.registerTools(server);