# openfate-ai/openfate-mcp architecture

> Architecture diagram of the GitHub repository openfate-ai/openfate-mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openfate-ai/openfate-mcp
- Repository: https://github.com/openfate-ai/openfate-mcp

## Overview

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: [`src/mcp.ts`](https://github.com/openfate-ai/openfate-mcp/blob/main/src/mcp.ts) (MCP core), [`scripts/pack-mcpb.mjs`](https://github.com/openfate-ai/openfate-mcp/blob/main/scripts/pack-mcpb.mjs) (Pack MCPB), [`scripts/sync-version.mjs`](https://github.com/openfate-ai/openfate-mcp/blob/main/scripts/sync-version.mjs) (Sync version), [`scripts/verify-version-sync.mjs`](https://github.com/openfate-ai/openfate-mcp/blob/main/scripts/verify-version-sync.mjs) (Verify versions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_stdio["stdio entry<br/>entrypoint<br/>[stdio.ts]"]
  node_mcp["MCP core<br/>tool server<br/>[mcp.ts]"]
  node_calculate_chart["Chart calc<br/>mcp tool"]
  node_detect_interactions["Interactions<br/>mcp tool"]
  node_solar_time_tool["Solar time tool<br/>mcp tool"]
  node_reverse_lookup["Reverse lookup<br/>mcp tool"]
  node_policy_tools["Policy tools<br/>mcp toolset"]
end

subgraph group_calc["Calculation"]
  node_bazi_engine["Bazi engine<br/>calc lib"]
  node_solar_time["Solar time<br/>calc lib"]
end

subgraph group_distribution["Distribution"]
  node_skill["Skill pack<br/>agent skill<br/>[SKILL.md]"]
  node_mcpb_manifest["MCPB manifest<br/>bundle manifest<br/>[manifest.json]"]
  node_mcpb_assets["MCPB assets<br/>bundle assets"]
  node_server_meta["Server meta<br/>registry metadata<br/>[server.json]"]
  node_glama_meta["Glama meta<br/>registry metadata<br/>[glama.json]"]
  node_mcp_meta["MCP config<br/>registry metadata<br/>[.mcp.json]"]
end

subgraph group_automation["Automation"]
  node_pack_script["Pack MCPB<br/>release script<br/>[pack-mcpb.mjs]"]
  node_smithery_script["Publish Smithery<br/>release script"]
  node_version_sync["Sync version<br/>release script<br/>[sync-version.mjs]"]
  node_version_verify["Verify versions<br/>release script"]
end

subgraph group_verification["Verification"]
  node_smoke_test["Smoke test<br/>integration test<br/>[smoke-stdio.ts]"]
  node_github_ci["CI workflow<br/>github workflow<br/>[ci.yml]"]
  node_github_release["Release workflow<br/>github workflow<br/>[github-release.yml]"]
  node_mcp_registry["Registry workflow<br/>github workflow<br/>[mcp-registry.yml]"]
  node_npm_publish["npm publish<br/>github workflow<br/>[npm-publish.yml]"]
end

node_stdio -->|"starts"| node_mcp
node_mcp -->|"exposes"| node_calculate_chart
node_mcp -->|"exposes"| node_detect_interactions
node_mcp -->|"exposes"| node_solar_time_tool
node_mcp -->|"exposes"| node_reverse_lookup
node_mcp -->|"exposes"| node_policy_tools
node_calculate_chart -->|"calls"| node_bazi_engine
node_detect_interactions -->|"calls"| node_bazi_engine
node_reverse_lookup -->|"calls"| node_bazi_engine
node_solar_time_tool -->|"calls"| node_solar_time
node_mcp -.->|"formats"| node_bazi_engine
node_mcp -.->|"formats"| node_solar_time
node_pack_script -->|"builds"| node_mcpb_manifest
node_pack_script -->|"includes"| node_mcpb_assets
node_version_sync -->|"syncs"| node_server_meta
node_version_sync -->|"syncs"| node_glama_meta
node_version_verify -->|"checks"| node_server_meta
node_version_verify -->|"checks"| node_glama_meta
node_smoke_test -->|"executes"| node_stdio
node_github_ci -->|"runs"| node_smoke_test
node_github_release -->|"uses"| node_pack_script
node_github_release -->|"uses"| node_version_verify
node_mcp_registry -->|"publishes"| node_server_meta
node_mcp_registry -->|"publishes"| node_mcp_meta
node_npm_publish -->|"uses"| node_version_sync
node_skill -.->|"documents"| node_mcp

click node_stdio "https://github.com/openfate-ai/openfate-mcp/blob/main/src/stdio.ts"
click node_mcp "https://github.com/openfate-ai/openfate-mcp/blob/main/src/mcp.ts"
click node_skill "https://github.com/openfate-ai/openfate-mcp/blob/main/skills/openfate-bazi/SKILL.md"
click node_mcpb_manifest "https://github.com/openfate-ai/openfate-mcp/blob/main/mcpb/manifest.json"
click node_mcpb_assets "https://github.com/openfate-ai/openfate-mcp/tree/main/mcpb/assets"
click node_server_meta "https://github.com/openfate-ai/openfate-mcp/blob/main/server.json"
click node_glama_meta "https://github.com/openfate-ai/openfate-mcp/blob/main/glama.json"
click node_mcp_meta "https://github.com/openfate-ai/openfate-mcp/blob/main/.mcp.json"
click node_pack_script "https://github.com/openfate-ai/openfate-mcp/blob/main/scripts/pack-mcpb.mjs"
click node_smithery_script "https://github.com/openfate-ai/openfate-mcp/blob/main/scripts/publish-smithery.mjs"
click node_version_sync "https://github.com/openfate-ai/openfate-mcp/blob/main/scripts/sync-version.mjs"
click node_version_verify "https://github.com/openfate-ai/openfate-mcp/blob/main/scripts/verify-version-sync.mjs"
click node_smoke_test "https://github.com/openfate-ai/openfate-mcp/blob/main/tests/smoke-stdio.ts"
click node_github_ci "https://github.com/openfate-ai/openfate-mcp/blob/main/.github/workflows/ci.yml"
click node_github_release "https://github.com/openfate-ai/openfate-mcp/blob/main/.github/workflows/github-release.yml"
click node_mcp_registry "https://github.com/openfate-ai/openfate-mcp/blob/main/.github/workflows/mcp-registry.yml"
click node_npm_publish "https://github.com/openfate-ai/openfate-mcp/blob/main/.github/workflows/npm-publish.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_stdio,node_mcp,node_calculate_chart,node_detect_interactions,node_solar_time_tool,node_reverse_lookup,node_policy_tools toneBlue
class node_bazi_engine,node_solar_time toneAmber
class node_skill,node_mcpb_manifest,node_mcpb_assets,node_server_meta,node_glama_meta,node_mcp_meta toneMint
class node_pack_script,node_smithery_script,node_version_sync,node_version_verify toneRose
class node_smoke_test,node_github_ci,node_github_release,node_mcp_registry,node_npm_publish toneIndigo
```

## Components

### Runtime

Local MCP server and tool surface

- [stdio entry](https://github.com/openfate-ai/openfate-mcp/blob/main/src/stdio.ts): entrypoint · Process entrypoint that wires the server to stdio for local agent clients · `src/stdio.ts`
- [MCP core](https://github.com/openfate-ai/openfate-mcp/blob/main/src/mcp.ts): tool server · Defines tools, request handling, response shaping, and machine-friendly output contract · `src/mcp.ts`
- **Chart calc**: mcp tool · Tool path for generating Bazi charts and enriched pillar output
- **Interactions**: mcp tool · Tool path for branch interaction detection and analysis
- **Solar time tool**: mcp tool · Tool path for converting local time to true solar time
- **Reverse lookup**: mcp tool · Tool path for mapping Bazi data back to solar-time candidates
- **Policy tools**: mcp toolset · Reference and policy tools exposing usage rules and resources

### Calculation

Deterministic Bazi and solar-time engines

- **Bazi engine**: calc lib · External engine for chart generation, interactions, and reverse lookup
- **Solar time**: calc lib · External library for true solar time conversion

### Distribution

Packaging and registry artifacts

- [Skill pack](https://github.com/openfate-ai/openfate-mcp/blob/main/skills/openfate-bazi/SKILL.md): agent skill · Portable instruction bundle for Claude-style agent ecosystems · `skills/openfate-bazi/SKILL.md`
- [MCPB manifest](https://github.com/openfate-ai/openfate-mcp/blob/main/mcpb/manifest.json): bundle manifest · Distribution manifest for MCPB packaging · `mcpb/manifest.json`
- [MCPB assets](https://github.com/openfate-ai/openfate-mcp/tree/main/mcpb/assets): bundle assets · Packaged assets used in MCPB distribution · `mcpb/assets`
- [Server meta](https://github.com/openfate-ai/openfate-mcp/blob/main/server.json): registry metadata · Registry-facing server metadata for discovery and publishing · `server.json`
- [Glama meta](https://github.com/openfate-ai/openfate-mcp/blob/main/glama.json): registry metadata · Metadata used by an external MCP directory or registry · `glama.json`
- [MCP config](https://github.com/openfate-ai/openfate-mcp/blob/main/.mcp.json): registry metadata · Local MCP configuration and integration metadata · `.mcp.json`

### Automation

Build and release scripts

- [Pack MCPB](https://github.com/openfate-ai/openfate-mcp/blob/main/scripts/pack-mcpb.mjs): release script · Builds the MCPB artifact from source and assets · `scripts/pack-mcpb.mjs`
- [Publish Smithery](https://github.com/openfate-ai/openfate-mcp/blob/main/scripts/publish-smithery.mjs): release script · Publishes the packaged server to Smithery-related distribution flow · `scripts/publish-smithery.mjs`
- [Sync version](https://github.com/openfate-ai/openfate-mcp/blob/main/scripts/sync-version.mjs): release script · Keeps versions aligned across publishable artifacts · `scripts/sync-version.mjs`
- [Verify versions](https://github.com/openfate-ai/openfate-mcp/blob/main/scripts/verify-version-sync.mjs): release script · Checks version consistency before release · `scripts/verify-version-sync.mjs`

### Verification

Smoke testing and release validation

- [Smoke test](https://github.com/openfate-ai/openfate-mcp/blob/main/tests/smoke-stdio.ts): integration test · Launches the built stdio server through an MCP client and validates basic interaction · `tests/smoke-stdio.ts`
- [CI workflow](https://github.com/openfate-ai/openfate-mcp/blob/main/.github/workflows/ci.yml): github workflow · Continuous integration workflow for build and validation · `.github/workflows/ci.yml`
- [Release workflow](https://github.com/openfate-ai/openfate-mcp/blob/main/.github/workflows/github-release.yml): github workflow · GitHub release automation · `.github/workflows/github-release.yml`
- [Registry workflow](https://github.com/openfate-ai/openfate-mcp/blob/main/.github/workflows/mcp-registry.yml): github workflow · Publishes or syncs MCP registry distribution artifacts · `.github/workflows/mcp-registry.yml`
- [npm publish](https://github.com/openfate-ai/openfate-mcp/blob/main/.github/workflows/npm-publish.yml): github workflow · Publishes the package to npm · `.github/workflows/npm-publish.yml`

## Connections

- 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
