Skip to main content
Glama
SiwuXue

Yijing Bazi MCP Server

by SiwuXue

bazi_generate_chart

Generate a Bazi (Four Pillars) destiny chart using birth time and gender to analyze traditional Chinese fortune-telling insights for life aspects like career, wealth, and relationships.

Instructions

生成八字命盘

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
birth_timeYes出生时间(阳历)
is_lunarNo是否为农历日期
genderYes性别
birth_locationNo出生地经纬度(可选,用于精确计算)

Implementation Reference

  • The primary handler function that executes the core logic for generating a Bazi (Four Pillars) chart from birth details. It handles time conversion, lunar/solar calendar, computes four pillars, major/minor luck cycles, gods/spirits, five elements, and ten gods analysis.
    async generateChart({ birth_datetime, timezone, gender, location, use_true_solar_time = false, is_lunar = false }) {
      try {
        this.logger.info('开始生成八字排盘', { birth_datetime, timezone, gender });
    
        // 转换时间
        const birthMoment = moment.tz(birth_datetime, timezone);
    
        // 真太阳时校正
        let adjustedTime = birthMoment;
        if (use_true_solar_time && location) {
          adjustedTime = this.calculator.adjustForTrueSolarTime(birthMoment, location);
        }
    
        // 根据is_lunar参数处理农历/公历日期
        let lunar, solar;
        if (is_lunar) {
          // 如果输入的是农历日期,需要先创建农历对象再转换为公历
          const year = adjustedTime.year();
          const month = adjustedTime.month() + 1; // moment月份从0开始
          const day = adjustedTime.date();
          const hour = adjustedTime.hour();
          const minute = adjustedTime.minute();
    
          lunar = Lunar.fromYmdHms(year, month, day, hour, minute, 0);
          solar = lunar.getSolar();
          // 更新adjustedTime为转换后的公历时间
          adjustedTime = moment.tz(`${solar.getYear()}-${solar.getMonth()}-${solar.getDay()} ${hour}:${minute}:00`, timezone);
        } else {
          // 如果输入的是公历日期,直接从公历创建农历对象
          lunar = Lunar.fromDate(adjustedTime.toDate());
          solar = lunar.getSolar();
        }
    
        // 计算四柱八字
        const fourPillars = this.calculateFourPillars(lunar, adjustedTime);
    
        // 计算大运
        const majorLuck = this.calculateMajorLuck(fourPillars, gender, lunar);
    
        // 计算流年
        const annualLuck = this.calculateAnnualLuck(adjustedTime.year());
    
        // 计算神煞
        const spirits = this.calculateSpirits(fourPillars);
    
        // 五行分析
        const fiveElementsAnalysis = this.analyzeFiveElements(fourPillars);
    
        // 十神分析
        const tenGodsAnalysis = this.analyzeTenGods(fourPillars);
    
        const result = {
          timestamp: new Date().toISOString(),
          birth_info: {
            solar_datetime: solar.toYmdHms(),
            lunar_date: lunar.toFullString(),
            timezone: timezone,
            gender: gender,
            location: location,
            use_true_solar_time: use_true_solar_time
          },
          four_pillars: fourPillars,
          major_luck: majorLuck,
          annual_luck: annualLuck,
          spirits_and_stars: spirits,
          five_elements: fiveElementsAnalysis,
          ten_gods: tenGodsAnalysis,
          chart_quality: this.evaluateChartQuality(fourPillars, fiveElementsAnalysis),
          basic_personality: this.analyzeBasicPersonality(fourPillars, fiveElementsAnalysis)
        };
    
        this.logger.info('八字排盘生成成功');
        return result;
      } catch (error) {
        this.logger.error('八字排盘生成失败', { error: error.message });
        throw error;
      }
    }
  • src/index.js:415-426 (registration)
    Registration and dispatch logic in the CallToolRequestSchema handler. Maps incoming tool arguments to the BaziEngine.generateChart method after parameter adaptation.
    case 'bazi_generate_chart':
      // 转换参数格式以匹配BaziEngine期望的格式
      const chartArgs = {
        birth_datetime: args.birth_time,
        timezone: args.birth_location?.timezone || 'Asia/Shanghai',
        gender: args.gender,
        location: args.birth_location,
        use_true_solar_time: false,
        is_lunar: args.is_lunar || false
      };
      result = await baziEngine.generateChart(chartArgs);
      break;
  • Joi-based input schema validation specifically for the bazi_generate_chart tool parameters, used in runtime validation.
    function createBaziGenerateChartSchema() {
      return Joi.object({
        birth_time: Joi.alternatives().try(
          Joi.date().iso(),
          Joi.string().pattern(/^\d{4}-\d{2}-\d{2}(\s\d{2}:\d{2}(:\d{2})?)?$/)
        ).required(),
        is_lunar: Joi.boolean().default(false),
        gender: Joi.string().valid('male', 'female', '男', '女').required(),
        birth_location: Joi.object({
          latitude: Joi.number().min(-90).max(90).optional(),
          longitude: Joi.number().min(-180).max(180).optional(),
          timezone: Joi.string().default('Asia/Shanghai')
        }).optional()
      });
    }
  • Static input schema definition for bazi_generate_chart returned by the ListToolsRequestSchema handler.
      name: 'bazi_generate_chart',
      description: '生成八字命盘',
      inputSchema: {
        type: 'object',
        properties: {
          birth_time: {
            type: 'string',
            format: 'date-time',
            description: '出生时间(阳历)'
          },
          is_lunar: {
            type: 'boolean',
            description: '是否为农历日期'
          },
          gender: {
            type: 'string',
            enum: ['male', 'female'],
            description: '性别'
          },
          birth_location: {
            type: 'object',
            properties: {
              longitude: { type: 'number' },
              latitude: { type: 'number' }
            },
            description: '出生地经纬度(可选,用于精确计算)'
          }
        },
        required: ['birth_time', 'gender']
      }
    },

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/SiwuXue/yijing-bazi-mcp-server'

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