getChineseCalendar
Retrieve traditional Chinese calendar details for any Gregorian date to align with lunar and cultural events. Perfect for planning, cultural study, or astrological analysis.
Instructions
获取指定公历时间(默认今天)的黄历信息。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| solarDatetime | No | 用ISO时间格式表示的公历时间. 例如:`2008-03-01T13:00:00+08:00`。 |
Implementation Reference
- src/lib/chineseCalendar.ts:7-39 (handler)The core handler function that implements the getChineseCalendar tool, computing Chinese calendar details like lunar date, Ganzhi, festivals, auspicious directions, etc., from a solar datetime.
export const getChineseCalendar = (date?: string) => { if (!date) { date = today(); } const solarTime = getSolarTime(date); const lunarHour = solarTime.getLunarHour(); const eightChar = lunarHour.getEightChar(); const lunarDay = lunarHour.getLunarDay(); const twentyStar = lunarDay.getTwentyEightStar(); const daySixtyCycle = lunarDay.getSixtyCycle(); const dayHeavenStem = daySixtyCycle.getHeavenStem(); const dayEarthBranch = daySixtyCycle.getEarthBranch(); return { 公历: solarTime.toString().split(' ').shift() + ' 星期' + solarTime.getSolarDay().getWeek(), 农历: lunarDay.toString(), 干支: eightChar.toString().split(' ').slice(0, 3).join(' '), 生肖: eightChar.getYear().getEarthBranch().getZodiac().toString(), 纳音: eightChar.getDay().getSound().toString(), 农历节日: lunarDay.getFestival()?.toString() || undefined, 公历节日: solarTime.getSolarDay().getFestival()?.toString() || undefined, 节气: solarTime.getSolarDay().getTerm().toString(), 二十八宿: twentyStar.toString() + twentyStar.getSevenStar() + twentyStar.getAnimal() + twentyStar.getLuck(), 彭祖百忌: daySixtyCycle.getPengZu().toString(), 喜神方位: dayHeavenStem.getJoyDirection().toString(), 阳贵神方位: dayHeavenStem.getYangDirection().toString(), 阴贵神方位: dayHeavenStem.getYinDirection().toString(), 福神方位: dayHeavenStem.getMascotDirection().toString(), 财神方位: dayHeavenStem.getWealthDirection().toString(), 冲煞: `冲${dayEarthBranch.getOpposite().getZodiac()}(${dayEarthBranch.getOpposite()})煞${dayEarthBranch.getOminous()}`, 宜: lunarDay.getRecommends().toString(), 忌: lunarDay.getAvoids().toString(), }; }; - src/mcp.ts:55-72 (registration)Registers the getChineseCalendar tool with the MCP server, defining its name, description, input schema, and a thin wrapper handler that calls the core function and formats the response.
server.tool( 'getChineseCalendar', '获取指定公历时间(默认今天)的黄历信息。', { solarDatetime: z.string().optional().describe('用ISO时间格式表示的公历时间. 例如:`2008-03-01T13:00:00+08:00`。'), }, async ({ solarDatetime }) => { const result = getChineseCalendar(solarDatetime); return { content: [ { type: 'text', text: JSON.stringify(result), }, ], }; }, ); - src/mcp.ts:58-60 (schema)Zod input schema for the getChineseCalendar tool, validating the optional solarDatetime parameter.
{ solarDatetime: z.string().optional().describe('用ISO时间格式表示的公历时间. 例如:`2008-03-01T13:00:00+08:00`。'), },