ming_bazi_analyze
Compute a complete BaZi (Four Pillars of Destiny) chart including Day Master analysis, pattern classification, decade luck pillars, and annual outlook. Optional question feature for targeted readings.
Instructions
Compute a full BaZi (Four Pillars of Destiny 八字) chart. Returns Day Master analysis, pattern classification (格局), decade luck pillars (大运), and annual outlook. Engine verified against 子平真詮 and 淵海子平. Requires Ming engine running at MING_API_URL.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| birth_date | Yes | Date of birth in YYYY-MM-DD format. Must be after 1900-01-01. | |
| birth_hour | No | Hour of birth in 24-hour format (0–23). If unknown, omit — analysis will note the limitation. | |
| birth_location | No | City and country of birth (e.g. 'Singapore, Singapore'). Provides timezone context. | |
| gender | Yes | Gender determines luck pillar direction (forward for males in yang years, backward for females). | |
| question | No | Optional. Specific question to orient the reading (e.g. 'Is 2026 good for a career change?'). |
Implementation Reference
- src/tools/bazi.ts:47-55 (handler)The handler function that executes the ming_bazi_analyze tool logic. It calls analyzeBazi() from engines-client with birth_date, birth_hour, and gender, then returns the result as JSON.
handler: async (args) => { const result = await analyzeBazi({ date: args.birth_date as string, hour: (args.birth_hour as number) ?? 12, gender: args.gender as string, }); return JSON.stringify(result, null, 2); }, }; - src/tools/bazi.ts:4-44 (schema)The inputSchema definition for ming_bazi_analyze. Defines five parameters: birth_date (required), birth_hour (optional), birth_location (optional), gender (required, enum male/female), and question (optional).
export const baziTool: MingTool = { definition: { name: "ming_bazi_analyze", description: "Compute a full BaZi (Four Pillars of Destiny 八字) chart. Returns Day Master analysis, " + "pattern classification (格局), decade luck pillars (大运), and annual outlook. " + "Engine verified against 子平真詮 and 淵海子平. Requires Ming engine running at MING_API_URL.", inputSchema: { type: "object", properties: { birth_date: { type: "string", format: "date", description: "Date of birth in YYYY-MM-DD format. Must be after 1900-01-01.", }, birth_hour: { type: "integer", minimum: 0, maximum: 23, description: "Hour of birth in 24-hour format (0–23). If unknown, omit — analysis will note the limitation.", }, birth_location: { type: "string", description: "City and country of birth (e.g. 'Singapore, Singapore'). Provides timezone context.", }, gender: { type: "string", enum: ["male", "female"], description: "Gender determines luck pillar direction (forward for males in yang years, backward for females).", }, question: { type: "string", description: "Optional. Specific question to orient the reading (e.g. 'Is 2026 good for a career change?').", }, }, required: ["birth_date", "gender"], }, - src/tools/index.ts:1-16 (registration)The tool registration point where baziTool is exported and included in the TOOLS array that gets imported by index.ts for the ListToolsRequestSchema handler.
export { baziTool } from "./bazi.js"; export { qmdjTool } from "./qmdj.js"; export { zwdsTool } from "./zwds.js"; export { fengshuiTool } from "./fengshui.js"; export { ichingTool } from "./iching.js"; export { forecastTool } from "./forecast.js"; export type { MingTool } from "./types.js"; import { baziTool } from "./bazi.js"; import { qmdjTool } from "./qmdj.js"; import { zwdsTool } from "./zwds.js"; import { fengshuiTool } from "./fengshui.js"; import { ichingTool } from "./iching.js"; import { forecastTool } from "./forecast.js"; export const TOOLS = [baziTool, qmdjTool, zwdsTool, fengshuiTool, ichingTool, forecastTool]; - src/engines-client.ts:40-54 (helper)The analyzeBazi helper function that makes an HTTP POST request to the Ming engine's /analyze endpoint with the BaZi parameters.
export interface BaziParams { date: string; hour: number; gender: string; } export async function analyzeBazi(params: BaziParams): Promise<unknown> { const res = await fetch(`${API_URL}/analyze`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ date: params.date, hour: params.hour, gender: params.gender }), signal: AbortSignal.timeout(TIMEOUT_MS), }); return handleResponse(res, "/analyze"); } - src/index.ts:45-69 (registration)The MCP server's CallToolRequestSchema handler that dispatches incoming tool calls by name, routing to the appropriate tool's handler function.
server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; const tool = TOOLS.find((t) => t.definition.name === name); if (!tool) { throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`); } try { const text = await tool.handler((args ?? {}) as Record<string, unknown>); return { content: [{ type: "text" as const, text }] }; } catch (err) { const message = err instanceof Error ? err.message : String(err); // Return structured error — don't expose raw stack traces to the client return { content: [ { type: "text" as const, text: JSON.stringify({ error: true, tool: name, message }, null, 2), }, ], isError: true, }; } });