get-current-date
Retrieve the current date in the Shanghai timezone (UTC+8) formatted as 'yyyy-MM-dd'. Ideal for resolving relative dates (e.g., 'tomorrow', 'next Wednesday') and providing accurate date inputs for other APIs.
Instructions
获取当前日期,以上海时区(Asia/Shanghai, UTC+8)为准,返回格式为 "yyyy-MM-dd"。主要用于解析用户提到的相对日期(如“明天”、“下周三”),为其他需要日期的接口提供准确的日期输入。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:815-839 (registration)Registration of the 'get-current-date' tool. Includes empty input schema and the inline handler function that computes the current date in Shanghai timezone (Asia/Shanghai) using date-fns-tz and returns it formatted as 'yyyy-MM-dd'. Error handling included.server.tool( 'get-current-date', '获取当前日期,以上海时区(Asia/Shanghai, UTC+8)为准,返回格式为 "yyyy-MM-dd"。主要用于解析用户提到的相对日期(如“明天”、“下周三”),提供准确的日期输入。', {}, async () => { try { const timeZone = 'Asia/Shanghai'; const nowInShanghai = toZonedTime(new Date(), timeZone); const formattedDate = format(nowInShanghai, 'yyyy-MM-dd'); return { content: [{ type: 'text', text: formattedDate }], }; } catch (error) { console.error('Error getting current date:', error); return { content: [ { type: 'text', text: 'Error: Failed to get current date.', }, ], }; } } );
- src/index.ts:819-837 (handler)The handler function for 'get-current-date' tool. It uses toZonedTime and format from date-fns-tz/date-fns to get and format the current date in Asia/Shanghai timezone as 'yyyy-MM-dd', wrapped in MCP response format. Includes try-catch for errors.async () => { try { const timeZone = 'Asia/Shanghai'; const nowInShanghai = toZonedTime(new Date(), timeZone); const formattedDate = format(nowInShanghai, 'yyyy-MM-dd'); return { content: [{ type: 'text', text: formattedDate }], }; } catch (error) { console.error('Error getting current date:', error); return { content: [ { type: 'text', text: 'Error: Failed to get current date.', }, ], }; }
- src/index.ts:818-818 (schema)Empty input schema for 'get-current-date' tool (no parameters required).{},