Skip to main content
Glama
wuunicorn

紫微斗数 MCP 服务器 (MCPIztro)

by wuunicorn

calculate_ziwei

Calculate a complete Ziwei Doushu astrology chart from birth details, including houses, stars, and brightness. Uses longitude and latitude for precise true solar time conversion.

Instructions

计算指定生辰的紫微斗数星盘,返回完整的星盘数据(包含十二宫、星耀、亮度等)。支持经纬度参数,将时间转换为真太阳时进行更精确的计算

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
birthdayYes生日,格式: YYYY-MM-DD
hourNo出生时辰(0-23)
genderNo性别
typeNo日期类型solar
isLeapMonthNo是否闰月(仅农历有效)
languageNo语言设置zh-CN
longitudeNo出生地经度(-180 到 180),用于真太阳时转换
latitudeNo出生地纬度(-90 到 90),用于真太阳时转换

Implementation Reference

  • The core handler function that implements the 'calculate_ziwei' tool logic. It converts input time to true solar time if longitude/latitude provided, computes time index, uses iztro.astro to generate the Ziwei Doushu chart (solar or lunar), and returns the astrolabe data 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 };
        }
    }
  • The JSON schema defining the input parameters for the 'calculate_ziwei' tool, including types, descriptions, defaults, enums, and required fields.
    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"]
    }
  • Registration of the 'calculate_ziwei' tool 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"]
        }
    },
  • The dispatch handler in the MCP 'tools/call' switch statement that extracts arguments, calls the calculateZiwei function, and formats the 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
                    }
                };
            }
        } else {
            response = {
                jsonrpc: "2.0",
                id: request.id,
                result: {
                    content: [{ type: "text", text: "错误: 需要提供 birthday 参数" }],
                    isError: true
                }
            };
        }
        break;
  • Helper function to convert clock time to true solar time using longitude correction and equation of time, used by calculateZiwei.
    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 };
        }
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It does reveal that this is a calculation tool (not a read-only query) and mentions precision enhancements through true solar time conversion. However, it doesn't disclose important behavioral traits like whether this is a computationally intensive operation, potential rate limits, authentication requirements, or error conditions. The description adds some context but leaves significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise with two sentences that each earn their place. The first sentence states the core functionality and output, while the second adds important precision capabilities. There's zero wasted language, and the information is front-loaded with the primary purpose stated immediately.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (8 parameters, astrological calculation), lack of annotations, and no output schema, the description is moderately complete. It covers the core purpose and precision features but doesn't address computational behavior, error handling, or output format details. For a calculation tool with this many parameters and no structured output documentation, more context would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage with detailed parameter documentation, so the baseline is 3. The description adds value by explaining the purpose of longitude/latitude parameters ('用于真太阳时转换' - for true solar time conversion) and mentioning that the tool supports these parameters for more precise calculations. This provides context beyond the schema's technical specifications, though it doesn't add detailed semantics for all parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('计算' - calculate), the resource ('紫微斗数星盘' - Zi Wei Dou Shu astrological chart), and the output ('完整的星盘数据' - complete chart data including twelve houses, stars, brightness). It distinguishes itself from sibling tools like get_current_time and get_horoscope by focusing on detailed astrological calculation rather than time retrieval or general horoscopes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by mentioning support for longitude/latitude parameters and true solar time conversion for more precise calculations, suggesting this tool should be used when geographic precision matters. However, it doesn't explicitly state when to use this versus alternatives (like the sibling get_horoscope tool) or provide exclusion criteria for simpler cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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

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