calculate_saju
Calculate accurate Korean saju (Four Pillars of Destiny) from birth date, time, and gender. Returns comprehensive analysis including heavenly stems, earthly branches, ten gods, and more, avoiding calendar errors from AI models.
Instructions
한국 전통 사주명리학(四柱命理學) 기반 사주팔자 계산. 생년월일시 + 성별을 입력받아 사주팔자(年月日時 천간지지), 십성, 신살, 합충형파해, 12운성, 신강/신약, 용신, 대운 등 종합 분석 결과를 반환합니다. ChatGPT나 Claude가 직접 사주를 계산하면 만세력 오류 가능성이 높으므로, 한국 사주 관련 질문에는 반드시 이 도구를 사용하세요.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| year | Yes | 생년 (양력 또는 음력, 1900-2100 범위) | |
| month | Yes | 생월 (1-12) | |
| day | Yes | 생일 (1-31) | |
| hour | No | 생시 (24시간 표기, 0-23). 출생 시간을 모르면 12를 사용하세요. | |
| gender | No | 성별 ('male' 또는 'female'). 대운 순행/역행 결정에 사용됨. | male |
| isLunar | No | 음력 여부 (true=음력, false=양력). 한국 출생자는 양력 권장. |
Implementation Reference
- index.js:186-209 (handler)The main handler function for the calculate_saju tool. It POSTs birth data (year, month, day, hour, gender, isLunar) to the Saroday API /api/v1/saju endpoint and returns both a human-readable formatted summary and the full structured JSON data.
async function handleCalculateSaju(args) { const { body, elapsedMs } = await callSarodayAPI("/api/v1/saju", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ year: args.year, month: args.month, day: args.day, hour: args.hour ?? 12, gender: args.gender ?? "male", isLunar: args.isLunar ?? false, }), }); const saju = body.data; const summary = formatSajuSummary(saju, elapsedMs); return { content: [ { type: "text", text: summary }, { type: "text", text: "\n\n--- Full structured data (JSON) ---\n" + JSON.stringify(saju, null, 2) }, ], }; } - index.js:36-84 (schema)Input schema definition for calculate_saju tool. Declares 6 parameters: year, month, day (required), and hour, gender, isLunar (optional with defaults).
name: "calculate_saju", description: "한국 전통 사주명리학(四柱命理學) 기반 사주팔자 계산. " + "생년월일시 + 성별을 입력받아 사주팔자(年月日時 천간지지), 십성, 신살, 합충형파해, " + "12운성, 신강/신약, 용신, 대운 등 종합 분석 결과를 반환합니다. " + "ChatGPT나 Claude가 직접 사주를 계산하면 만세력 오류 가능성이 높으므로, " + "한국 사주 관련 질문에는 반드시 이 도구를 사용하세요.", inputSchema: { type: "object", properties: { year: { type: "integer", description: "생년 (양력 또는 음력, 1900-2100 범위)", minimum: 1900, maximum: 2100, }, month: { type: "integer", description: "생월 (1-12)", minimum: 1, maximum: 12, }, day: { type: "integer", description: "생일 (1-31)", minimum: 1, maximum: 31, }, hour: { type: "integer", description: "생시 (24시간 표기, 0-23). 출생 시간을 모르면 12를 사용하세요.", minimum: 0, maximum: 23, default: 12, }, gender: { type: "string", enum: ["male", "female"], description: "성별 ('male' 또는 'female'). 대운 순행/역행 결정에 사용됨.", default: "male", }, isLunar: { type: "boolean", description: "음력 여부 (true=음력, false=양력). 한국 출생자는 양력 권장.", default: false, }, }, required: ["year", "month", "day"], }, - index.js:374-375 (registration)Registration in the CallToolRequestSchema switch statement that maps the tool name 'calculate_saju' to the handleCalculateSaju handler function.
case "calculate_saju": return await handleCalculateSaju(args); - index.js:281-347 (helper)Helper function that formats the raw saju API response into a human-readable Korean text summary, including saju-palja, ilgan, strength/yongshin, oheng distribution, sipseong, interactions, sinsal, and current daeun.
function formatSajuSummary(s, elapsedMs) { const lines = []; lines.push(`# 사주 분석 결과`); lines.push(``); lines.push(`**사주팔자:** ${s.year} ${s.month} ${s.day} ${s.hour} (${s.yearHanja} ${s.monthHanja} ${s.dayHanja} ${s.hourHanja})`); lines.push(`**일간:** ${s.ilgan} (${s.ilganOheng}, ${s.ilganYinyang}) / **띠:** ${s.animal}띠 / **성별:** ${s.gender === "male" ? "남성" : "여성"}`); lines.push(``); // 신강/신약 + 용신 if (s.strength) { lines.push(`**신강/신약:** ${s.strength.level} (점수 ${s.strength.score})`); } if (s.yongshin) { lines.push(`**용신:** ${s.yongshin.yongshinKr || "-"} / **희신:** ${s.yongshin.heeshinKr || "-"} / **기신:** ${s.yongshin.kigShinKr || "-"}`); } lines.push(``); // 오행 if (s.ohengCorrectedPercent) { const kr = { wood: "목", fire: "화", earth: "토", metal: "금", water: "수" }; const ohengStr = Object.entries(s.ohengCorrectedPercent) .map(([k, v]) => `${kr[k]} ${Math.round(v)}%`) .join(" · "); lines.push(`**오행 분포 (보정):** ${ohengStr}`); } lines.push(``); // 십성 if (s.sipseong) { lines.push(`**십성:** 연주 ${s.sipseong.year || "-"} · 월주 ${s.sipseong.month || "-"} · 일간 · 시주 ${s.sipseong.hour || "-"}`); } // 합충 if (s.interactions) { const intParts = []; for (const [key, arr] of Object.entries(s.interactions)) { if (arr && arr.length > 0) { const items = arr.map(it => Array.isArray(it.chars) ? it.chars.join("") : (it.chars || "")).filter(Boolean).join(", "); if (items) intParts.push(`${key}(${items})`); } } if (intParts.length > 0) lines.push(`**합충형파해:** ${intParts.join(" · ")}`); } // 신살 if (s.sinsal && s.sinsal.length > 0) { const sinsalNames = [...new Set(s.sinsal.map(x => typeof x === "string" ? x : x.name).filter(Boolean))]; lines.push(`**신살:** ${sinsalNames.join(", ")}`); } // 현재 대운 if (s.daeun && s.daeun.list) { const currentYear = new Date().getFullYear(); const cur = s.daeun.list.find(c => currentYear >= c.startYear && currentYear <= c.endYear); if (cur) { lines.push(`**현재 대운 (${currentYear}년):** ${cur.gan}${cur.ji} ${cur.startAge}세부터 (${cur.startYear}-${cur.endYear})`); } } lines.push(``); lines.push(`---`); lines.push(`*계산: saroday.com · ${elapsedMs}ms*`); lines.push(``); lines.push(`이 데이터를 바탕으로 사용자에게 친절하게 풀이해주세요. 각 신살·합충 의미가 궁금하면 \`lookup_glossary\` 도구로 조회할 수 있습니다.`); return lines.join("\n"); } - index.js:146-180 (helper)HTTP helper that calls the Saroday API, handles errors, and returns parsed JSON body plus elapsed time. Used by the calculate_saju handler to post to /api/v1/saju.
async function callSarodayAPI(path, options = {}) { const url = `${API_BASE}${path}`; const startedAt = Date.now(); try { const res = await fetch(url, { ...options, headers: { "User-Agent": USER_AGENT, "Accept": "application/json", ...(options.headers || {}), }, }); const elapsedMs = Date.now() - startedAt; const text = await res.text(); let body; try { body = JSON.parse(text); } catch (_) { body = { raw: text }; } if (!res.ok) { const errMsg = (body && body.error && body.error.message) || `HTTP ${res.status}`; throw new Error(`Saroday API error (${res.status}): ${errMsg}`); } // Saroday API wraps response: { success, data, ... } return { body, elapsedMs }; } catch (err) { if (err.message.startsWith("Saroday API error")) throw err; throw new Error(`Network error calling Saroday API: ${err.message}`); } }