@adobe/design-data-mcp 1.1.0 → 1.3.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 +1 -1
- package/package.json +4 -2
- package/src/tools/design-data.js +91 -65
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
|
|
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.
|
|
3
|
+
"version": "1.3.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",
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
"provenance": true
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@modelcontextprotocol/sdk": "^1.27.1"
|
|
30
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
31
|
+
"@adobe/design-data-wasm": "0.2.0",
|
|
32
|
+
"@adobe/spectrum-design-data": "0.3.0"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
35
|
"ava": "^6.0.1"
|
package/src/tools/design-data.js
CHANGED
|
@@ -9,57 +9,52 @@
|
|
|
9
9
|
// governing permissions and limitations under the License.
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* MCP tool definitions
|
|
12
|
+
* MCP tool definitions for @adobe/design-data-mcp.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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 {
|
|
19
|
+
import { createRequire } from "module";
|
|
20
|
+
import { readFileSync, existsSync } from "fs";
|
|
21
|
+
import { join, dirname } from "path";
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
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
|
+
}
|
|
24
29
|
|
|
30
|
+
let _dataset;
|
|
25
31
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* Uses spawnSync (blocking) intentionally: this MCP server serves a single
|
|
29
|
-
* stdio client and processes requests sequentially, so blocking the event
|
|
30
|
-
* loop is safe. The -y flag suppresses the interactive "install?" prompt on
|
|
31
|
-
* first run so the server doesn't hang waiting for user input.
|
|
32
|
+
* Return the embedded Spectrum dataset, caching it after first access.
|
|
32
33
|
*
|
|
33
|
-
*
|
|
34
|
+
* Dataset.embedded() clones the in-memory graph on every call; caching here
|
|
35
|
+
* avoids that per-request cost.
|
|
34
36
|
*/
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
timeout: 30_000,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// result.error is set when the process can't start at all (binary not found,
|
|
43
|
-
// timeout exceeded, etc.) — check before result.status.
|
|
44
|
-
if (result.error) throw result.error;
|
|
45
|
-
|
|
46
|
-
if (result.status !== 0) {
|
|
47
|
-
const msg = (result.stderr || result.stdout || "").trim();
|
|
48
|
-
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();
|
|
49
41
|
}
|
|
42
|
+
return _dataset;
|
|
43
|
+
}
|
|
50
44
|
|
|
45
|
+
/** Return the @adobe/spectrum-design-data package root directory, or null. */
|
|
46
|
+
function resolveSpectrumDataPackage() {
|
|
51
47
|
try {
|
|
52
|
-
|
|
48
|
+
const req = createRequire(import.meta.url);
|
|
49
|
+
return dirname(req.resolve("@adobe/spectrum-design-data/package.json"));
|
|
53
50
|
} catch {
|
|
54
|
-
|
|
55
|
-
// If JSON.parse fails, return the raw string so the caller can decide.
|
|
56
|
-
return result.stdout.trim();
|
|
51
|
+
return null;
|
|
57
52
|
}
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
export function createDesignDataTools() {
|
|
61
56
|
return [
|
|
62
|
-
// ── primer
|
|
57
|
+
// ── primer ─────────────────────────────────────────────────────────────
|
|
63
58
|
{
|
|
64
59
|
name: "design-data-primer",
|
|
65
60
|
description:
|
|
@@ -72,12 +67,28 @@ export function createDesignDataTools() {
|
|
|
72
67
|
properties: {},
|
|
73
68
|
additionalProperties: false,
|
|
74
69
|
},
|
|
75
|
-
handler() {
|
|
76
|
-
|
|
70
|
+
async handler() {
|
|
71
|
+
const [wasm, ds] = await Promise.all([getWasm(), getDataset()]);
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
source: "embedded",
|
|
75
|
+
tokenCount: ds.tokenCount(),
|
|
76
|
+
modeSets: {
|
|
77
|
+
colorScheme: wasm.getFieldValues("colorScheme") ?? [],
|
|
78
|
+
scale: wasm.getFieldValues("scale") ?? [],
|
|
79
|
+
contrast: wasm.getFieldValues("contrast") ?? [],
|
|
80
|
+
},
|
|
81
|
+
taxonomyFields: {
|
|
82
|
+
indexed: wasm.getIndexedFields(),
|
|
83
|
+
advisory: wasm.getAdvisoryFields() ?? [],
|
|
84
|
+
},
|
|
85
|
+
components: wasm.getFieldValues("component") ?? [],
|
|
86
|
+
properties: wasm.getFieldValues("property") ?? [],
|
|
87
|
+
};
|
|
77
88
|
},
|
|
78
89
|
},
|
|
79
90
|
|
|
80
|
-
// ── query
|
|
91
|
+
// ── query ───────────────────────────────────────────────────────────────
|
|
81
92
|
{
|
|
82
93
|
name: "design-data-query",
|
|
83
94
|
description:
|
|
@@ -97,17 +108,19 @@ export function createDesignDataTools() {
|
|
|
97
108
|
required: ["filter"],
|
|
98
109
|
additionalProperties: false,
|
|
99
110
|
},
|
|
100
|
-
handler({ filter }) {
|
|
101
|
-
|
|
111
|
+
async handler({ filter }) {
|
|
112
|
+
const ds = await getDataset();
|
|
113
|
+
return ds.query(filter);
|
|
102
114
|
},
|
|
103
115
|
},
|
|
104
116
|
|
|
105
|
-
// ── suggest
|
|
117
|
+
// ── suggest ─────────────────────────────────────────────────────────────
|
|
106
118
|
{
|
|
107
119
|
name: "design-data-suggest",
|
|
108
120
|
description:
|
|
109
|
-
"Suggest Spectrum tokens matching a natural-language intent
|
|
110
|
-
"
|
|
121
|
+
"Suggest Spectrum tokens matching a natural-language intent using Jaccard similarity " +
|
|
122
|
+
"scoring over token name segments, name-object fields, and description text. " +
|
|
123
|
+
"Returns matches ranked by confidence with token name, layer, value, and name object. " +
|
|
111
124
|
"Use when the user describes what they need rather than knowing the token name.",
|
|
112
125
|
inputSchema: {
|
|
113
126
|
type: "object",
|
|
@@ -126,20 +139,13 @@ export function createDesignDataTools() {
|
|
|
126
139
|
required: ["intent"],
|
|
127
140
|
additionalProperties: false,
|
|
128
141
|
},
|
|
129
|
-
handler({ intent, limit = 5 }) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
"--",
|
|
133
|
-
intent,
|
|
134
|
-
"--format",
|
|
135
|
-
"json",
|
|
136
|
-
"--limit",
|
|
137
|
-
String(limit),
|
|
138
|
-
]);
|
|
142
|
+
async handler({ intent, limit = 5 }) {
|
|
143
|
+
const ds = await getDataset();
|
|
144
|
+
return ds.suggest(intent, undefined, limit);
|
|
139
145
|
},
|
|
140
146
|
},
|
|
141
147
|
|
|
142
|
-
// ── component
|
|
148
|
+
// ── component ───────────────────────────────────────────────────────────
|
|
143
149
|
{
|
|
144
150
|
name: "design-data-component",
|
|
145
151
|
description:
|
|
@@ -159,13 +165,26 @@ export function createDesignDataTools() {
|
|
|
159
165
|
required: ["id"],
|
|
160
166
|
additionalProperties: false,
|
|
161
167
|
},
|
|
162
|
-
handler({ id }) {
|
|
163
|
-
|
|
164
|
-
|
|
168
|
+
async handler({ id }) {
|
|
169
|
+
const pkgRoot = resolveSpectrumDataPackage();
|
|
170
|
+
if (!pkgRoot) {
|
|
171
|
+
throw new Error(
|
|
172
|
+
`@adobe/spectrum-design-data is not installed — cannot load component "${id}". ` +
|
|
173
|
+
`Install it with: pnpm add @adobe/spectrum-design-data`,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
const componentFile = join(pkgRoot, "components", `${id}.json`);
|
|
177
|
+
if (!existsSync(componentFile)) {
|
|
178
|
+
throw new Error(
|
|
179
|
+
`Component not found: "${id}". ` +
|
|
180
|
+
`Call design-data-primer to see available component IDs.`,
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return JSON.parse(readFileSync(componentFile, "utf-8"));
|
|
165
184
|
},
|
|
166
185
|
},
|
|
167
186
|
|
|
168
|
-
// ── resolve
|
|
187
|
+
// ── resolve ─────────────────────────────────────────────────────────────
|
|
169
188
|
{
|
|
170
189
|
name: "design-data-resolve",
|
|
171
190
|
description:
|
|
@@ -186,22 +205,29 @@ export function createDesignDataTools() {
|
|
|
186
205
|
},
|
|
187
206
|
scale: {
|
|
188
207
|
type: "string",
|
|
189
|
-
description: 'Scale mode, e.g. "
|
|
208
|
+
description: 'Scale mode, e.g. "desktop" or "mobile"',
|
|
190
209
|
},
|
|
191
210
|
contrast: {
|
|
192
211
|
type: "string",
|
|
193
|
-
description: 'Contrast mode, e.g. "
|
|
212
|
+
description: 'Contrast mode, e.g. "regular" or "high"',
|
|
194
213
|
},
|
|
195
214
|
},
|
|
196
215
|
required: ["property"],
|
|
197
216
|
additionalProperties: false,
|
|
198
217
|
},
|
|
199
|
-
handler({ property, colorScheme, scale, contrast }) {
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
if (
|
|
204
|
-
|
|
218
|
+
async handler({ property, colorScheme, scale, contrast }) {
|
|
219
|
+
const ds = await getDataset();
|
|
220
|
+
const context = {};
|
|
221
|
+
if (colorScheme) context.colorScheme = colorScheme;
|
|
222
|
+
if (scale) context.scale = scale;
|
|
223
|
+
if (contrast) context.contrast = contrast;
|
|
224
|
+
const result = ds.resolve(property, context);
|
|
225
|
+
if (!result) {
|
|
226
|
+
throw new Error(
|
|
227
|
+
`No token found for property "${property}" in context ${JSON.stringify(context)}`,
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
205
231
|
},
|
|
206
232
|
},
|
|
207
233
|
];
|