get_bazi_fortune
Calculate Bazi (Four Pillars) fortune readings based on birth details to analyze destiny cycles, annual luck, and elemental influences for personal insight.
Instructions
获取八字运势信息,包含大运、流年等详情
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| birth_date | Yes | 出生日期,格式:YYYY-MM-DD | |
| time_index | Yes | 出生时辰序号(0-12) | |
| gender | Yes | ||
| calendar | No | solar | |
| is_leap_month | No | ||
| query_date | No | 查询运势的日期,格式:YYYY-MM-DD | |
| format | No | markdown | |
| language | No | zh-CN |
Implementation Reference
- mcp/tools/bazi_handlers.py:106-135 (handler)The main handler function executing the tool logic: validates parameters, constructs birth information, retrieves fortune from the Bazi system, and formats the response.@log_performance def handle_get_bazi_fortune(args: Dict[str, Any]) -> str: """工具:获取八字运势""" # Validate parameters _validate_common_params( args, ["birth_date", "time_index", "gender"], BAZI_FORTUNE_PARAM_DESCRIPTIONS, date_key="birth_date", ) with PerformanceTimer("八字运势查询"): birth_info = _build_birth_info(args, date_key="birth_date") query_date_str = args.get("query_date") if query_date_str: query_date = datetime.strptime(query_date_str, "%Y-%m-%d") else: query_date = datetime.now() language = args.get("language", "zh-CN") system = get_system("bazi") fortune = system.get_fortune(birth_info, query_date, language) output_format = args.get("format", "markdown") if output_format == "json": return _format_response(fortune, "json") else: return _bazi_formatter.format_fortune(fortune, "markdown")
- mcp/tools/definitions.py:298-351 (schema)Defines the input schema, description, and annotations for the get_bazi_fortune tool.def get_bazi_fortune_definition() -> Dict[str, Any]: """Get definition for get_bazi_fortune tool""" return { "name": "get_bazi_fortune", "description": "获取八字运势信息,包含大运、流年等详情", "annotations": { "readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, }, "inputSchema": { "type": "object", "properties": { "birth_date": { "type": "string", "description": "出生日期,格式:YYYY-MM-DD", }, "time_index": { "type": "integer", "description": "出生时辰序号(0-12)", "minimum": 0, "maximum": 12, }, "gender": { "type": "string", "enum": ["男", "女"], }, "calendar": { "type": "string", "enum": ["solar", "lunar"], "default": "solar", }, "is_leap_month": { "type": "boolean", "default": False, }, "query_date": { "type": "string", "description": "查询运势的日期,格式:YYYY-MM-DD", }, "format": { "type": "string", "enum": ["json", "markdown"], "default": "markdown", }, "language": { "type": "string", "enum": ["zh-CN", "zh-TW", "en-US", "ja-JP", "ko-KR", "vi-VN"], "default": "zh-CN", }, }, "required": ["birth_date", "time_index", "gender"], }, }
- mcp/tools/__init__.py:37-40 (registration)Registers the get_bazi_fortune handler in the ToolRegistry alongside other Bazi tools.# Bazi tools self.register("get_bazi_chart", handle_get_bazi_chart) self.register("get_bazi_fortune", handle_get_bazi_fortune) self.register("analyze_bazi_element", handle_analyze_bazi_element)
- mcp/tools/definitions.py:406-416 (registration)Includes the get_bazi_fortune definition in the list of all tool definitions used for MCP tools/list.def get_all_tool_definitions() -> List[Dict[str, Any]]: """Get all tool definitions""" return [ get_ziwei_chart_definition(), get_ziwei_fortune_definition(), get_analyze_ziwei_palace_definition(), get_list_fortune_systems_definition(), get_bazi_chart_definition(), get_bazi_fortune_definition(), get_analyze_bazi_element_definition(), ]
- mcp/tools/bazi_handlers.py:66-75 (helper)Helper function used by the handler to construct standardized birth information dictionary.def _build_birth_info(args: Dict[str, Any], date_key: str = "date") -> Dict[str, Any]: """构建生辰信息字典""" return { "date": args[date_key], "time_index": args["time_index"], "gender": args["gender"], "calendar": args.get("calendar", "solar"), "is_leap_month": args.get("is_leap_month", False), }