@dangamsoft/cafe-mcp 0.0.1 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +161 -7
  3. package/index.js +205 -0
  4. package/package.json +19 -2
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,14 +1,168 @@
1
- # @dangamsoft/cafe-mcp
1
+ # cafe-mcp
2
2
 
3
- Korean Saju (Four Pillars) MCP server **coming soon**.
3
+ > **CAFE = Cross-weighted Analysis of the Five Elements**
4
+ >
5
+ > Public OWL ontology for Korean Saju (사주명리학),
6
+ > with planned MCP integration via the CAFE engine.
4
7
 
5
- This is a placeholder. The actual MCP server implementation will be released in v0.6.0.
8
+ [![MCP](https://img.shields.io/badge/MCP-planned-blue.svg)](https://modelcontextprotocol.io)
9
+ [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](LICENSE)
10
+ [![W3C OWL 2](https://img.shields.io/badge/W3C-OWL%202-orange.svg)](https://www.w3.org/TR/owl2-overview/)
11
+ [![Ontology](https://img.shields.io/badge/Ontology-1%2C711%20triples-brightgreen.svg)](./ontology/)
12
+ [![Version](https://img.shields.io/badge/Version-0.6.1-green.svg)](#)
6
13
 
7
- For the public ontology (1,711 RDF triples · 18 patterns · 75 sinsal · CC BY 4.0)
8
- and roadmap, see the GitHub repository:
14
+ > **v0.6.0** The MCP server is live. A local (stdio) server exposing
15
+ > **5 free birth-chart tools** — `saju_chart`, `ohaeng_balance`, `gyeokguk`,
16
+ > `eumyang_johu`, `yongshin_candidates` — alongside the public W3C OWL
17
+ > ontology. See **[Install](#install-mcp-server)** below.
9
18
 
10
- 🔗 https://github.com/dangamsoft/cafe-mcp
19
+ ---
20
+
21
+ ## What this is
22
+
23
+ A formal W3C OWL 2 ontology for Korean Saju (사주명리학), grounded in
24
+ classical Myeongli theory and six canonical treatises. Released under
25
+ CC BY 4.0 for academic use, system integration, and downstream development.
26
+
27
+ The ontology is the public layer of the **CAFE engine** — a deterministic
28
+ Saju analysis system combining classical theory with ML-based yongshin
29
+ classification.
30
+
31
+ W3C OWL 2 온톨로지 형태로 공개된 한국 사주명리학 도메인 모델입니다.
32
+ 6대 고전(적천수·자평진전·난강망·궁통보감·연해자평·삼명통회)에 근거하며,
33
+ CC BY 4.0으로 학술·시스템 통합·후속 개발에 자유롭게 사용할 수 있습니다.
34
+
35
+ 이 온톨로지는 **CAFE 엔진**의 공개 레이어입니다 — 결정적(deterministic)
36
+ 사주 분석 시스템으로, 명리학 고전 이론과 ML 기반 용신 분류를 결합합니다.
37
+
38
+ ---
39
+
40
+ ## Install (MCP server)
41
+
42
+ The server runs locally over stdio and talks to the hosted CAFE backend —
43
+ **no API key, no local engine, no database** required.
44
+
45
+ **Claude Desktop** — add to `claude_desktop_config.json`:
46
+
47
+ ```json
48
+ {
49
+ "mcpServers": {
50
+ "cafe-mcp": {
51
+ "command": "npx",
52
+ "args": ["-y", "@dangamsoft/cafe-mcp"]
53
+ }
54
+ }
55
+ }
56
+ ```
57
+
58
+ **Cursor** — add the same `mcpServers` entry to `~/.cursor/mcp.json`.
59
+
60
+ Then ask, e.g. *"Show my saju for 1990-01-15 10:30, male."*
61
+
62
+ ### Tools (5, free)
63
+
64
+ | Tool | Returns |
65
+ |------|---------|
66
+ | `saju_chart` | Four Pillars chart — stems/branches, Ten Gods, Spirit Stars |
67
+ | `ohaeng_balance` | Five Elements (五行) distribution |
68
+ | `gyeokguk` | Chart structure/pattern (格局) |
69
+ | `eumyang_johu` | Yin-Yang & Climate (陰陽·調候) balance |
70
+ | `yongshin_candidates` | Classical 5-type Yongshin (用神) candidates |
71
+
72
+ All tools take `birth` (`YYYYMMDDHHMM`) and `gender` (0 = female, 1 = male);
73
+ `name` and `is_lunar` are optional.
74
+
75
+ > The AI-selected final Yongshin (91.1%-accuracy classifier), full Yongshin
76
+ > report, NCODE personality profile and AI naming are part of the
77
+ > 24Plus service and are **not** exposed here.
78
+
79
+ **Custom backend:** set `CAFE_MCP_API_URL` (the server POSTs to
80
+ `${CAFE_MCP_API_URL}/try/panels`; default `https://24plus.ai.kr/api`).
81
+
82
+ ---
83
+
84
+ ## Ontology
85
+
86
+ - **1,711 RDF triples** · SPARQL-queryable · W3C OWL 2 conformant
87
+ - Models:
88
+ - 60갑자 (Sexagenary cycle)
89
+ - 75 sinsal (special-star annotations)
90
+ - **18 patterns** — 정격 10 + 특수격 8
91
+ - 5 yongshin types — 격국·억부·병약·조후·통관
92
+ - 12 life stages (12운성)
93
+ - Grounded in 6 classical treatises:
94
+ - 적천수 (Diqianshui)
95
+ - 자평진전 (Zipingzhenquan)
96
+ - 난강망 (Lanjiangwang)
97
+ - 궁통보감 (Qiongtongbaojian)
98
+ - 연해자평 (Yuanhaiziping)
99
+ - 삼명통회 (Sanmingtonghui)
100
+
101
+ See [`ontology/`](./ontology/) for module structure, SPARQL examples, and
102
+ the integrated turtle file (`cafe-ontology.ttl`).
103
+
104
+ ---
105
+
106
+ ## CAFE engine performance
107
+
108
+ The CAFE engine — the inference system this ontology models — operates
109
+ inside the 24Plus platform. Validated performance on 5-class yongshin
110
+ classification (목/화/토/금/수, 5-fold cross-validated):
111
+
112
+ | Metric | Result |
113
+ |-------------------------|----------|
114
+ | Accuracy | 91.10% |
115
+ | F1-Score (Macro) | 91.08% |
116
+ | Precision (Macro) | 91.16% |
117
+ | Recall (Macro) | 91.10% |
118
+ | ROC AUC (Macro) | 97.76% |
119
+
120
+ Random baseline = 20% (5 classes). 4.56× better than random. ML ensemble
121
+ with weighted voting and probability calibration.
122
+
123
+ The engine itself remains proprietary; the ontology models the domain
124
+ structure it operates on.
125
+
126
+ ---
127
+
128
+ ## Note on East Asian Myeongli traditions
129
+
130
+ This MCP focuses on the Korean Myeongli (사주명리학) tradition, which
131
+ shares its classical roots — 子平眞詮 (Zipingzhenquan), 滴天髓 (Diqianshui),
132
+ 窮通寶鑑 (Qiongtongbaojian), 淵海子平 (Yuanhaiziping), 三命通會 (Sanmingtonghui),
133
+ 欄江網 (Lanjiangwang) — with the Chinese Bazi (八字) tradition.
134
+
135
+ Romanization uses Korean Revised Romanization (e.g., Yongshin, Sinsal).
136
+ Hanja (정자) is preserved throughout the ontology.
137
+
138
+ 본 MCP는 한국 명리학(사주명리학) 전통에 기반하며, 중국 八字 전통과
139
+ 6대 고전(자평진전·적천수·궁통보감·연해자평·삼명통회·난강망)을 공유합니다.
140
+
141
+ ---
142
+
143
+ ## Documentation
144
+
145
+ - 📖 [Ontology specification](./ontology/) — formal OWL ontology with SPARQL examples
146
+
147
+ ---
148
+
149
+ ## Built by
150
+
151
+ [Dangamsoft (단감소프트)](https://24plus.ai.kr) — Korean AI company
152
+ specializing in classical East Asian knowledge systems.
153
+
154
+ 🌐 https://24plus.ai.kr
155
+
156
+ ---
157
+
158
+ ## License
159
+
160
+ - **Code** (when published in v0.6.0): Apache 2.0
161
+ - **Public OWL ontology** ([`ontology/`](./ontology/)): CC BY 4.0
162
+
163
+ The CAFE inference engine, scoring algorithms, ML model weights, and
164
+ interpretation templates remain proprietary.
11
165
 
12
166
  ---
13
167
 
14
- Built by [Dangamsoft (단감소프트)](https://24plus.ai.kr).
168
+ > 깊은 분석(AI 선정 용신 · 전체 리포트)https://24plus.ai.kr
package/index.js ADDED
@@ -0,0 +1,205 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @dangamsoft/cafe-mcp — Korean Saju (四柱八字 / 사주명리) MCP server.
4
+ *
5
+ * A thin, stdio MCP server that exposes a FIXED set of 5 free analysis tools.
6
+ * Each tool forwards to the 24Plus backend endpoint `POST /try/panels`, which
7
+ * returns panel-extracted (safe) data only — never raw engine output.
8
+ *
9
+ * Design / safety invariants (do not weaken):
10
+ * 1. Free-5 allowlist is HARD-CODED below (tool -> preset). There is NO
11
+ * generic "preset" parameter, so a client can never request a paid
12
+ * preset (yongshin / ncode / cafe_ucode / naming) through this server.
13
+ * 2. The backend /try/panels gates on the 'try' channel AND returns only
14
+ * extracted panels (raw tool_result, AI-selected yongshin, model
15
+ * probabilities and the 91.1% metric are NOT included).
16
+ * 3. No API key / engine / DB is bundled. This process only makes HTTPS
17
+ * calls to the public backend.
18
+ *
19
+ * Config:
20
+ * CAFE_MCP_API_URL Base URL of the 24Plus backend (default below).
21
+ * The server POSTs to `${CAFE_MCP_API_URL}/try/panels`.
22
+ */
23
+
24
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
25
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
26
+ import {
27
+ CallToolRequestSchema,
28
+ ListToolsRequestSchema,
29
+ } from "@modelcontextprotocol/sdk/types.js";
30
+
31
+ const API_BASE = (process.env.CAFE_MCP_API_URL || "https://24plus.ai.kr/api").replace(/\/+$/, "");
32
+ const ENDPOINT = `${API_BASE}/try/panels`;
33
+ const REQUEST_TIMEOUT_MS = 15000;
34
+
35
+ // Appended as plain TEXT after the panels JSON on every successful tool
36
+ // response. This does NOT modify the backend payload or the `panels` data —
37
+ // the wrapper only adds an output-text line. Handled once here, not per-tool.
38
+ const FUNNEL_NOTE =
39
+ "— 더 깊은 분석(AI 선정 용신 · 전체 리포트)은 https://24plus.ai.kr";
40
+
41
+ // Shared input schema for all 5 tools (birth chart inputs).
42
+ const BIRTH_INPUT = {
43
+ type: "object",
44
+ properties: {
45
+ birth: {
46
+ type: "string",
47
+ description: "Birth date & time, 12 digits YYYYMMDDHHMM (e.g. 199001151030). Use 1230 for unknown time.",
48
+ },
49
+ gender: {
50
+ type: "integer",
51
+ enum: [0, 1],
52
+ description: "Gender — 0: female, 1: male (CAFE convention).",
53
+ },
54
+ name: {
55
+ type: "string",
56
+ description: "Optional name. Affects some engine outputs; omit to use the default.",
57
+ },
58
+ is_lunar: {
59
+ type: "boolean",
60
+ description: "Optional. true if the birth date is a lunar-calendar date (default false = solar).",
61
+ },
62
+ },
63
+ required: ["birth", "gender"],
64
+ };
65
+
66
+ /**
67
+ * Free-5 allowlist. tool name -> { preset, description }.
68
+ * preset values MUST be 'try'+'mcp' channel free presets in the backend registry.
69
+ * Adding a paid preset here would defeat the BM separation — do not.
70
+ */
71
+ const TOOLS = [
72
+ {
73
+ name: "saju_chart",
74
+ preset: "saju",
75
+ description:
76
+ "Korean Saju (Four Pillars / 四柱八字) birth chart. Returns the four pillars (year/month/day/hour), heavenly stems & earthly branches, and the Ten Gods / Spirit-Star overview. Use for 'show me my saju / birth chart'.",
77
+ },
78
+ {
79
+ name: "ohaeng_balance",
80
+ preset: "saju_ohang",
81
+ description:
82
+ "Five Elements (五行 / 오행: Wood·Fire·Earth·Metal·Water) distribution of the birth chart, including hidden-stem weighting. Use for 'analyze my five elements / element balance'.",
83
+ },
84
+ {
85
+ name: "gyeokguk",
86
+ preset: "gyeokguk",
87
+ description:
88
+ "Gyeokguk (格局, chart structure/pattern) determination with the supporting chart table. Use for 'what is my gyeokguk / chart pattern'.",
89
+ },
90
+ {
91
+ name: "eumyang_johu",
92
+ preset: "eumyang",
93
+ description:
94
+ "Yin-Yang (陰陽 / 음양) and Climate (調候 / 조후, hot-cold-wet-dry) balance diagnostic, including how it shifts across major/yearly fortune periods. Use for 'yin-yang / climate balance'.",
95
+ },
96
+ {
97
+ name: "yongshin_candidates",
98
+ preset: "yongshin_candidates",
99
+ description:
100
+ "Classical Yongshin (用神, favorable element) CANDIDATES — the 5 traditional types (Eokbu / Byeongyak / Tonggwan / Johu / Gyeokguk) and their candidate elements. This is the classical-theory view; it does NOT include an AI-selected final yongshin or confidence scores. Use for 'what are my yongshin candidates'.",
101
+ },
102
+ ];
103
+
104
+ const TOOL_BY_NAME = new Map(TOOLS.map((t) => [t.name, t]));
105
+
106
+ const server = new Server(
107
+ { name: "cafe-mcp", version: "0.6.1" },
108
+ { capabilities: { tools: {} } }
109
+ );
110
+
111
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
112
+ tools: TOOLS.map((t) => ({
113
+ name: t.name,
114
+ description: t.description,
115
+ inputSchema: BIRTH_INPUT,
116
+ })),
117
+ }));
118
+
119
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
120
+ const { name, arguments: args = {} } = request.params;
121
+ const tool = TOOL_BY_NAME.get(name);
122
+
123
+ // Allowlist enforcement — unknown / non-free tool names are rejected here.
124
+ if (!tool) {
125
+ return {
126
+ isError: true,
127
+ content: [{ type: "text", text: `Unknown tool: ${name}` }],
128
+ };
129
+ }
130
+
131
+ if (!args.birth || args.gender === undefined || args.gender === null) {
132
+ return {
133
+ isError: true,
134
+ content: [
135
+ { type: "text", text: "Required: 'birth' (YYYYMMDDHHMM) and 'gender' (0=female, 1=male)." },
136
+ ],
137
+ };
138
+ }
139
+
140
+ // preset is fixed by the tool — never taken from client input.
141
+ const body = {
142
+ preset: tool.preset,
143
+ birth: String(args.birth),
144
+ gender: Number(args.gender),
145
+ name: typeof args.name === "string" ? args.name : "",
146
+ is_lunar: Boolean(args.is_lunar),
147
+ };
148
+
149
+ const controller = new AbortController();
150
+ const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
151
+ try {
152
+ const res = await fetch(ENDPOINT, {
153
+ method: "POST",
154
+ headers: { "Content-Type": "application/json" },
155
+ body: JSON.stringify(body),
156
+ signal: controller.signal,
157
+ });
158
+
159
+ const text = await res.text();
160
+ if (!res.ok) {
161
+ return {
162
+ isError: true,
163
+ content: [
164
+ { type: "text", text: `Backend error ${res.status} for tool '${name}': ${text.slice(0, 500)}` },
165
+ ],
166
+ };
167
+ }
168
+
169
+ let payload;
170
+ try {
171
+ payload = JSON.parse(text);
172
+ } catch {
173
+ return { content: [{ type: "text", text }] };
174
+ }
175
+
176
+ // Return the extracted panels (safe data). Strip nothing else here.
177
+ const out = {
178
+ tool: name,
179
+ preset_label: payload.preset_label,
180
+ panel_count: payload.panel_count,
181
+ panels: payload.panels,
182
+ };
183
+ return { content: [{ type: "text", text: JSON.stringify(out, null, 2) + "\n\n" + FUNNEL_NOTE }] };
184
+ } catch (err) {
185
+ const msg = err && err.name === "AbortError" ? `timeout after ${REQUEST_TIMEOUT_MS}ms` : String(err);
186
+ return {
187
+ isError: true,
188
+ content: [{ type: "text", text: `Request failed for tool '${name}': ${msg}` }],
189
+ };
190
+ } finally {
191
+ clearTimeout(timer);
192
+ }
193
+ });
194
+
195
+ async function main() {
196
+ const transport = new StdioServerTransport();
197
+ await server.connect(transport);
198
+ // stderr only — stdout is reserved for the MCP protocol stream.
199
+ console.error(`[cafe-mcp] ready — 5 free tools, backend: ${ENDPOINT}`);
200
+ }
201
+
202
+ main().catch((e) => {
203
+ console.error("[cafe-mcp] fatal:", e);
204
+ process.exit(1);
205
+ });
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@dangamsoft/cafe-mcp",
3
- "version": "0.0.1",
4
- "description": "Korean Saju (Four Pillars) MCP server — coming soon. See https://github.com/dangamsoft/cafe-mcp",
3
+ "version": "0.6.1",
4
+ "mcpName": "io.github.dangamsoft/cafe-mcp",
5
+ "description": "Korean Saju (Four Pillars / 사주명리) MCP server — 5 free birth-chart analysis tools (chart, five-elements, gyeokguk, yin-yang/climate, yongshin candidates) powered by the CAFE engine.",
6
+ "type": "module",
5
7
  "license": "Apache-2.0",
6
8
  "author": "Dangamsoft",
7
9
  "homepage": "https://github.com/dangamsoft/cafe-mcp",
@@ -12,8 +14,23 @@
12
14
  "bugs": {
13
15
  "url": "https://github.com/dangamsoft/cafe-mcp/issues"
14
16
  },
17
+ "bin": {
18
+ "cafe-mcp": "index.js"
19
+ },
20
+ "files": [
21
+ "index.js",
22
+ "README.md",
23
+ "LICENSE"
24
+ ],
25
+ "engines": {
26
+ "node": ">=18"
27
+ },
28
+ "dependencies": {
29
+ "@modelcontextprotocol/sdk": "^1.29.0"
30
+ },
15
31
  "keywords": [
16
32
  "mcp",
33
+ "model-context-protocol",
17
34
  "saju",
18
35
  "bazi",
19
36
  "korean",