get_current_date
Retrieve the current date in ISO, US, EU, or custom formats to ensure time-sensitive content uses accurate date information.
Instructions
Get only the current date
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Output format: 'iso' (YYYY-MM-DD), 'us' (MM/DD/YYYY), 'eu' (DD/MM/YYYY), or custom format | iso |
Implementation Reference
- src/index.ts:109-130 (handler)Handler for the 'get_current_date' tool. Extracts the current date from 'now' (a new Date()), formats it based on the 'format' parameter ('iso', 'us', 'eu', or custom via formatDate helper), and returns it as text content.case "get_current_date": { const format = request.params.arguments?.format || "iso"; let result: string; if (format === "iso") { result = now.toISOString().split('T')[0]; } else if (format === "us") { result = `${(now.getMonth() + 1).toString().padStart(2, '0')}/${now.getDate().toString().padStart(2, '0')}/${now.getFullYear()}`; } else if (format === "eu") { result = `${now.getDate().toString().padStart(2, '0')}/${(now.getMonth() + 1).toString().padStart(2, '0')}/${now.getFullYear()}`; } else { result = formatDate(now, format as string); } return { content: [{ type: "text", text: result }] }; }
- src/index.ts:44-57 (registration)Tool registration in ListTools handler, defining name, description, and input schema for 'get_current_date'.{ name: "get_current_date", description: "Get only the current date", inputSchema: { type: "object", properties: { format: { type: "string", description: "Output format: 'iso' (YYYY-MM-DD), 'us' (MM/DD/YYYY), 'eu' (DD/MM/YYYY), or custom format", default: "iso" } } } },
- src/index.ts:47-56 (schema)Input schema definition for the 'get_current_date' tool, specifying the optional 'format' parameter.inputSchema: { type: "object", properties: { format: { type: "string", description: "Output format: 'iso' (YYYY-MM-DD), 'us' (MM/DD/YYYY), 'eu' (DD/MM/YYYY), or custom format", default: "iso" } } }
- src/index.ts:167-183 (helper)Helper function 'formatDate' used by 'get_current_date' (and others) for custom date formatting with placeholders like YYYY, MM, etc.function formatDate(date: Date, format: string): string { const replacements: { [key: string]: string } = { 'YYYY': date.getFullYear().toString(), 'MM': (date.getMonth() + 1).toString().padStart(2, '0'), 'DD': date.getDate().toString().padStart(2, '0'), 'HH': date.getHours().toString().padStart(2, '0'), 'mm': date.getMinutes().toString().padStart(2, '0'), 'ss': date.getSeconds().toString().padStart(2, '0'), }; let result = format; for (const [key, value] of Object.entries(replacements)) { result = result.replace(new RegExp(key, 'g'), value); } return result; }