get_horoscope
Calculate personalized horoscopes for a specified date, time, and location. Use input parameters like datetime, latitude, and longitude to generate astrological insights tailored to individual preferences.
Instructions
ホロスコープを計算して返します
Args:
datetime_str: 計算する日時(YYYY-MM-DD HH:MM:SS形式、省略時は現在時刻)
random_time: ランダムな日時でホロスコープを生成するか
latitude: 緯度(デフォルト: 東京)
longitude: 経度(デフォルト: 東京)
Returns:
ホロスコープの結果
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| datetime_str | No | ||
| latitude | No | ||
| longitude | No | ||
| random_time | No |
Implementation Reference
- fortune_mcp/server.py:131-267 (handler)The complete handler for the 'get_horoscope' tool. It is registered via the @mcp.tool() decorator and implements horoscope calculation including planetary longitudes, ascendant, MC, and major aspects using the swisseph library. Supports custom datetime, random time, and location.@mcp.tool() def get_horoscope( datetime_str: str = None, random_time: bool = False, latitude: float = 35.6895, longitude: float = 139.6917 ) -> str: """ホロスコープを計算して返します Args: datetime_str: 計算する日時(YYYY-MM-DD HH:MM:SS形式、省略時は現在時刻) random_time: ランダムな日時でホロスコープを生成するか latitude: 緯度(デフォルト: 東京) longitude: 経度(デフォルト: 東京) Returns: ホロスコープの結果 """ try: # 日時の取得 jst = pytz.timezone('Asia/Tokyo') if random_time: year = random.randint(1900, 2100) month = random.randint(1, 12) day = random.randint(1, 28) hour = random.randint(0, 23) minute = random.randint(0, 59) second = random.randint(0, 59) jst_dt = jst.localize(datetime(year, month, day, hour, minute, second)) elif datetime_str: try: dt = datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S') jst_dt = jst.localize(dt) except ValueError: try: dt = datetime.strptime(datetime_str, '%Y-%m-%d') jst_dt = jst.localize(dt) except ValueError: return "エラー: 日時は 'YYYY-MM-DD HH:MM:SS' または 'YYYY-MM-DD' 形式で指定してください" else: utc_dt = datetime.now(pytz.utc) jst_dt = utc_dt.astimezone(jst) # UTCに変換 utc_dt = jst_dt.astimezone(pytz.utc) # ユリウス日の計算 jd = swe.julday(utc_dt.year, utc_dt.month, utc_dt.day, utc_dt.hour + utc_dt.minute / 60) # 天体の定義 planets = { '太陽': swe.SUN, '月': swe.MOON, '水星': swe.MERCURY, '金星': swe.VENUS, '火星': swe.MARS, '木星': swe.JUPITER, '土星': swe.SATURN, '天王星': swe.URANUS, '海王星': swe.NEPTUNE, '冥王星': swe.PLUTO, } zodiac_signs = [ ('牡羊座♈', 0), ('牡牛座♉', 30), ('双子座♊', 60), ('蟹座♋', 90), ('獅子座♌', 120), ('乙女座♍', 150), ('天秤座♎', 180), ('蠍座♏', 210), ('射手座♐', 240), ('山羊座♑', 270), ('水瓶座♒', 300), ('魚座♓', 330) ] # 天体位置の計算 positions = {} for name, planet_id in planets.items(): lon = swe.calc_ut(jd, planet_id)[0][0] positions[name] = lon # ハウスの計算 _, asc_mc = swe.houses(jd, latitude, longitude, b'P') positions['アセンダント'] = asc_mc[0] positions['MC(天頂)'] = asc_mc[1] # 結果の整形 result_text = f"🌟 ホロスコープ 🌟\n" result_text += f"日時: {jst_dt.strftime('%Y年%m月%d日 %H:%M:%S')} JST\n" result_text += f"場所: 緯度 {latitude:.4f}, 経度 {longitude:.4f}\n\n" result_text += "【天体位置】\n" for body, lon in positions.items(): sign_index = int(lon / 30) sign_name = zodiac_signs[sign_index][0] degree_in_sign = lon % 30 result_text += f"{body}: {sign_name} {degree_in_sign:.2f}°\n" # アスペクトの計算(主要なもののみ) result_text += "\n【主要アスペクト】\n" aspects_found = [] planet_names = list(planets.keys()) for i in range(len(planet_names)): for j in range(i + 1, len(planet_names)): name1, name2 = planet_names[i], planet_names[j] lon1, lon2 = positions[name1], positions[name2] diff = abs(lon1 - lon2) if diff > 180: diff = 360 - diff # 主要アスペクトのチェック if abs(diff - 0) <= 8: aspects_found.append(f"{name1} - {name2}: コンジャンクション(0°)") elif abs(diff - 60) <= 6: aspects_found.append(f"{name1} - {name2}: セクスタイル(60°)") elif abs(diff - 90) <= 8: aspects_found.append(f"{name1} - {name2}: スクエア(90°)") elif abs(diff - 120) <= 8: aspects_found.append(f"{name1} - {name2}: トライン(120°)") elif abs(diff - 180) <= 8: aspects_found.append(f"{name1} - {name2}: オポジション(180°)") if aspects_found: for aspect in aspects_found[:10]: # 最大10個まで表示 result_text += f"{aspect}\n" else: result_text += "主要アスペクトは検出されませんでした。\n" return result_text except Exception as e: return f"エラーが発生しました: {str(e)}"
- fortune_mcp/server.py:131-131 (registration)The @mcp.tool() decorator registers the get_horoscope function as an MCP tool.@mcp.tool()
- fortune_mcp/server.py:132-147 (schema)Input schema defined by function parameters with type annotations and detailed docstring describing arguments and return value.def get_horoscope( datetime_str: str = None, random_time: bool = False, latitude: float = 35.6895, longitude: float = 139.6917 ) -> str: """ホロスコープを計算して返します Args: datetime_str: 計算する日時(YYYY-MM-DD HH:MM:SS形式、省略時は現在時刻) random_time: ランダムな日時でホロスコープを生成するか latitude: 緯度(デフォルト: 東京) longitude: 経度(デフォルト: 東京) Returns: ホロスコープの結果