get_horoscope
Generate personalized Chinese Ziwei Doushu horoscope readings by analyzing specific birth details (date, time, gender) and target dates to uncover detailed life cycle insights such as major and yearly fortunes.
Instructions
获取指定生辰在特定时间的运限信息(大限、流年等)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| birthday | Yes | 生日,格式: YYYY-MM-DD | |
| gender | No | 性别 | 男 |
| hour | No | 出生时辰(0-23) | |
| isLeapMonth | No | 是否闰月(仅农历有效) | |
| language | No | 语言设置 | zh-CN |
| targetDate | No | 目标日期,格式: YYYY-MM-DD,不指定则使用当前日期 | |
| type | No | 日期类型 | solar |
Implementation Reference
- ziwei_mcp_server.js:197-247 (handler)The core handler function that generates the horoscope (运限信息) for the given birth details, using the iztro library. Supports true solar time conversion via longitude/latitude.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 }; } }
- ziwei_mcp_server.js:364-425 (schema)Input schema definition for the get_horoscope tool, specifying parameters like birthday, hour, gender, etc., with types, descriptions, 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 }, 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"] }
- ziwei_mcp_server.js:361-426 (registration)Tool registration in the MCP tools/list response, including name, description, and input schema.{ 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"] } }
- ziwei_mcp_server.js:506-549 (registration)Dispatch handler in the tools/call switch statement that invokes the getHoroscope function with parsed arguments.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;
- ziwei_mcp_server.js:21-32 (helper)Helper function to convert 24-hour time to Chinese 12 Shichen (时辰) index used in horoscope calculation.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); } }