getSolarTimes
Converts Bazi (Chinese astrological chart) data into a list of Gregorian calendar times formatted as YYYY-MM-DD hh:mm:ss for accurate Chinese astrological calculations.
Instructions
根据八字获取公历时间列表。返回的时间格式为:YYYY-MM-DD hh:mm:ss。例如时间1998年7月31日下午2点整表示为:1998-07-31 14:00:00
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bazi | Yes | 八字,按年柱、月柱、日柱、时柱顺序,用空格隔开。例如:戊寅 己未 己卯 辛未 |
Implementation Reference
- src/index.ts:30-35 (handler)Core handler function that implements the getSolarTimes tool logic: parses the bazi string into year, month, day, hour pillars, computes solar times using the EightChar class from tyme4ts library, maps over them formatting with formatSolarTime, and returns the list.export const getSolarTimes = async ({ bazi }) => { const [year, month, day, hour] = bazi.split(' '); const solarTimes = new EightChar(year, month, day, hour).getSolarTimes(1700, new Date().getFullYear()); const result = solarTimes.map((time) => formatSolarTime(time)); return result; };
- src/mcp.ts:36-53 (registration)Registration of the getSolarTimes tool in the MCP server using server.tool(), including name, description, Zod input schema, and a thin wrapper handler that invokes the core getSolarTimes function and formats the response as MCP content.server.tool( 'getSolarTimes', '根据八字获取公历时间列表。返回的时间格式为:YYYY-MM-DD hh:mm:ss。例如时间1998年7月31日下午2点整表示为:1998-07-31 14:00:00', { bazi: z.string().describe('八字,按年柱、月柱、日柱、时柱顺序,用空格隔开。例如:戊寅 己未 己卯 辛未'), }, async (data) => { const result = await getSolarTimes(data); return { content: [ { type: 'text', text: JSON.stringify(result), }, ], }; }, );
- src/mcp.ts:39-41 (schema)Zod input schema for the getSolarTimes tool, defining the 'bazi' parameter as a string describing the eight characters in year, month, day, hour pillars separated by spaces.{ bazi: z.string().describe('八字,按年柱、月柱、日柱、时柱顺序,用空格隔开。例如:戊寅 己未 己卯 辛未'), },
- src/lib/date.ts:29-43 (helper)Helper function formatSolarTime that converts a SolarTime object from tyme4ts into a formatted string 'YYYY-MM-DD hh:mm:ss', used in the getSolarTimes handler to format the list of solar times.export function formatSolarTime(solarTime: SolarTime) { return ( [ solarTime.getYear(), solarTime.getMonth().toString().padStart(2, '0'), solarTime.getDay().toString().padStart(2, '0'), ].join('-') + ' ' + [ solarTime.getHour().toString().padStart(2, '0'), solarTime.getMinute().toString().padStart(2, '0'), solarTime.getSecond().toString().padStart(2, '0'), ].join(':') ); }