get-current-date
Retrieve the current date in Shanghai timezone (UTC+8) formatted as yyyy-MM-dd. Provides accurate date input for parsing relative dates like 'tomorrow' or 'next Wednesday' in railway ticket queries.
Instructions
获取当前日期,以上海时区(Asia/Shanghai, UTC+8)为准,返回格式为 "yyyy-MM-dd"。主要用于解析用户提到的相对日期(如“明天”、“下周三”),为其他需要日期的接口提供准确的日期输入。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:574-588 (handler)The handler function for the 'get-current-date' tool. It retrieves the current date in the Asia/Shanghai timezone using toZonedTime and formats it as 'yyyy-MM-dd' using format from date-fns libraries. Includes error handling.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:573-573 (schema)Input schema for 'get-current-date' tool: no parameters required (empty object).{},
- src/index.ts:570-589 (registration)Registration of the 'get-current-date' tool using server.tool, including name, description, empty input schema, and inline handler function.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.' }], }; } } );