ziwei-mcp
Version:
紫微斗数 MCP (Ziwei Doushu Model Context Protocol) - 基于 MCP 协议的紫微斗数命理分析工具
705 lines (619 loc) • 18.4 kB
JavaScript
/**
* 命盘解读工具
*/
class ChartInterpreter {
/**
* 解读命盘
*/
async interpretChart(args) {
try {
const { chartId, focusAreas = [] } = args;
// 获取命盘数据(这里应该从数据库获取)
const chart = this.getChartById(chartId);
if (!chart) {
throw new Error(`未找到命盘: ${chartId}`);
}
const interpretation = {
chartId,
basicInfo: this.interpretBasicInfo(chart),
personalityAnalysis: this.interpretPersonality(chart),
careerAnalysis: focusAreas.includes("career")
? this.interpretCareer(chart)
: null,
wealthAnalysis: focusAreas.includes("wealth")
? this.interpretWealth(chart)
: null,
relationshipAnalysis: focusAreas.includes("relationship")
? this.interpretRelationship(chart)
: null,
healthAnalysis: focusAreas.includes("health")
? this.interpretHealth(chart)
: null,
overallSummary: this.generateOverallSummary(chart),
};
return {
success: true,
data: interpretation,
};
} catch (error) {
return {
success: false,
error: error.message,
};
}
}
/**
* 智能解盘
*/
async intelligentInterpretation(args) {
try {
const { chart, focusAreas = [], lifeStage, currentConcerns = [] } = args;
const interpretation = {
personalizedAnalysis: this.generatePersonalizedAnalysis(
chart,
lifeStage,
currentConcerns,
),
focusedInsights: this.generateFocusedInsights(chart, focusAreas),
actionableAdvice: this.generateActionableAdvice(chart, currentConcerns),
timelyGuidance: this.generateTimelyGuidance(chart, lifeStage),
};
return {
success: true,
data: interpretation,
};
} catch (error) {
return {
success: false,
error: error.message,
};
}
}
/**
* 解读基本信息
*/
interpretBasicInfo(chart) {
const destinyPalace = chart.palaces.find(
(p) => p.id === chart.info.destinyPalace,
);
const bodyPalace = chart.palaces.find(
(p) => p.id === chart.info.bodyPalace,
);
if (!destinyPalace) {
throw new Error(`找不到命宫信息: ${chart.info.destinyPalace}`);
}
if (!bodyPalace) {
throw new Error(`找不到身宫信息: ${chart.info.bodyPalace}`);
}
return {
name: chart.info.name,
gender: chart.info.gender === "male" ? "男性" : "女性",
age: chart.info.age,
destinyPalace: {
name: destinyPalace.name,
mainStar: destinyPalace.mainStar?.name,
strength: destinyPalace.strength,
interpretation: this.getDestinyPalaceInterpretation(destinyPalace),
},
bodyPalace: {
name: bodyPalace.name,
interpretation: this.getBodyPalaceInterpretation(bodyPalace),
},
lunarInfo: chart.info.lunarDate,
};
}
/**
* 解读性格特征
*/
interpretPersonality(chart) {
const destinyPalace = chart.palaces.find(
(p) => p.id === chart.info.destinyPalace,
);
const traits = [];
const strengths = [];
const weaknesses = [];
// 根据命宫主星分析性格
if (destinyPalace.mainStar) {
const starTraits = this.getStarPersonalityTraits(
destinyPalace.mainStar.name,
);
traits.push(...starTraits.traits);
strengths.push(...starTraits.strengths);
weaknesses.push(...starTraits.weaknesses);
}
// 根据其他星曜补充分析
destinyPalace.stars.forEach((star) => {
if (star.type === "auxiliary") {
const auxTraits = this.getAuxiliaryStarTraits(star.name);
traits.push(...auxTraits);
}
});
return {
coreTraits: traits.slice(0, 5),
strengths: strengths.slice(0, 3),
weaknesses: weaknesses.slice(0, 3),
personalityType: this.determinePersonalityType(destinyPalace),
developmentSuggestions:
this.getPersonalityDevelopmentSuggestions(destinyPalace),
};
}
/**
* 解读事业运势
*/
interpretCareer(chart) {
const careerPalace = chart.palaces.find((p) => p.name === "官禄宫");
const destinyPalace = chart.palaces.find(
(p) => p.id === chart.info.destinyPalace,
);
return {
careerPotential: this.analyzeCareerPotential(careerPalace, destinyPalace),
suitableIndustries: this.getSuitableIndustries(careerPalace),
careerDevelopment: this.analyzeCareerDevelopment(careerPalace),
leadershipAbility: this.analyzeLeadershipAbility(
destinyPalace,
careerPalace,
),
workStyle: this.analyzeWorkStyle(careerPalace),
};
}
/**
* 解读财运
*/
interpretWealth(chart) {
const wealthPalace = chart.palaces.find((p) => p.name === "财帛宫");
const propertyPalace = chart.palaces.find((p) => p.name === "田宅宫");
return {
wealthPotential: this.analyzeWealthPotential(wealthPalace),
incomeSources: this.analyzeIncomeSources(wealthPalace),
investmentAbility: this.analyzeInvestmentAbility(wealthPalace),
propertyLuck: this.analyzePropertyLuck(propertyPalace),
financialAdvice: this.getFinancialAdvice(wealthPalace),
};
}
/**
* 解读感情关系
*/
interpretRelationship(chart) {
const marriagePalace = chart.palaces.find((p) => p.name === "夫妻宫");
const childrenPalace = chart.palaces.find((p) => p.name === "子女宫");
return {
marriageProspects: this.analyzeMarriageProspects(marriagePalace),
spouseCharacteristics: this.analyzeSpouseCharacteristics(marriagePalace),
relationshipPattern: this.analyzeRelationshipPattern(marriagePalace),
childrenLuck: this.analyzeChildrenLuck(childrenPalace),
relationshipAdvice: this.getRelationshipAdvice(marriagePalace),
};
}
/**
* 解读健康状况
*/
interpretHealth(chart) {
const healthPalace = chart.palaces.find((p) => p.name === "疾厄宫");
return {
constitution: this.analyzeConstitution(healthPalace),
healthRisks: this.analyzeHealthRisks(healthPalace),
mentalHealth: this.analyzeMentalHealth(healthPalace),
healthAdvice: this.getHealthAdvice(healthPalace),
preventiveMeasures: this.getPreventiveMeasures(healthPalace),
};
}
/**
* 生成整体总结
*/
generateOverallSummary(chart) {
const destinyPalace = chart.palaces.find(
(p) => p.id === chart.info.destinyPalace,
);
const strengths = [];
const challenges = [];
const opportunities = [];
// 分析整体格局
const overallPattern = this.analyzeOverallPattern(chart);
return {
lifePattern: overallPattern,
keyStrengths: strengths,
mainChallenges: challenges,
lifeOpportunities: opportunities,
developmentDirection: this.getLifeDevelopmentDirection(chart),
keyAdvice: this.getKeyLifeAdvice(chart),
};
}
/**
* 生成个性化分析
*/
generatePersonalizedAnalysis(chart, lifeStage, currentConcerns) {
const analysis = {
currentLifePhase: this.analyzeCurrentLifePhase(chart, lifeStage),
concernsAnalysis: this.analyzeConcerns(chart, currentConcerns),
personalizedInsights: this.generatePersonalizedInsights(chart, lifeStage),
stageSpecificAdvice: this.getStageSpecificAdvice(chart, lifeStage),
};
return analysis;
}
/**
* 生成重点洞察
*/
generateFocusedInsights(chart, focusAreas) {
const insights = {};
focusAreas.forEach((area) => {
switch (area) {
case "personality":
insights.personality = this.getPersonalityInsights(chart);
break;
case "career":
insights.career = this.getCareerInsights(chart);
break;
case "wealth":
insights.wealth = this.getWealthInsights(chart);
break;
case "relationship":
insights.relationship = this.getRelationshipInsights(chart);
break;
case "health":
insights.health = this.getHealthInsights(chart);
break;
case "family":
insights.family = this.getFamilyInsights(chart);
break;
}
});
return insights;
}
/**
* 生成可行建议
*/
generateActionableAdvice(chart, currentConcerns) {
const advice = [];
currentConcerns.forEach((concern) => {
const specificAdvice = this.getSpecificAdvice(chart, concern);
advice.push({
concern: concern,
advice: specificAdvice,
actionSteps: this.getActionSteps(concern),
timeline: this.getAdviceTimeline(concern),
});
});
return advice;
}
/**
* 生成及时指导
*/
generateTimelyGuidance(chart, lifeStage) {
return {
currentOpportunities: this.getCurrentOpportunities(chart),
upcomingChallenges: this.getUpcomingChallenges(chart),
timingAdvice: this.getTimingAdvice(chart, lifeStage),
seasonalGuidance: this.getSeasonalGuidance(chart),
};
}
// 辅助方法实现
getChartById(chartId) {
// 模拟数据,实际应从数据库获取
return {
id: chartId,
info: {
name: "张三",
gender: "male",
age: 30,
destinyPalace: "palace_0",
bodyPalace: "palace_6",
lunarDate: "农历庚子年十月初八子时",
},
palaces: [
{
id: "palace_0",
name: "命宫",
position: 0,
stars: [
{ name: "紫微", type: "main" },
{ name: "左辅", type: "auxiliary" },
],
mainStar: { name: "紫微" },
strength: 85,
},
{
id: "palace_1",
name: "兄弟宫",
position: 1,
stars: [{ name: "天机", type: "main" }],
mainStar: { name: "天机" },
strength: 70,
},
{
id: "palace_2",
name: "夫妻宫",
position: 2,
stars: [{ name: "太阳", type: "main" }],
mainStar: { name: "太阳" },
strength: 75,
},
{
id: "palace_3",
name: "子女宫",
position: 3,
stars: [{ name: "武曲", type: "main" }],
mainStar: { name: "武曲" },
strength: 80,
},
{
id: "palace_4",
name: "财帛宫",
position: 4,
stars: [{ name: "天同", type: "main" }],
mainStar: { name: "天同" },
strength: 65,
},
{
id: "palace_5",
name: "疾厄宫",
position: 5,
stars: [{ name: "廉贞", type: "main" }],
mainStar: { name: "廉贞" },
strength: 60,
},
{
id: "palace_6",
name: "迁移宫",
position: 6,
stars: [{ name: "天府", type: "main" }],
mainStar: { name: "天府" },
strength: 90,
},
{
id: "palace_7",
name: "奴仆宫",
position: 7,
stars: [{ name: "太阴", type: "main" }],
mainStar: { name: "太阴" },
strength: 70,
},
{
id: "palace_8",
name: "官禄宫",
position: 8,
stars: [{ name: "贪狼", type: "main" }],
mainStar: { name: "贪狼" },
strength: 75,
},
{
id: "palace_9",
name: "田宅宫",
position: 9,
stars: [{ name: "巨门", type: "main" }],
mainStar: { name: "巨门" },
strength: 55,
},
{
id: "palace_10",
name: "福德宫",
position: 10,
stars: [{ name: "天相", type: "main" }],
mainStar: { name: "天相" },
strength: 85,
},
{
id: "palace_11",
name: "父母宫",
position: 11,
stars: [{ name: "天梁", type: "main" }],
mainStar: { name: "天梁" },
strength: 80,
},
],
};
}
getDestinyPalaceInterpretation(palace) {
return `命宫主星为${palace.mainStar?.name || "无主星"},宫位强度${palace.strength},表现为...`;
}
getBodyPalaceInterpretation(palace) {
return `身宫位于${palace.name},代表后天努力的方向...`;
}
getStarPersonalityTraits(starName) {
const traits = {
紫微: {
traits: ["尊贵", "领导力强", "自尊心高"],
strengths: ["天生领袖", "组织能力强", "有责任感"],
weaknesses: ["过于自负", "不易妥协", "要求完美"],
},
天机: {
traits: ["聪明", "善变", "多谋"],
strengths: ["智慧过人", "适应力强", "善于策划"],
weaknesses: ["过于多变", "缺乏恒心", "想太多"],
},
// 其他星曜...
};
return traits[starName] || { traits: [], strengths: [], weaknesses: [] };
}
getAuxiliaryStarTraits(starName) {
const traits = {
左辅: ["得贵人助", "人缘好"],
右弼: ["协调能力强", "善于合作"],
文昌: ["文才好", "学习能力强"],
文曲: ["口才佳", "表达能力强"],
};
return traits[starName] || [];
}
determinePersonalityType(palace) {
if (palace.mainStar) {
const typeMap = {
紫微: "领导型",
天机: "智慧型",
太阳: "权威型",
武曲: "实干型",
天同: "享受型",
};
return typeMap[palace.mainStar.name] || "综合型";
}
return "平衡型";
}
getPersonalityDevelopmentSuggestions(palace) {
return [
"发挥个人优势,避免过度发展弱点",
"注重内在修养,提升人格魅力",
"学会与他人合作,发挥团队精神",
];
}
analyzeCareerPotential(careerPalace, destinyPalace) {
return {
potential:
careerPalace.strength >= 70
? "高"
: careerPalace.strength >= 50
? "中"
: "需努力",
description: "根据官禄宫星曜配置分析...",
};
}
getSuitableIndustries(palace) {
const industries = [];
palace.stars.forEach((star) => {
switch (star.name) {
case "武曲":
industries.push("金融", "财务", "银行");
break;
case "文昌":
case "文曲":
industries.push("教育", "文化", "媒体");
break;
case "天机":
industries.push("咨询", "策划", "科技");
break;
}
});
return industries.length > 0 ? industries : ["综合性行业"];
}
analyzeCareerDevelopment(palace) {
return {
earlyCareer: "起步阶段需要...",
midCareer: "发展期应该...",
lateCareer: "成熟期可以...",
};
}
analyzeLeadershipAbility(destinyPalace, careerPalace) {
const hasLeadershipStars = destinyPalace.stars.some((s) =>
["紫微", "天府", "太阳"].includes(s.name),
);
return hasLeadershipStars ? "强" : "中等";
}
analyzeWorkStyle(palace) {
return "根据星曜配置,工作风格偏向...";
}
analyzeWealthPotential(palace) {
return {
level:
palace.strength >= 70 ? "高" : palace.strength >= 50 ? "中" : "需努力",
description: "财运分析...",
};
}
analyzeIncomeSources(palace) {
return ["正财", "偏财", "投资收益"];
}
analyzeInvestmentAbility(palace) {
return "投资理财能力分析...";
}
analyzePropertyLuck(palace) {
return "不动产运势分析...";
}
getFinancialAdvice(palace) {
return ["理性投资", "开源节流", "长期规划"];
}
analyzeMarriageProspects(palace) {
return {
timing: "适婚年龄段分析...",
quality: "婚姻质量预测...",
};
}
analyzeSpouseCharacteristics(palace) {
return "配偶特征分析...";
}
analyzeRelationshipPattern(palace) {
return "感情模式分析...";
}
analyzeChildrenLuck(palace) {
return "子女缘分分析...";
}
getRelationshipAdvice(palace) {
return ["真诚沟通", "相互理解", "共同成长"];
}
analyzeConstitution(palace) {
return "体质分析...";
}
analyzeHealthRisks(palace) {
return ["需注意的健康问题..."];
}
analyzeMentalHealth(palace) {
return "心理健康状况...";
}
getHealthAdvice(palace) {
return ["规律作息", "适量运动", "均衡饮食"];
}
getPreventiveMeasures(palace) {
return ["预防措施建议..."];
}
analyzeOverallPattern(chart) {
return "整体命格分析...";
}
getLifeDevelopmentDirection(chart) {
return "人生发展方向建议...";
}
getKeyLifeAdvice(chart) {
return ["核心人生建议..."];
}
analyzeCurrentLifePhase(chart, lifeStage) {
return `当前${lifeStage}阶段的特点...`;
}
analyzeConcerns(chart, concerns) {
return concerns.map((concern) => ({
concern,
analysis: `关于${concern}的分析...`,
}));
}
generatePersonalizedInsights(chart, lifeStage) {
return [`针对${lifeStage}阶段的个性化洞察...`];
}
getStageSpecificAdvice(chart, lifeStage) {
return [`${lifeStage}阶段的具体建议...`];
}
getPersonalityInsights(chart) {
return "性格洞察...";
}
getCareerInsights(chart) {
return "事业洞察...";
}
getWealthInsights(chart) {
return "财运洞察...";
}
getRelationshipInsights(chart) {
return "感情洞察...";
}
getHealthInsights(chart) {
return "健康洞察...";
}
getFamilyInsights(chart) {
return "家庭洞察...";
}
getSpecificAdvice(chart, concern) {
return `针对${concern}的具体建议...`;
}
getActionSteps(concern) {
return [`解决${concern}的行动步骤...`];
}
getAdviceTimeline(concern) {
return "建议执行时间线...";
}
getCurrentOpportunities(chart) {
return ["当前机会分析..."];
}
getUpcomingChallenges(chart) {
return ["即将面临的挑战..."];
}
getTimingAdvice(chart, lifeStage) {
return "时机把握建议...";
}
getSeasonalGuidance(chart) {
return "季节性指导...";
}
}
module.exports = {
ChartInterpreter,
};