Skip to main content
Glama
ZoezoeCookie

mcp-luopan

by ZoezoeCookie

mcp-luopan

Turn "Luopan"—a Bazi chart calculation engine based on the Ziping Zhenquan pattern method—into an MCP (Model Context Protocol) toolset, allowing any MCP client (Claude Code / Claude Desktop / OpenClaw / Cursor / custom LLM Agent) to generate charts, read charts, and answer follow-up questions for users within a conversation.

The cloud entry point is live: https://luopan.caihangao.com. MCP points to it by default, ready to use out of the box, no need to run a local server.


What problem does it solve?

LLMs cannot calculate Bazi themselves. Letting models "analyze a chart" directly based on training knowledge is incorrect—Heavenly Stems, Earthly Branches, Monthly Commands, Ten Gods, and pattern determination are all rule-based calculations that must be performed by a specialized engine.

mcp-luopan encapsulates the entire engine (chart generation → Ten Gods → patterns → Da Yun/Luck Cycles → reports → multi-turn follow-ups) into 3 MCP tools, so the LLM no longer hallucinates, but instead:

  1. Obtains accurate chart data (Four Pillars / Patterns / Da Yun / Five Elements / Ten Gods)

  2. Organizes language based on real data (leaves storytelling to the LLM, facts to the engine)

  3. Supports contextual follow-ups (5 follow-ups / 2-hour TTL, managed by backend session)


Related MCP server: Chinese Fortune Analysis System (BaZi)

Typical Use Cases

Scenario A: Analyzing for a friend in Claude Code / Claude Desktop

You (user):

Help me analyze a male born on March 15, 1991, at 5:00 AM, and look at his pattern and career this year.

Claude automatically:

  1. Calls luopan_analyze(year=1991, month=3, day=15, hour=5, gender=1) → gets session_id and the complete chart

  2. Translates "Zheng Guan Pattern / Tian Cheng / Da Yun trend / Spouse profile" into natural language for you

  3. You follow up with "career this year" → Claude calls luopan_chat(session_id, "career this year") → gets an answer tailored to this specific chart

The whole process requires no knowledge of terminology or viewing JSON.

Scenario B: Batch Analysis

You want to run a "distribution of patterns for 100 celebrities":

# 伪代码:让一个 Agent 循环调用
for person in people:
    chart = call_tool("luopan_analyze", **person.birth_info)
    record(person.name, chart["pattern"]["final_pattern"])

The engine is in the cloud, not consuming your local CPU; the script only handles IO orchestration.

Scenario C: Embedding into OpenClaw / Feishu Agent

Register luopan in OpenClaw's mcp.json, authorize these 3 tools to an agent (e.g., a Feishu bot), and the agent can generate charts + answer follow-ups for users in Feishu conversations. The local OpenClaw has already run in this mode; cloud OpenClaw deployment is still TODO.

Scenario D: LLM Eval / Prompt Engineering Experiments

Want to test the language style of different models interpreting charts, or tune the "Luopan persona" for an agent—the backend always returns the same factual data, exposing model differences entirely at the natural language layer.


Quick start: 60 seconds to get started

1. Install

git clone <this-repo> /Users/Neil/Projects/mcp-servers/mcp-luopan
cd /Users/Neil/Projects/mcp-servers/mcp-luopan
uv venv && uv pip install -e .

Or use a standard venv:

python3 -m venv .venv && source .venv/bin/activate
pip install -e .

After installation, there will be an mcp-luopan executable (in .venv/bin/).

2. Smoke test (verify without entering an MCP host)

echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | .venv/bin/mcp-luopan

Expect to see 3 tools: luopan_analyze / luopan_chat / luopan_session_info.

3. Register to an MCP host

Claude Code (currently the most common)

Edit ~/.claude.json or project-level .mcp.json:

{
  "mcpServers": {
    "luopan": {
      "command": "/Users/Neil/Projects/mcp-servers/mcp-luopan/.venv/bin/mcp-luopan",
      "env": {
        "LUOPAN_API_BASE": "https://luopan.caihangao.com",
        "LUOPAN_TIMEOUT_SECONDS": "60"
      }
    }
  }
}

Restart Claude Code, then open a new session and say "Use Luopan to help me look at a chart," and it will call the tools.

OpenClaw (local or cloud)

Add to ~/.openclaw/mcp.json:

"luopan": {
  "command": "/Users/Neil/Projects/mcp-servers/mcp-luopan/.venv/bin/mcp-luopan",
  "env": {
    "LUOPAN_API_BASE": "https://luopan.caihangao.com",
    "LUOPAN_TIMEOUT_SECONDS": "60"
  }
}

To let an agent use it, the agent's tools.allow does not need to explicitly list luopan_*—OpenClaw allows all agents to see all servers in mcp.json by default.

Claude Desktop

Edit ~/Library/Application Support/Claude/claude_desktop_config.json, with the same structure as above.


Semantics of the three tools

All tools return JSON strings. On error, they return {"error": "...", "hint": "..."}, without throwing exceptions to the LLM.

luopan_analyze(year, month, day, hour, gender)

Complete chart analysis—one call produces all information. Before calling, you must: confirm the Gregorian date, birth hour (0-23), and gender (1=male / 0=female) with the user.

Return fields (excerpt):

Field

Content

session_id

12-character short ID, used for subsequent luopan_chat

sizhu

Four Pillars (Heavenly Stems and Earthly Branches of Year/Month/Day/Hour pillars)

pattern

Pattern determination (e.g., "Zheng Guan Pattern / Tian Cheng / followup_remaining=5")

report

Three-tier interpretation (card tier1 / detailed reading tier2 / technical tier3)

dayun

Da Yun timeline + 5-level auspiciousness

highlights

Chart highlights (13 rules, rarity 1-3)

partner

Complementary partner profile (38 sub-patterns × 3 state mappings)

female

Female-specific (husband star/child star/spouse palace, only when gender=0)

wuxing / shishen

Five Elements statistics / Ten Gods relationships

followup_remaining

Remaining follow-up count (default 5)

luopan_chat(session_id, question)

Follow-up on an existing chart. Must be within 2 hours and within 5 turns.

Return (normalized):

{
  "answer": "AI 的回答文本",
  "followup_remaining": 4,
  "followup_count": 1,
  "max_followups": 5,
  "session_id": "..."
}

When followup_remaining == 0 or session_expired is returned, you must call luopan_analyze again to start a new chart.

luopan_session_info(session_id)

Optimistic check of session status—does not hit the backend. The backend does not have an independent session status interface; authoritative determination relies on luopan_chat errors. This tool is an aid for agents to locally maintain "remembering if a session has expired."


Configuration Parameters

Environment Variable

Default Value

Description

LUOPAN_API_BASE

http://127.0.0.1:8000

Backend address. For cloud, use https://luopan.caihangao.com; for local debugging, use http://127.0.0.1:8000 to start uvicorn

LUOPAN_TIMEOUT_SECONDS

60

HTTP timeout. AI analysis occasionally takes 30s+, leave enough margin

LUOPAN_HTTP_RETRIES

1

Retry count for brief network jitters


A complete LLM conversation example

Below is the tool call sequence the LLM should automatically generate (you only need to converse normally):

[user] 我哥 1985 年 8 月 12 日中午 12 点出生,男的,最近老换工作,帮我看看是不是格局问题?

[assistant] (调用 luopan_analyze year=1985 month=8 day=12 hour=12 gender=1)
[tool result]
  session_id=a1b2c3d4e5f6
  pattern=偏财格 / 败格有救(柳暗花明)
  ...

[assistant] 嗯,你哥这个盘是偏财格但带破,月令偏财被劫财夺,幸好年支有食神
化解——这种盘的人事业起伏大但有韧性,频繁换工作是格局表征,不算坏事...

[user] 那今年呢?

[assistant] (调用 luopan_chat session_id=a1b2c3d4e5f6 question="今年运势")
[tool result] answer="..." followup_remaining=4

[assistant] 今年走丙寅大运 + 丙午流年,火土并旺,财星受冲... (汇报答案)
你还可以追问 4 次。

The LLM will not invent astrology, all data comes from luopan_* tools; follow-ups maintain context, and each time it is based on this specific chart.


Troubleshooting

service_unreachable

Backend unreachable. Two most common causes:

  • Local mode uvicorn not started—cd "/Users/Neil/Projects/Four Pillars of Destiny" && .venv/bin/uvicorn src.api.main:app --port 8000

  • Cloud mode network proxy (mihomo / Clash) intercepted caihangao.com—temporarily add "HTTPS_PROXY": "" in the mcp.json env to force disable the proxy; or check the proxy rule whitelist

session_expired

Session exceeded 2h or follow-ups exhausted. Have the LLM call luopan_analyze again to start a new chart.

LLM always wants to "interpret itself" and doesn't call tools

Add a line to the System prompt:

For any questions regarding Bazi/charts/patterns/Ten Gods/Da Yun, you cannot answer based on training data; you must first call luopan_analyze to generate a chart, then use fields like pattern / report / dayun returned by the tool to organize your language.

Day Pillar/Ten Gods in the return are hard to understand

Normal—these are technical terms. Have the LLM read report.tier1 (card tier) and report.tier2 (detailed reading tier) directly; those two tiers are already Chinese narratives for humans; tier3 is the technical layer left for those willing to dig deeper.


Known Limitations

  • Not published to PyPI: Must pip install -e . locally, cannot pip install mcp-luopan

  • Not git-initialized: The current mcp-luopan directory does not have git init, no version management

  • Session stored in memory: Backend uvicorn restart loses all sessions (user must restart the chart)

  • Depends on cloud SiliconFlow: When AI_API_KEY is invalid or SiliconFlow is rate-limited, all chat tools will timeout

  • No concurrency isolation: No guarantee of order when the same session_id is chatted with multiple times simultaneously


How the backend runs (Architecture Overview)

MCP Client (Claude Code / OpenClaw / ...)
   │
   │ stdio (JSON-RPC)
   ▼
mcp-luopan (Python, 这个仓库)
   │
   │ HTTPS
   ▼
luopan.caihangao.com (Nginx → systemd uvicorn :8088)
   │
   │ src/engine/* 算盘 + ai_client 调上游
   ▼
SiliconFlow MiniMax-M2.5

See the upstream project for backend service deployment details: Four Pillars of Destiny / docs/design/deployment.md.

Available Tools

2 tools
luopan_analyzeA

Produce a full destiny-chart reading for a birth moment.

IMPORTANT: Before calling, you MUST confirm with the user:

  • solar calendar date (阳历): year / month / day

  • birth hour 0-23 (时辰),if unsure warn them the reading will be less precise

  • gender: 1 for 男, 0 for 女

Output contains: session_id (used for follow-ups), sizhu (the chart), pattern (格局), report (a three-tier reading), dayun (luck pillars), highlights (notable traits), partner (气场画像), female (if gender=0), and followup_remaining (starts at 5).

When presenting to the user, translate technical terms (e.g. 十神, 格局名称) into plain language like "气场 / 画像 / 此局". The public persona is 罗盘 (fengshui compass), never expose the words 八字 / 子平.

Sessions expire in 2 hours and allow up to 5 follow-up questions via luopan_chat.

Args: year: Birth year, e.g. 1991 month: Birth month 1-12 day: Birth day 1-31 hour: Birth hour 0-23 gender: 1 = 男, 0 = 女

ParametersJSON Schema
NameRequiredDescriptionDefault
yearYes
monthYes
dayYes
hourYes
genderYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.9/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Despite no annotations, the description fully discloses behavioral traits: outputs, session expiration (2 hours), follow-up limit (5), and presentation instructions (translate terms, use persona).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with clear sections (title, note, output, presentation, session info). Slightly lengthy but every sentence adds value; no wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the output schema exists, the description still adds valuable context about follow-ups, session expiration, and output fields. No notable gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but the description explains all 5 parameters with examples and ranges (e.g., year e.g. 1991, month 1-12, day 1-31, hour 0-23, gender 1=男, 0=女). This adds complete meaning beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it produces a full destiny-chart reading for a birth moment. It distinguishes from the sibling tool luopan_chat by mentioning follow-up capability.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly lists pre-call confirmations required from the user, warns about less precise hour, and explains session expiration and follow-up limit. Provides clear guidance on when to use this tool vs luopan_chat.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

luopan_chatA

Ask a follow-up question against an existing chart-reading session.

Session_id comes from a prior luopan_analyze call. The backend enforces a 2-hour TTL and a 5-question cap; when either is hit, call luopan_analyze again to open a new session.

Returns (normalized): answer: the AI reply text followup_remaining: questions you still have left after this one followup_count: questions used so far (incl. this one) max_followups: hard cap (5) session_id: echoed back

When followup_remaining == 0 or this call returns session_expired, the next turn must call luopan_analyze to open a fresh session. When followup_remaining == 1, warn the user before they spend it.

Args: session_id: The session_id returned by luopan_analyze question: The user's follow-up question (specific events / years / topics yield better answers than vague "is my fate good")

ParametersJSON Schema
NameRequiredDescriptionDefault
session_idYes
questionYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description fully discloses behavior: backend-enforced limits, return fields with meanings, and lifecycle management. It clearly states what happens when limits are hit, meeting the full burden for behavioral transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured: purpose statement, runtime constraints, structured return fields, and actionable usage notes. Each sentence earns its place; no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the output schema not provided as structured input, the description enumerates return fields and their meanings. It fully explains the session lifecycle, restrictions, and expected behavior, providing complete context for an AI to use the tool correctly within the sibling ecosystem.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so description must add meaning. It explains session_id comes from prior luopan_analyze, and question provides usage tips ('specific events/years/topics yield better answers'). This adds significant value beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Ask a follow-up question against an existing chart-reading session.' It specifies the resource (session) and verb (ask), and distinguishes from sibling tool luopan_analyze, which starts new sessions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly guides when to use (follow-up questions) and when not to (session expired or followup_remaining==0, then call luopan_analyze). It also details constraints (2-hour TTL, 5-question cap) and gives actionable advice (warn user when remaining==1).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updatesv0.1.0
    • First observedluopan_analyze
    • First observedluopan_chat

TDQS

A5/5.0

Scored across 2 tools

Disambiguation5/5

The two tools have clearly distinct purposes: one creates a new chart-reading session, the other handles follow-up questions within an existing session. There is no overlap or ambiguity.

Naming Consistency5/5

Both tools follow a consistent verb_noun pattern with the prefix 'luopan_' (luopan_analyze, luopan_chat) in snake_case, making them predictable and easy to understand.

Tool Count5/5

With only 2 tools, the server is tightly scoped to its purpose: initial analysis and follow-up chat. No unnecessary tools exist, and the count is perfect for the functionality provided.

Completeness5/5

The tool set covers the complete lifecycle: creating a session with a full chart reading and asking up to 5 follow-up questions. No obvious gaps exist for the intended domain.

Maintenance

ActivityInactive
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    B
    maintenance
    Enables AI tools to perform Chinese fortune-telling analysis including Ziwei Doushu (Purple Star Astrology) and Bazi (Four Pillars) chart generation, fortune reading, and element analysis. Supports multiple calendar systems and output formats for comprehensive divination services.
    7
    4
    6
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables traditional Chinese fortune-telling through BaZi (Four Pillars) analysis, including solar/lunar date conversion, Five Element balance calculations, Ten Gods deduction, and destiny interpretation for metaphysics applications.
    34
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides accurate Chinese Bazi (八字) fortune-telling calculations including birth chart analysis, destiny forecasting, and Chinese calendar information. Addresses inaccuracies in existing AI fortune-telling tools by delivering precise Bazi data for personality analysis and metaphysical insights.
    108
    ISC
  • A
    license
    A
    quality
    C
    maintenance
    Enables AI agents to perform Chinese metaphysics calculations including BaZi charts, Tong Shu indicators, solar terms, and more, using a verified engine with 740+ tests.
    8
    8
    MIT