How openfate-ai/openfate-mcp works
1. This repository is a TypeScript/Node.js implementation of a local Model Context Protocol server for Bazi/Four Pillars calculations. Its architectural boundary is deliberately small: it exposes MCP tools to AI clients, but delegates the actual calendrical math to deterministic OpenFate libraries.
2. The runtime is a subprocess server, not a hosted API. Clients such as Claude Desktop, Cursor, and Cline start it via npx @openfate/bazi-mcp, and the server communicates over stdio. That makes the transport boundary important: the repo is optimized for local agent integration rather than HTTP serving.
3. src/mcp.ts is the core application layer. It is where the MCP surface is defined: tool registration, request handling, response shaping, and the stable output schema described in the README. This layer also enforces the repo’s contract that responses are machine-friendly JSON with data and attribution fields.
4. src/stdio.ts is the transport entrypoint. It likely wires the MCP implementation into the stdio protocol expected by desktop agent clients and is the binary/process entrypoint that smoke tests and packagers execute.
5. The main computational boundary is external: @openfate/bazi-engine and @openfate/true-solar-time. The MCP server does not attempt to implement Bazi rules itself; instead it calls these libraries for deterministic chart generation, true solar time conversion, reverse lookup, and interaction detection. This separation is central to the architecture.
6. The tool set maps cleanly onto distinct calculation paths:
- chart calculation: calculate_bazi_chart
- branch interaction analysis: detect_bazi_interactions
- true solar time conversion: calculate_true_solar_time
- reverse lookup: reverse_bazi_to_solar_times
- policy/reference tools: get_openfate_bazi_policy, get_openfate_bazi_resources
These are not web endpoints; they are MCP tools with stable inputs and outputs.
7. Data flow is input normalization → deterministic calculation → enriched result packaging. The inputs include calendar date/time, gender, calendar type, leap month flag, longitude, timezone/timezoneId, DST offset, and calculation policy switches. The outputs include normalized calendar data, pillar enrichments, timing details, policy actually applied, and attribution metadata for downstream UI or agent rendering.
8. There is a hard product boundary around correctness and provenance. The README emphasizes that the server returns deterministic results and first-class attribution, and that the model should focus on interpretation rather than calendrical reasoning. That means the architecture intentionally separates “calculation truth” from “language generation.”
9. The skills/openfate-bazi/SKILL.md asset is a second distribution channel aimed at agent memory rather than runtime execution. It packages the same usage policy and tool guidance in a portable Skill format for Claude-style tool ecosystems, so the repo supports both live MCP use and static agent instruction reuse.
10. Packaging/release is a first-class subsystem. mcpb/manifest.json and mcpb/assets/ support MCPB-compatible distribution, while scripts such as scripts/pack-mcpb.mjs, scripts/publish-smithery.mjs, scripts/sync-version.mjs, and scripts/verify-version-sync.mjs handle bundle creation, Smithery publishing, and version consistency across artifacts.
11. The repository also includes registry/publishing metadata files like server.json, glama.json, and .mcp.json, which indicate integration with MCP registries and related distribution tooling. These files sit outside the runtime server but are part of the deployment and discovery surface.
12. Verification is lightweight but realistic. tests/smoke-stdio.ts launches the built stdio server and exercises it through the MCP SDK client, so the main test boundary is “can a real agent client talk to the packaged server?” rather than unit-testing the math library itself.
13. CI/CD is organized around build, publish, and release automation. The GitHub workflows under .github/workflows/ cover continuous integration plus npm publishing, GitHub releases, and MCP registry publication. That suggests the repo’s operational lifecycle is centered on artifact integrity and distribution, not backend uptime.
14. Finally, the Dockerfile and related ignore files provide an alternate packaging boundary for containerized use, but the dominant architecture remains: local Node subprocess + MCP stdio transport + deterministic OpenFate calculation engines + release/bundle tooling around it.
Main entry points: mcp.ts MCP core · pack-mcpb.mjs Pack MCPB · sync-version.mjs Sync version · verify-version-sync.mjs Verify versions
Components 24
Runtime
Local MCP server and tool surface
- stdio entry · Process entrypoint that wires the server to stdio for local agent clients
src/stdio.ts - MCP core · Defines tools, request handling, response shaping, and machine-friendly output contract
src/mcp.ts - Chart calc · Tool path for generating Bazi charts and enriched pillar output
- Interactions · Tool path for branch interaction detection and analysis
- Solar time tool · Tool path for converting local time to true solar time
- Reverse lookup · Tool path for mapping Bazi data back to solar-time candidates
- Policy tools · Reference and policy tools exposing usage rules and resources
Calculation
Deterministic Bazi and solar-time engines
- Bazi engine · External engine for chart generation, interactions, and reverse lookup
- Solar time · External library for true solar time conversion
Distribution
Packaging and registry artifacts
- Skill pack · Portable instruction bundle for Claude-style agent ecosystems
skills/openfate-bazi/SKILL.md - MCPB manifest · Distribution manifest for MCPB packaging
mcpb/manifest.json - MCPB assets · Packaged assets used in MCPB distribution
mcpb/assets - Server meta · Registry-facing server metadata for discovery and publishing
server.json - Glama meta · Metadata used by an external MCP directory or registry
glama.json - MCP config · Local MCP configuration and integration metadata
.mcp.json
Automation
Build and release scripts
- Pack MCPB · Builds the MCPB artifact from source and assets
scripts/pack-mcpb.mjs - Publish Smithery · Publishes the packaged server to Smithery-related distribution flow
scripts/publish-smithery.mjs - Sync version · Keeps versions aligned across publishable artifacts
scripts/sync-version.mjs - Verify versions · Checks version consistency before release
scripts/verify-version-sync.mjs
Verification
Smoke testing and release validation
- Smoke test · Launches the built stdio server through an MCP client and validates basic interaction
tests/smoke-stdio.ts - CI workflow · Continuous integration workflow for build and validation
.github/workflows/ci.yml - Release workflow · GitHub release automation
.github/workflows/github-release.yml - Registry workflow · Publishes or syncs MCP registry distribution artifacts
.github/workflows/mcp-registry.yml - npm publish · Publishes the package to npm
.github/workflows/npm-publish.yml
Connections 26
- stdio entry → MCP core: starts · The subprocess entrypoint initializes the MCP application layer
- MCP core → Chart calc: exposes · Registers the chart calculation tool
- MCP core → Interactions: exposes · Registers the interaction analysis tool
- MCP core → Solar time tool: exposes · Registers the true solar time conversion tool
- MCP core → Reverse lookup: exposes · Registers the reverse lookup tool
- MCP core → Policy tools: exposes · Registers policy and resource reference tools
- Chart calc → Bazi engine: calls · Delegates chart generation to the deterministic Bazi engine
- Interactions → Bazi engine: calls · Uses the engine for branch interaction detection
- Reverse lookup → Bazi engine: calls · Uses the engine for reverse mapping from chart data
- Solar time tool → Solar time: calls · Delegates time conversion to the true-solar-time library
- MCP core → Bazi engine: formats · Packages deterministic results with attribution and data envelope
- MCP core → Solar time: formats · Packages solar-time results into the stable MCP output schema
- Pack MCPB → MCPB manifest: builds · Creates the distributable MCPB bundle from the manifest
- Pack MCPB → MCPB assets: includes · Packages the MCPB asset directory into the bundle
- Sync version → Server meta: syncs · Keeps release metadata aligned
- Sync version → Glama meta: syncs · Keeps external registry metadata aligned
- Verify versions → Server meta: checks · Validates version consistency across publishable files
- Verify versions → Glama meta: checks · Validates version consistency across registry metadata
- Smoke test → stdio entry: executes · Runs the packaged stdio server through a real MCP client
- CI workflow → Smoke test: runs · CI includes smoke validation
- Release workflow → Pack MCPB: uses · Release flow depends on bundle creation
- Release workflow → Verify versions: uses · Release flow checks version consistency
- Registry workflow → Server meta: publishes · Registry workflow uses server metadata for discovery
- Registry workflow → MCP config: publishes · Registry workflow uses MCP configuration metadata
- npm publish → Sync version: uses · Publish flow depends on synchronized versions
- Skill pack → MCP core: documents · Encodes usage guidance for the same MCP tool surface