timestamp
Generate current timestamps in ISO, Unix, or readable formats for standardized time data in MCP server applications.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "timestamp"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | iso |
Implementation Reference
- src/tools/timestampTool.ts:14-39 (handler)The handler function that computes the current timestamp in the specified format ('iso', 'unix', or 'readable') and returns it 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)Input schema using Zod, defining an optional 'format' parameter with enum values ['iso', 'unix', 'readable'] defaulting to 'iso'.
{ format: z.enum(['iso', 'unix', 'readable']).optional().default('iso'), }, - src/tools/timestampTool.ts:8-41 (registration)The timestampTool function registers the 'timestamp' tool on the MCP server, specifying the tool name, input schema, and handler function.
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)Within registerTools, calls timestampTool(server) to register the timestamp tool.
// Register timestamp tool timestampTool(server);