@adobe/design-data-mcp 1.0.0 → 1.2.0

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/LICENSE CHANGED
@@ -186,7 +186,7 @@ file or class name and description of purpose be included on the
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
189
+ Copyright 2026 Adobe
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/design-data-mcp",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "MCP server for Spectrum design tokens and component schemas via the design-data CLI",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -12,9 +12,6 @@
12
12
  "README.md",
13
13
  "LICENSE"
14
14
  ],
15
- "scripts": {
16
- "start": "node src/cli.js"
17
- },
18
15
  "repository": {
19
16
  "type": "git",
20
17
  "url": "git+https://github.com/adobe/spectrum-design-data.git",
@@ -30,7 +27,12 @@
30
27
  "provenance": true
31
28
  },
32
29
  "dependencies": {
33
- "@modelcontextprotocol/sdk": "^1.27.1"
30
+ "@modelcontextprotocol/sdk": "^1.27.1",
31
+ "@adobe/design-data-wasm": "0.1.0",
32
+ "@adobe/spectrum-design-data": "0.3.0"
33
+ },
34
+ "devDependencies": {
35
+ "ava": "^6.0.1"
34
36
  },
35
37
  "engines": {
36
38
  "node": ">=20.12.0"
@@ -43,5 +45,9 @@
43
45
  "cli"
44
46
  ],
45
47
  "author": "Adobe",
46
- "license": "Apache-2.0"
47
- }
48
+ "license": "Apache-2.0",
49
+ "scripts": {
50
+ "start": "node src/cli.js",
51
+ "test": "ava"
52
+ }
53
+ }
package/src/cli.js CHANGED
File without changes
@@ -9,54 +9,83 @@
9
9
  // governing permissions and limitations under the License.
10
10
 
11
11
  /**
12
- * MCP tool definitions that wrap the @adobe/design-data CLI.
12
+ * MCP tool definitions for @adobe/design-data-mcp.
13
13
  *
14
- * Each tool shells out to `npx @adobe/design-data <subcommand>` and returns
15
- * the parsed JSON output. The CLI handles data resolution automatically —
16
- * it uses the embedded Spectrum snapshot when no `.design-data.toml` is present,
17
- * or the configured source/version if one exists in the project.
14
+ * All tools run in-process via @adobe/design-data-wasm no CLI binary or npx
15
+ * required. Dataset.embedded() provides the canonical Spectrum snapshot with
16
+ * zero configuration.
18
17
  */
19
18
 
20
- import { spawnSync } from "child_process";
19
+ import { createRequire } from "module";
20
+ import { readFileSync, existsSync } from "fs";
21
+ import { join, dirname } from "path";
21
22
 
23
+ let _wasm;
24
+ /** Lazy-load and cache the wasm module (nodejs target, no init() required). */
25
+ async function getWasm() {
26
+ if (!_wasm) _wasm = await import("@adobe/design-data-wasm");
27
+ return _wasm;
28
+ }
29
+
30
+ let _dataset;
22
31
  /**
23
- * Run `npx -y @adobe/design-data` with the given args and return parsed JSON stdout.
32
+ * Return the embedded Spectrum dataset, caching it after first access.
24
33
  *
25
- * Uses spawnSync (blocking) intentionally: this MCP server serves a single
26
- * stdio client and processes requests sequentially, so blocking the event
27
- * loop is safe. The -y flag suppresses the interactive "install?" prompt on
28
- * first run so the server doesn't hang waiting for user input.
29
- *
30
- * Throws if the process can't start (result.error) or exits non-zero.
34
+ * Dataset.embedded() clones the in-memory graph on every call; caching here
35
+ * avoids that per-request cost.
31
36
  */
32
- function runDesignData(args) {
33
- const result = spawnSync("npx", ["-y", "@adobe/design-data", ...args], {
34
- encoding: "utf8",
35
- // Allow up to 30s for first-run install + binary execution.
36
- timeout: 30_000,
37
- });
38
-
39
- // result.error is set when the process can't start at all (binary not found,
40
- // timeout exceeded, etc.) — check before result.status.
41
- if (result.error) throw result.error;
42
-
43
- if (result.status !== 0) {
44
- const msg = (result.stderr || result.stdout || "").trim();
45
- throw new Error(`design-data exited ${result.status}: ${msg}`);
37
+ async function getDataset() {
38
+ if (!_dataset) {
39
+ const wasm = await getWasm();
40
+ _dataset = wasm.Dataset.embedded();
46
41
  }
42
+ return _dataset;
43
+ }
47
44
 
45
+ /**
46
+ * Score tokens by keyword-overlap against an intent string.
47
+ *
48
+ * Pure function — accepts the token array so it can be tested independently.
49
+ *
50
+ * @param {object[]} tokens - Array of token result objects with a `name` string.
51
+ * @param {string} intent - Natural-language intent to match against.
52
+ * @param {number} limit - Maximum results to return.
53
+ * @returns {{ name: string, confidence: number, uuid: string, raw: unknown }[]}
54
+ */
55
+ export function scoreTokensByKeyword(tokens, intent, limit = 5) {
56
+ const words = intent.toLowerCase().split(/\s+/).filter(Boolean);
57
+ if (words.length === 0) return [];
58
+ return tokens
59
+ .map((token) => {
60
+ const nameStr = token.name?.toLowerCase() ?? "";
61
+ const matches = words.filter((w) => nameStr.includes(w)).length;
62
+ const confidence = matches / words.length;
63
+ return { token, confidence };
64
+ })
65
+ .filter(({ confidence }) => confidence > 0)
66
+ .sort((a, b) => b.confidence - a.confidence)
67
+ .slice(0, limit)
68
+ .map(({ token, confidence }) => ({
69
+ name: token.name,
70
+ confidence: Math.round(confidence * 100) / 100,
71
+ uuid: token.uuid,
72
+ raw: token.raw,
73
+ }));
74
+ }
75
+
76
+ /** Return the @adobe/spectrum-design-data package root directory, or null. */
77
+ function resolveSpectrumDataPackage() {
48
78
  try {
49
- return JSON.parse(result.stdout);
79
+ const req = createRequire(import.meta.url);
80
+ return dirname(req.resolve("@adobe/spectrum-design-data/package.json"));
50
81
  } catch {
51
- // Some commands (e.g. component) output valid JSON but without --format json.
52
- // If JSON.parse fails, return the raw string so the caller can decide.
53
- return result.stdout.trim();
82
+ return null;
54
83
  }
55
84
  }
56
85
 
57
86
  export function createDesignDataTools() {
58
87
  return [
59
- // ── primer ────────────────────────────────────────────────────────────────
88
+ // ── primer ─────────────────────────────────────────────────────────────
60
89
  {
61
90
  name: "design-data-primer",
62
91
  description:
@@ -69,12 +98,28 @@ export function createDesignDataTools() {
69
98
  properties: {},
70
99
  additionalProperties: false,
71
100
  },
72
- handler() {
73
- return runDesignData(["primer", "--format", "json"]);
101
+ async handler() {
102
+ const [wasm, ds] = await Promise.all([getWasm(), getDataset()]);
103
+
104
+ return {
105
+ source: "embedded",
106
+ tokenCount: ds.tokenCount(),
107
+ modeSets: {
108
+ colorScheme: wasm.getFieldValues("colorScheme") ?? [],
109
+ scale: wasm.getFieldValues("scale") ?? [],
110
+ contrast: wasm.getFieldValues("contrast") ?? [],
111
+ },
112
+ taxonomyFields: {
113
+ indexed: wasm.getIndexedFields(),
114
+ advisory: wasm.getAdvisoryFields() ?? [],
115
+ },
116
+ components: wasm.getFieldValues("component") ?? [],
117
+ properties: wasm.getFieldValues("property") ?? [],
118
+ };
74
119
  },
75
120
  },
76
121
 
77
- // ── query ─────────────────────────────────────────────────────────────────
122
+ // ── query ───────────────────────────────────────────────────────────────
78
123
  {
79
124
  name: "design-data-query",
80
125
  description:
@@ -94,18 +139,20 @@ export function createDesignDataTools() {
94
139
  required: ["filter"],
95
140
  additionalProperties: false,
96
141
  },
97
- handler({ filter }) {
98
- return runDesignData(["query", "--filter", filter, "--format", "json"]);
142
+ async handler({ filter }) {
143
+ const ds = await getDataset();
144
+ return ds.query(filter);
99
145
  },
100
146
  },
101
147
 
102
- // ── suggest ───────────────────────────────────────────────────────────────
148
+ // ── suggest ─────────────────────────────────────────────────────────────
103
149
  {
104
150
  name: "design-data-suggest",
105
151
  description:
106
- "Suggest Spectrum tokens matching a natural-language intent. " +
107
- "Returns ranked matches with confidence scores, token names, and values. " +
108
- "Use when the user describes what they need rather than knowing the token name.",
152
+ "Suggest Spectrum tokens matching a natural-language intent using keyword-overlap " +
153
+ "scoring. Returns matches ranked by confidence, token names, and values. " +
154
+ "Use when the user describes what they need rather than knowing the token name. " +
155
+ "(TODO: swap to wasm NLP suggest when available for higher-quality ranking.)",
109
156
  inputSchema: {
110
157
  type: "object",
111
158
  properties: {
@@ -123,19 +170,14 @@ export function createDesignDataTools() {
123
170
  required: ["intent"],
124
171
  additionalProperties: false,
125
172
  },
126
- handler({ intent, limit = 5 }) {
127
- return runDesignData([
128
- "suggest",
129
- intent,
130
- "--format",
131
- "json",
132
- "--limit",
133
- String(limit),
134
- ]);
173
+ async handler({ intent, limit = 5 }) {
174
+ const ds = await getDataset();
175
+ const allTokens = ds.query("");
176
+ return scoreTokensByKeyword(allTokens, intent, limit);
135
177
  },
136
178
  },
137
179
 
138
- // ── component ─────────────────────────────────────────────────────────────
180
+ // ── component ───────────────────────────────────────────────────────────
139
181
  {
140
182
  name: "design-data-component",
141
183
  description:
@@ -155,13 +197,26 @@ export function createDesignDataTools() {
155
197
  required: ["id"],
156
198
  additionalProperties: false,
157
199
  },
158
- handler({ id }) {
159
- // component always outputs JSON — no --format flag.
160
- return runDesignData(["component", id]);
200
+ async handler({ id }) {
201
+ const pkgRoot = resolveSpectrumDataPackage();
202
+ if (!pkgRoot) {
203
+ throw new Error(
204
+ `@adobe/spectrum-design-data is not installed — cannot load component "${id}". ` +
205
+ `Install it with: pnpm add @adobe/spectrum-design-data`,
206
+ );
207
+ }
208
+ const componentFile = join(pkgRoot, "components", `${id}.json`);
209
+ if (!existsSync(componentFile)) {
210
+ throw new Error(
211
+ `Component not found: "${id}". ` +
212
+ `Call design-data-primer to see available component IDs.`,
213
+ );
214
+ }
215
+ return JSON.parse(readFileSync(componentFile, "utf-8"));
161
216
  },
162
217
  },
163
218
 
164
- // ── resolve ───────────────────────────────────────────────────────────────
219
+ // ── resolve ─────────────────────────────────────────────────────────────
165
220
  {
166
221
  name: "design-data-resolve",
167
222
  description:
@@ -182,22 +237,29 @@ export function createDesignDataTools() {
182
237
  },
183
238
  scale: {
184
239
  type: "string",
185
- description: 'Scale mode, e.g. "medium" or "large"',
240
+ description: 'Scale mode, e.g. "desktop" or "mobile"',
186
241
  },
187
242
  contrast: {
188
243
  type: "string",
189
- description: 'Contrast mode, e.g. "standard" or "high"',
244
+ description: 'Contrast mode, e.g. "regular" or "high"',
190
245
  },
191
246
  },
192
247
  required: ["property"],
193
248
  additionalProperties: false,
194
249
  },
195
- handler({ property, colorScheme, scale, contrast }) {
196
- const args = ["resolve", property, "--format", "json"];
197
- if (colorScheme) args.push("--color-scheme", colorScheme);
198
- if (scale) args.push("--scale", scale);
199
- if (contrast) args.push("--contrast", contrast);
200
- return runDesignData(args);
250
+ async handler({ property, colorScheme, scale, contrast }) {
251
+ const ds = await getDataset();
252
+ const context = {};
253
+ if (colorScheme) context.colorScheme = colorScheme;
254
+ if (scale) context.scale = scale;
255
+ if (contrast) context.contrast = contrast;
256
+ const result = ds.resolve(property, context);
257
+ if (!result) {
258
+ throw new Error(
259
+ `No token found for property "${property}" in context ${JSON.stringify(context)}`,
260
+ );
261
+ }
262
+ return result;
201
263
  },
202
264
  },
203
265
  ];