Skip to main content
Glama
wuunicorn

紫微斗数 MCP 服务器 (MCPIztro)

by wuunicorn

get_horoscope

Calculate personalized Ziwei Doushu horoscope cycles (major and annual fortunes) using birth details, target dates, and location-based true solar time for precise Chinese astrology analysis.

Instructions

获取指定生辰在特定时间的运限信息(大限、流年等)。支持经纬度参数,将时间转换为真太阳时进行更精确的计算

Input Schema

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

Implementation Reference

  • The core handler function for the 'get_horoscope' tool. It calculates the Ziwei Doushu (Purple Star Astrology) horoscope for a given birth date and time, supporting solar/lunar calendars, leap months, language, location-based true solar time correction, and a target date for the horoscope period. Uses the 'iztro' library's astro object to generate astrolabe and horoscope data.
    function getHoroscope(birthday, hour = 0, gender = '男', type = 'solar', isLeapMonth = false, targetDate = null, language = 'zh-CN', longitude = 116.4074, latitude = 39.9042) {
        try {
            // 如果提供了经纬度,进行真太阳时转换
            let actualHour = hour;
            if (longitude !== undefined && latitude !== undefined) {
                const trueSolarTime = convertToTrueSolarTime(hour, 0, longitude, birthday);
                actualHour = trueSolarTime.hour;
            }
    
            // 将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('无法生成星盘数据');
            }
    
            // 如果没有指定目标日期,使用当前日期
            const target = targetDate ? new Date(targetDate) : new Date();
            const horoscope = astrolabe.horoscope(target);
    
            // 直接返回horoscope对象,添加请求参数信息
            const result = {
                ...horoscope,
                requestParams: {
                    birthday: birthday,
                    originalHour: hour,
                    actualHour: actualHour,
                    timeIndex: timeIndex,
                    gender: gender,
                    type: type,
                    isLeapMonth: isLeapMonth,
                    targetDate: target.toISOString().slice(0, 10),
                    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 input schema and metadata (name, description) for the 'get_horoscope' tool as returned in the tools/list MCP method. Defines validation for all parameters including defaults and examples.
        name: "get_horoscope",
        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
                },
                targetDate: {
                    type: "string",
                    description: "目标日期,格式: YYYY-MM-DD,不指定则使用当前日期",
                    examples: ["2024-12-31", "2025-06-15"]
                },
                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 and dispatch logic in the 'tools/call' switch statement. Parses arguments from the MCP call, invokes the getHoroscope handler function, formats the response as MCP content, and handles errors.
    case 'get_horoscope':
        const hBirthday = arguments_.birthday;
        if (hBirthday) {
            try {
                const result = getHoroscope(
                    hBirthday,
                    arguments_.hour || 0,
                    arguments_.gender || '男',
                    arguments_.type || 'solar',
                    arguments_.isLeapMonth || false,
                    arguments_.targetDate || null,
                    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 24-hour time to traditional Chinese 12 'shichen' (时辰) index (0-11), used in horoscope calculations for accurate astrolabe generation.
    function hourToTimeIndex(hour) {
        // 确保hour在0-23范围内
        hour = Math.max(0, Math.min(23, Math.floor(hour)));
    
        // 时辰划分:每个时辰2小时,但子时跨越了23-1点
        if (hour === 23 || hour === 0) {
            return 0; // 子时
        } else {
            // 其他时辰:1-3点为丑时(1),3-5点为寅时(2),依此类推
            return Math.floor((hour + 1) / 2);
        }
    }
  • Helper function to convert local clock time to true solar time based on longitude and approximate equation of time, improving accuracy for birth time in astrology calculations.
    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 };
        }
    }
Behavior2/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. While it mentions that longitude/latitude parameters enable true solar time conversion for more precise calculations, it doesn't describe what type of data is returned (format, structure), whether this is a read-only operation, potential rate limits, authentication requirements, or error conditions. For a 9-parameter tool with no annotation coverage, this is insufficient.

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

Conciseness4/5

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

The description is appropriately concise - two sentences that convey the core functionality and a key feature (true solar time conversion). It's front-loaded with the main purpose. However, the second sentence could be more tightly integrated with the first for better flow.

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

Completeness2/5

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

For a complex tool with 9 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what '运限信息(大限、流年等)' actually returns, the format of results, or how to interpret the output. The description should provide more context about the fortune/luck information being retrieved and what users can expect from the tool's response.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all 9 parameters thoroughly. The description adds minimal value beyond the schema - it mentions that longitude/latitude parameters are used for true solar time conversion, which is already indicated in the schema descriptions. No additional parameter context, constraints, or relationships are provided in the description.

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

Purpose4/5

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

The description clearly states the tool's purpose: '获取指定生辰在特定时间的运限信息(大限、流年等)' - it retrieves fortune/luck information for a specified birth time at a target date. It specifies the resource (birth information) and action (retrieve fortune data). However, it doesn't explicitly differentiate from sibling tools like 'calculate_ziwei' which might be related to Chinese astrology calculations.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It mentions supporting longitude/latitude parameters for true solar time conversion, but doesn't indicate when this tool should be chosen over 'calculate_ziwei' or other potential alternatives. There's no mention of prerequisites, use cases, or exclusion criteria.

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