Skip to main content
Glama
baranwang

mcp-tung-shing

get-tung-shing

Retrieve Chinese Tung Shing almanac data for selected dates, including lunar calendar, auspicious activities, taboos, and astrological details.

Instructions

获取通胜黄历,包括公历、农历、宜忌、吉凶、冲煞等信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
startDateNo开始日期,格式为"YYYY-MM-DD"的字符串2026-01-02
daysNo要获取的连续天数
includeHoursNo是否包含时辰信息
tabooFiltersNo多个筛选宜忌事项,条件之间为或关系

Implementation Reference

  • Handler for the 'get-tung-shing' tool: parses parameters using the schema, validates date, fetches almanac data for multiple days using getDailyAlmanac, applies optional taboo filters, and returns JSON-formatted content.
    case 'get-tung-shing': {
      const {
        startDate,
        days,
        includeHours,
        tabooFilters = [],
      } = getTungShingParamsSchema.parse(request.params.arguments);
      const start = dayjs(startDate);
      if (!start.isValid()) {
        return {
          content: [
            {
              type: 'text',
              text: 'Invalid date',
            },
          ],
          isError: true,
        };
      }
    
      return {
        content: Array.from({ length: days }, (_, i) => {
          const almanac = getDailyAlmanac(start.add(i, 'day'), includeHours);
    
          // 如果没有指定taboo过滤,直接返回结果
          if (!tabooFilters.length) {
            return {
              type: 'text',
              text: JSON.stringify(almanac),
            };
          }
    
          // 提取宜忌内容
          const recommends = (almanac.当日[ContentType.宜] as string[]) || [];
          const avoids = (almanac.当日[ContentType.忌] as string[]) || [];
    
          // 根据tabooFilters进行过滤,条件之间为或的关系
          const hasMatch = tabooFilters.some((filter) => {
            // 宜事项过滤
            if (filter.type === TabooType.宜) {
              return recommends.includes(filter.value);
            }
            // 忌事项过滤
            if (filter.type === TabooType.忌) {
              return avoids.includes(filter.value);
            }
            return false;
          });
    
          if (hasMatch) {
            return {
              type: 'text',
              text: JSON.stringify(almanac),
            };
          }
          return null;
        }).filter(Boolean),
      };
    }
  • Zod schema defining input parameters for the get-tung-shing tool: startDate (YYYY-MM-DD), days (default 1), includeHours (default false), tabooFilters (array of type/value filters).
    export const getTungShingParamsSchema = z.object({
      startDate: z
        .string()
        .optional()
        .default(new Date().toISOString().split('T')[0])
        .describe('开始日期,格式为"YYYY-MM-DD"的字符串'),
      days: z
        .union([
          z.number().int().min(1),
          z
            .string()
            .regex(/^\d+$/)
            .transform((val) => Number.parseInt(val)),
        ])
        .optional()
        .default(1)
        .describe('要获取的连续天数'),
      includeHours: z
        .boolean()
        .optional()
        .default(false)
        .describe('是否包含时辰信息'),
      tabooFilters: z
        .array(tabooFilterSchema)
        .optional()
        .describe('多个筛选宜忌事项,条件之间为或关系'),
    });
  • src/server.ts:32-40 (registration)
    Tool registration in ListToolsRequestHandler: defines name, description, and input schema for 'get-tung-shing'.
    mcpServer.server.setRequestHandler(ListToolsRequestSchema, () => ({
      tools: [
        {
          name: 'get-tung-shing',
          description: '获取通胜黄历,包括公历、农历、宜忌、吉凶、冲煞等信息',
          inputSchema: zodToJsonSchema(getTungShingParamsSchema),
        },
      ],
    }));
  • Core helper function getDailyAlmanac that generates the Tung Shing (Chinese almanac) data for a given date, including Gregorian/Lunar dates, festivals, 宜/忌, 吉凶, 冲煞, etc., optionally with hourly data.
    export function getDailyAlmanac(
      date: dayjs.Dayjs,
      includeHours = false,
    ): DailyAlmanac {
      const parsedDate = dayjs(date);
      if (!parsedDate.isValid()) {
        throw new Error('Invalid date');
      }
    
      const lunarDay = parsedDate.toLunarDay();
      const solarDay = lunarDay.getSolarDay();
      const sixtyCycle = lunarDay.getSixtyCycle();
      const earthBranch = sixtyCycle.getEarthBranch();
      const twentyEightStar = lunarDay.getTwentyEightStar();
      const gods = lunarDay.getGods().reduce(
        (acc, god) => {
          const category =
            god.getLuck().getName() === '吉' ? 'auspicious' : 'inauspicious';
          acc[category].push(god.getName());
          return acc;
        },
        { auspicious: [] as string[], inauspicious: [] as string[] },
      );
    
      const result: DailyAlmanac = {
        公历: parsedDate.locale('zh-cn').format('YYYY 年 M 月 D日(ddd)'),
        农历: parsedDate.format('LY年LMLD'),
        节日: lunarDay.getFestival()?.getName(),
        节气: solarDay.getTermDay().toString(),
        七十二候: solarDay.getPhenologyDay().toString(),
        当日: {
          [ContentType.宜]: lunarDay.getRecommends().map((item) => item.getName()),
          [ContentType.忌]: lunarDay.getAvoids().map((item) => item.getName()),
          [ContentType.吉凶]: lunarDay
            .getTwelveStar()
            .getEcliptic()
            .getLuck()
            .toString(),
          [ContentType.五行]: sixtyCycle.getSound().toString(),
          [ContentType.冲煞]: `冲${earthBranch.getOpposite().getZodiac()}煞${earthBranch.getOminous()}`,
          [ContentType.值神]: lunarDay.getTwelveStar().toString(),
          [ContentType.建除十二神]: lunarDay.getDuty().toString(),
          [ContentType.二十八星宿]: `${twentyEightStar}${twentyEightStar.getSevenStar()}${twentyEightStar.getAnimal()}(${twentyEightStar.getLuck()})`,
          [ContentType.吉神宜趋]: gods.auspicious,
          [ContentType.凶煞宜忌]: gods.inauspicious,
          [ContentType.彭祖百忌]: `${sixtyCycle.getHeavenStem().getPengZuHeavenStem()} ${earthBranch.getPengZuEarthBranch()}`,
        },
      };
    
      if (includeHours) {
        result.分时 = {};
        for (let i = 0; i < 12; i++) {
          const hour = parsedDate.addLunar(i, 'dual-hour');
          result.分时[hour.format('LH')] = getHourlyAlmanac(hour);
        }
      }
    
      return result;
    }
  • Sub-schema for tabooFilter items used in getTungShingParamsSchema: type (宜/忌), value (specific item name).
    export const tabooFilterSchema = z.object({
      type: z.nativeEnum(TabooType).describe('过滤类型:宜(1)、忌(2)'),
      value: z.enum(getDayTabooNames()).describe('要筛选的宜忌事项'),
    });

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/baranwang/mcp-tung-shing'

If you have feedback or need assistance with the MCP directory API, please join our Discord server