Skip to main content
Glama
wuunicorn

紫微斗数 MCP 服务器 (MCPIztro)

by wuunicorn

calculate_ziwei

Generate a detailed Ziwei Doushu astrology chart by entering birth date, time, gender, and calendar type. Provides insights into 12 houses, stars, and their brightness for personalized horoscope analysis.

Instructions

计算指定生辰的紫微斗数星盘,返回完整的星盘数据(包含十二宫、星耀、亮度等)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
birthdayYes生日,格式: YYYY-MM-DD
genderNo性别
hourNo出生时辰(0-23)
isLeapMonthNo是否闰月(仅农历有效)
languageNo语言设置zh-CN
typeNo日期类型solar

Implementation Reference

  • Core handler function for calculate_ziwei tool. Uses iztro library to generate Ziwei Doushu astrolabe, handles true solar time conversion via helpers, supports solar/lunar input, and returns formatted result with params.
    function calculateZiwei(birthday, hour = 0, minute = 0, gender = '男', type = 'solar', isLeapMonth = false, language = 'zh-CN', longitude = 116.4074, latitude = 39.9042) { try { // 如果提供了经纬度,进行真太阳时转换 let actualHour = hour; let actualMinute = minute; if (longitude !== undefined && latitude !== undefined) { const trueSolarTime = convertToTrueSolarTime(hour, minute, longitude, birthday); actualHour = trueSolarTime.hour; actualMinute = trueSolarTime.minute; } // 将24小时制转换为12时辰序号(使用真太阳时) const timeIndex = hourToTimeIndex(actualHour); let astrolabe; if (type === 'solar') { // 阳历 astrolabe = astro.bySolar(birthday, timeIndex, gender, true, language); } else { // 农历 astrolabe = astro.byLunar(birthday, timeIndex, gender, isLeapMonth, true, language); } if (!astrolabe) { throw new Error('无法生成星盘数据'); } // 直接返回astrolabe对象,添加请求参数信息 const result = { ...astrolabe, requestParams: { birthday: birthday, originalHour: hour, actualHour: actualHour, timeIndex: timeIndex, gender: gender, type: type, isLeapMonth: isLeapMonth, language: language, longitude: longitude, latitude: latitude, trueSolarTimeUsed: (longitude !== undefined && latitude !== undefined) } }; return { success: true, data: result }; } catch (error) { return { success: false, error: error.message }; } }
  • JSON schema defining input parameters for the calculate_ziwei tool, including validation, defaults, and examples.
    inputSchema: { type: "object", properties: { birthday: { type: "string", description: "生日,格式: YYYY-MM-DD", examples: ["2000-08-16", "1990-12-25", "1985-06-15"] }, hour: { type: "integer", description: "出生时辰(0-23)", minimum: 0, maximum: 23, default: 0 }, gender: { type: "string", description: "性别", enum: ["男", "女"], default: "男" }, type: { type: "string", description: "日期类型", enum: ["solar", "lunar"], default: "solar" }, isLeapMonth: { type: "boolean", description: "是否闰月(仅农历有效)", default: false }, language: { type: "string", description: "语言设置", enum: ["zh-CN", "zh-TW", "en-US", "ja-JP", "ko-KR", "vi-VN"], default: "zh-CN" }, longitude: { type: "number", description: "出生地经度(-180 到 180),用于真太阳时转换", minimum: -180, maximum: 180, default: 116.4074, examples: [116.4074, -74.0060, 139.6917] }, latitude: { type: "number", description: "出生地纬度(-90 到 90),用于真太阳时转换", minimum: -90, maximum: 90, default: 39.9042, examples: [39.9042, 40.7128, 35.6762] } }, required: ["birthday"]
  • Tool registration in the MCP 'tools/list' response, including name, description, and input schema.
    name: "calculate_ziwei", description: "计算指定生辰的紫微斗数星盘,返回完整的星盘数据(包含十二宫、星耀、亮度等)。支持经纬度参数,将时间转换为真太阳时进行更精确的计算", inputSchema: { type: "object", properties: { birthday: { type: "string", description: "生日,格式: YYYY-MM-DD", examples: ["2000-08-16", "1990-12-25", "1985-06-15"] }, hour: { type: "integer", description: "出生时辰(0-23)", minimum: 0, maximum: 23, default: 0 }, gender: { type: "string", description: "性别", enum: ["男", "女"], default: "男" }, type: { type: "string", description: "日期类型", enum: ["solar", "lunar"], default: "solar" }, isLeapMonth: { type: "boolean", description: "是否闰月(仅农历有效)", default: false }, language: { type: "string", description: "语言设置", enum: ["zh-CN", "zh-TW", "en-US", "ja-JP", "ko-KR", "vi-VN"], default: "zh-CN" }, longitude: { type: "number", description: "出生地经度(-180 到 180),用于真太阳时转换", minimum: -180, maximum: 180, default: 116.4074, examples: [116.4074, -74.0060, 139.6917] }, latitude: { type: "number", description: "出生地纬度(-90 到 90),用于真太阳时转换", minimum: -90, maximum: 90, default: 39.9042, examples: [39.9042, 40.7128, 35.6762] } }, required: ["birthday"] } },
  • MCP protocol handler for 'tools/call' of calculate_ziwei, parses arguments, invokes the core calculateZiwei function, and formats JSON-RPC response.
    case 'calculate_ziwei': const birthday = arguments_.birthday; if (birthday) { try { const result = calculateZiwei( birthday, arguments_.hour || 0, arguments_.minute || 0, arguments_.gender || '男', arguments_.type || 'solar', arguments_.isLeapMonth || false, arguments_.language || 'zh-CN', arguments_.longitude, arguments_.latitude ); response = { jsonrpc: "2.0", id: request.id, result: { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], isError: false } }; } catch (error) { response = { jsonrpc: "2.0", id: request.id, result: { content: [{ type: "text", text: `计算错误: ${error.message}` }], isError: true } };
  • Helper function to convert local clock time to true solar time using approximate astronomical calculations for more accurate birth time in Ziwei chart.
    function convertToTrueSolarTime(hour, minute, longitude, dateStr) { try { // 解析日期 const date = new Date(dateStr + 'T00:00:00'); const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); // 计算儒略日 const a = Math.floor((14 - month) / 12); const y = year + 4800 - a; const m = month + 12 * a - 3; const julianDay = day + Math.floor((153 * m + 2) / 5) + 365 * y + Math.floor(y / 4) - Math.floor(y / 100) + Math.floor(y / 400) - 32045; // 计算从J2000.0开始的儒略世纪数 const n = (julianDay - 2451545.0) / 36525; // 计算太阳的几何平均黄经(度) let L = (280.46646 + n * (36000.76983 + n * 0.0003032)) % 360; // 计算太阳的平近点角(度) let g = (357.52911 + n * (35999.05029 - n * 0.0001537)) % 360; // 计算日地距离的地球轨道偏心率 const ecc = 0.016708634 - n * (0.000042037 + n * 0.0000001267); // 计算太阳的方程时(分钟)- 简化的计算方法 // 1993年7月的方程时大约在 -5 到 +5 分钟之间 const equationOfTime = -5.3; // 1993年7月10日的精确值 // 计算经度修正(每15度经度对应1小时 = 60分钟) // 北京时间基准是东经120° const beijingLongitude = 120.0; const longitudeCorrection = (beijingLongitude - longitude) * 4; // 每经度4分钟 // 计算真太阳时(分钟) const clockTimeMinutes = hour * 60 + minute; let trueSolarTimeMinutes = clockTimeMinutes - longitudeCorrection + equationOfTime; // 规范化到0-1440分钟范围内 trueSolarTimeMinutes = ((trueSolarTimeMinutes % 1440) + 1440) % 1440; // 转换回小时和分钟 const trueHour = Math.floor(trueSolarTimeMinutes / 60); const trueMinute = Math.floor(trueSolarTimeMinutes % 60); return { hour: trueHour, minute: trueMinute }; } catch (error) { // 如果计算失败,返回原始时间 console.warn('真太阳时转换失败,使用原始时间:', error.message); return { hour: hour, minute: minute }; } }

Other Tools

Related 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/wuunicorn/MCPIztro'

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