@orange-halo/mcp 1.0.1 → 1.0.3
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.
- package/index.json +1 -1
- package/package.json +4 -4
- package/server.mjs +42 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orange-halo/mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "An MCP server that answers questions about the Orange Halo Design System: every component and its API, every tier 2 token with each brand's value, the rules and the recipes. Runs anywhere with npx; its data is bundled.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"zod": "3.25.76"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@orange-halo/
|
|
30
|
-
"@orange-halo/
|
|
31
|
-
"@orange-halo/
|
|
29
|
+
"@orange-halo/brand-orange-halo": "2.0.4",
|
|
30
|
+
"@orange-halo/components": "3.5.0",
|
|
31
|
+
"@orange-halo/tokens": "3.2.0"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "node build-index.mjs",
|
package/server.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* OHDS MCP server (stdio). Read-only answers about the design system, from
|
|
4
4
|
* index.json beside this file (written by build-index.mjs). See README.md.
|
|
5
5
|
*/
|
|
6
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
6
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
9
9
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -16,8 +16,33 @@ if (!existsSync(indexFile)) {
|
|
|
16
16
|
);
|
|
17
17
|
process.exit(1);
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// The index is re-read when the file changes (a rebuild during a long
|
|
20
|
+
// session), so answers never lag the build.
|
|
21
|
+
let versions, brands, elements, apiValues, llms, tier2, values, tier3;
|
|
22
|
+
let byTag, brandIds, components;
|
|
23
|
+
let loadedAt = 0;
|
|
24
|
+
const load = () => {
|
|
25
|
+
const changed = statSync(indexFile).mtimeMs;
|
|
26
|
+
if (changed === loadedAt) return;
|
|
27
|
+
({ versions, brands, elements, apiValues, llms, tier2, values, tier3 } =
|
|
28
|
+
JSON.parse(readFileSync(indexFile, "utf8")));
|
|
29
|
+
loadedAt = changed;
|
|
30
|
+
byTag = new Map(elements.map((e) => [e.tagName, e]));
|
|
31
|
+
brandIds = brands.map((b) => b.id);
|
|
32
|
+
// Component words: "card" -> oh-card and the card.* tier 3 tokens; "close button" -> closeButton
|
|
33
|
+
components = new Map(
|
|
34
|
+
[...new Set(tier3.map((t) => t.path.split(".")[0]))].map((c) => [
|
|
35
|
+
c.toLowerCase(),
|
|
36
|
+
c,
|
|
37
|
+
])
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
load();
|
|
41
|
+
// An element in the repo but not in the published package yet
|
|
42
|
+
const unreleased = (e) =>
|
|
43
|
+
e.released === false
|
|
44
|
+
? `not on npm yet: it's in the repo and comes after ${e.pkg} ${versions[e.pkg]}`
|
|
45
|
+
: "";
|
|
21
46
|
const { version } = JSON.parse(
|
|
22
47
|
readFileSync(
|
|
23
48
|
fileURLToPath(new URL("./package.json", import.meta.url)),
|
|
@@ -25,8 +50,6 @@ const { version } = JSON.parse(
|
|
|
25
50
|
)
|
|
26
51
|
);
|
|
27
52
|
const text = (t) => ({ content: [{ type: "text", text: t }] });
|
|
28
|
-
const byTag = new Map(elements.map((e) => [e.tagName, e]));
|
|
29
|
-
const brandIds = brands.map((b) => b.id);
|
|
30
53
|
const section = (title) =>
|
|
31
54
|
(
|
|
32
55
|
llms.split(/\n(?=## )/).find((s) => s.startsWith(`## ${title}`)) ?? ""
|
|
@@ -50,13 +73,6 @@ const words = (p) =>
|
|
|
50
73
|
.toLowerCase()
|
|
51
74
|
.split(" ")
|
|
52
75
|
);
|
|
53
|
-
// Component words: "card" -> oh-card and the card.* tier 3 tokens; "close button" -> closeButton
|
|
54
|
-
const components = new Map(
|
|
55
|
-
[...new Set(tier3.map((t) => t.path.split(".")[0]))].map((c) => [
|
|
56
|
-
c.toLowerCase(),
|
|
57
|
-
c,
|
|
58
|
-
])
|
|
59
|
-
);
|
|
60
76
|
const brandValue = (b, p) => JSON.stringify(values[b]?.[p] ?? "?");
|
|
61
77
|
|
|
62
78
|
const server = new McpServer({ name: "ohds", version });
|
|
@@ -70,11 +86,12 @@ server.registerTool(
|
|
|
70
86
|
inputSchema: {},
|
|
71
87
|
},
|
|
72
88
|
async () =>
|
|
89
|
+
load() ??
|
|
73
90
|
text(
|
|
74
91
|
elements
|
|
75
92
|
.map(
|
|
76
93
|
(e) =>
|
|
77
|
-
`<${e.tagName}> (${e.pkg}): ${firstSentence(e.description) || "no description"}`
|
|
94
|
+
`<${e.tagName}> (${e.pkg}${unreleased(e) ? `, ${unreleased(e)}` : ""}): ${firstSentence(e.description) || "no description"}`
|
|
78
95
|
)
|
|
79
96
|
.join("\n")
|
|
80
97
|
)
|
|
@@ -91,6 +108,7 @@ server.registerTool(
|
|
|
91
108
|
},
|
|
92
109
|
},
|
|
93
110
|
async ({ tag }) => {
|
|
111
|
+
load();
|
|
94
112
|
const name = tag.trim().replace(/^<|>$/g, "");
|
|
95
113
|
const el = byTag.get(name) ?? byTag.get(`oh-${name}`);
|
|
96
114
|
if (!el)
|
|
@@ -98,7 +116,9 @@ server.registerTool(
|
|
|
98
116
|
`No element "${tag}". Elements: ${[...byTag.keys()].join(", ")}`
|
|
99
117
|
);
|
|
100
118
|
const lines = [
|
|
101
|
-
|
|
119
|
+
unreleased(el)
|
|
120
|
+
? `# <${el.tagName}> (${el.pkg}, ${unreleased(el)})`
|
|
121
|
+
: `# <${el.tagName}> (${el.pkg} ${versions[el.pkg] ?? ""})`.trimEnd(),
|
|
102
122
|
"",
|
|
103
123
|
el.description || "(No description.)",
|
|
104
124
|
"",
|
|
@@ -180,8 +200,13 @@ server.registerTool(
|
|
|
180
200
|
},
|
|
181
201
|
},
|
|
182
202
|
async ({ query, brand }) => {
|
|
203
|
+
load();
|
|
204
|
+
// A renamed brand's old id ("hood") still finds it
|
|
205
|
+
const asked = brand?.toLowerCase();
|
|
183
206
|
const ids = brand
|
|
184
|
-
?
|
|
207
|
+
? brands
|
|
208
|
+
.filter((b) => b.id === asked || b.formerIds?.includes(asked))
|
|
209
|
+
.map((b) => b.id)
|
|
185
210
|
: brandIds;
|
|
186
211
|
if (!ids.length)
|
|
187
212
|
return text(`No brand "${brand}". Brands: ${brandIds.join(", ")}`);
|
|
@@ -268,7 +293,7 @@ server.registerTool(
|
|
|
268
293
|
}
|
|
269
294
|
if (!out.length)
|
|
270
295
|
return text(
|
|
271
|
-
`No tier 2 token matches "${query}". Try a role (surface, text, border, brand, accent, feedback, spacing, typography, shape, elevation, motion, focus) or a component (${[...components.values()].join(", ")}).`
|
|
296
|
+
`No tier 2 token matches "${query}". Try a role (surface, text, border, brand, accent, feedback, data, spacing, typography, shape, elevation, motion, focus) or a component (${[...components.values()].join(", ")}).`
|
|
272
297
|
);
|
|
273
298
|
return text(out.join("\n").trim());
|
|
274
299
|
}
|
|
@@ -283,6 +308,7 @@ server.registerTool(
|
|
|
283
308
|
inputSchema: {},
|
|
284
309
|
},
|
|
285
310
|
async () =>
|
|
311
|
+
load() ??
|
|
286
312
|
text(
|
|
287
313
|
[
|
|
288
314
|
section("Use it"),
|