@adobe/spectrum-design-data-mcp 0.0.0-layout-20260209174611
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/CHANGELOG.md +188 -0
- package/LICENSE +201 -0
- package/README.md +309 -0
- package/package.json +60 -0
- package/src/cli.js +42 -0
- package/src/data/schemas.js +150 -0
- package/src/data/tokens.js +111 -0
- package/src/index.js +97 -0
- package/src/tools/schemas.js +472 -0
- package/src/tools/tokens.js +592 -0
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adobe/spectrum-design-data-mcp",
|
|
3
|
+
"version": "0.0.0-layout-20260209174611",
|
|
4
|
+
"description": "Model Context Protocol server for Spectrum design data including tokens, schemas, and component anatomy",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"model-context-protocol",
|
|
8
|
+
"spectrum",
|
|
9
|
+
"design-tokens",
|
|
10
|
+
"component-schemas",
|
|
11
|
+
"component-anatomy",
|
|
12
|
+
"design-data",
|
|
13
|
+
"design-system",
|
|
14
|
+
"adobe",
|
|
15
|
+
"ai-tools"
|
|
16
|
+
],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./src/index.js",
|
|
19
|
+
"bin": {
|
|
20
|
+
"spectrum-design-data-mcp": "./src/cli.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"src/",
|
|
24
|
+
"README.md",
|
|
25
|
+
"CHANGELOG.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20.12.0",
|
|
30
|
+
"pnpm": ">=10.17.1"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/adobe/spectrum-design-data.git",
|
|
35
|
+
"directory": "tools/spectrum-design-data-mcp"
|
|
36
|
+
},
|
|
37
|
+
"author": "Garth Braithwaite <garthdb@gmail.com> (http://garthdb.com/)",
|
|
38
|
+
"license": "Apache-2.0",
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/adobe/spectrum-design-data/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/adobe/spectrum-design-data/tree/main/tools/spectrum-design-data-mcp#readme",
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"registry": "https://registry.npmjs.org/",
|
|
46
|
+
"provenance": false
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@modelcontextprotocol/sdk": "^0.5.0",
|
|
50
|
+
"commander": "^13.1.0",
|
|
51
|
+
"@adobe/spectrum-tokens": "0.0.0-layout-20260209174611",
|
|
52
|
+
"@adobe/spectrum-component-api-schemas": "6.0.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"ava": "^6.0.1"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"test": "ava"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
5
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { Command } from "commander";
|
|
16
|
+
import { startServer } from "./index.js";
|
|
17
|
+
|
|
18
|
+
const program = new Command();
|
|
19
|
+
|
|
20
|
+
program
|
|
21
|
+
.name("spectrum-design-data-mcp")
|
|
22
|
+
.description("Model Context Protocol server for Spectrum design data")
|
|
23
|
+
.version("0.1.0");
|
|
24
|
+
|
|
25
|
+
program
|
|
26
|
+
.command("start")
|
|
27
|
+
.description("Start the MCP server with stdio transport")
|
|
28
|
+
.action(async () => {
|
|
29
|
+
try {
|
|
30
|
+
await startServer();
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error("Failed to start MCP server:", error);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// If no command is provided, default to start
|
|
38
|
+
if (process.argv.length === 2) {
|
|
39
|
+
process.argv.push("start");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
program.parse();
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { readFileSync, readdirSync, statSync } from "fs";
|
|
14
|
+
import { join, dirname } from "path";
|
|
15
|
+
import { fileURLToPath } from "url";
|
|
16
|
+
|
|
17
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
18
|
+
const __dirname = dirname(__filename);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get schema data from the component-schemas package
|
|
22
|
+
* @returns {Promise<Object>} Schema data organized by type
|
|
23
|
+
*/
|
|
24
|
+
export async function getSchemaData() {
|
|
25
|
+
try {
|
|
26
|
+
// Try to import from the workspace package first
|
|
27
|
+
const componentSchemas = await import(
|
|
28
|
+
"@adobe/spectrum-component-api-schemas"
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// If the package exports schema data directly, use it
|
|
32
|
+
if (componentSchemas.default || componentSchemas.schemas) {
|
|
33
|
+
return componentSchemas.default || componentSchemas.schemas;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Otherwise, read the schema files directly from the package
|
|
37
|
+
return await loadSchemaFilesDirectly();
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error(
|
|
40
|
+
"Failed to load schema data from package, trying direct file access:",
|
|
41
|
+
error,
|
|
42
|
+
);
|
|
43
|
+
return await loadSchemaFilesDirectly();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Load schema files directly from the repository structure
|
|
49
|
+
* @returns {Promise<Object>} Schema data
|
|
50
|
+
*/
|
|
51
|
+
async function loadSchemaFilesDirectly() {
|
|
52
|
+
const schemaData = {
|
|
53
|
+
components: {},
|
|
54
|
+
types: {},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Path to the schemas directory
|
|
58
|
+
const schemasPath = join(
|
|
59
|
+
__dirname,
|
|
60
|
+
"../../../../packages/component-schemas/schemas",
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// Load component schemas
|
|
64
|
+
const componentsPath = join(schemasPath, "components");
|
|
65
|
+
try {
|
|
66
|
+
const componentFiles = readdirSync(componentsPath).filter((file) =>
|
|
67
|
+
file.endsWith(".json"),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
for (const fileName of componentFiles) {
|
|
71
|
+
try {
|
|
72
|
+
const filePath = join(componentsPath, fileName);
|
|
73
|
+
const fileContent = readFileSync(filePath, "utf8");
|
|
74
|
+
schemaData.components[fileName] = JSON.parse(fileContent);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error(`Failed to load component schema ${fileName}:`, error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error("Failed to read components directory:", error);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Load type schemas
|
|
84
|
+
const typesPath = join(schemasPath, "types");
|
|
85
|
+
try {
|
|
86
|
+
const typeFiles = readdirSync(typesPath).filter((file) =>
|
|
87
|
+
file.endsWith(".json"),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
for (const fileName of typeFiles) {
|
|
91
|
+
try {
|
|
92
|
+
const filePath = join(typesPath, fileName);
|
|
93
|
+
const fileContent = readFileSync(filePath, "utf8");
|
|
94
|
+
schemaData.types[fileName] = JSON.parse(fileContent);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error(`Failed to load type schema ${fileName}:`, error);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error("Failed to read types directory:", error);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return schemaData;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get available component names
|
|
108
|
+
* @returns {Promise<Array<string>>} List of component names
|
|
109
|
+
*/
|
|
110
|
+
export async function getComponentNames() {
|
|
111
|
+
const schemaData = await getSchemaData();
|
|
112
|
+
return Object.keys(schemaData.components).map((fileName) =>
|
|
113
|
+
fileName.replace(".json", ""),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Get schema for a specific component
|
|
119
|
+
* @param {string} componentName - Component name
|
|
120
|
+
* @returns {Promise<Object|null>} Component schema
|
|
121
|
+
*/
|
|
122
|
+
export async function getComponentSchema(componentName) {
|
|
123
|
+
const schemaData = await getSchemaData();
|
|
124
|
+
const fileName = componentName.endsWith(".json")
|
|
125
|
+
? componentName
|
|
126
|
+
: `${componentName}.json`;
|
|
127
|
+
return schemaData.components[fileName] || null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Get available type names
|
|
132
|
+
* @returns {Promise<Array<string>>} List of type names
|
|
133
|
+
*/
|
|
134
|
+
export async function getTypeNames() {
|
|
135
|
+
const schemaData = await getSchemaData();
|
|
136
|
+
return Object.keys(schemaData.types).map((fileName) =>
|
|
137
|
+
fileName.replace(".json", ""),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Get schema for a specific type
|
|
143
|
+
* @param {string} typeName - Type name
|
|
144
|
+
* @returns {Promise<Object|null>} Type schema
|
|
145
|
+
*/
|
|
146
|
+
export async function getTypeSchema(typeName) {
|
|
147
|
+
const schemaData = await getSchemaData();
|
|
148
|
+
const fileName = typeName.endsWith(".json") ? typeName : `${typeName}.json`;
|
|
149
|
+
return schemaData.types[fileName] || null;
|
|
150
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { readFileSync } from "fs";
|
|
14
|
+
import { join, dirname } from "path";
|
|
15
|
+
import { fileURLToPath } from "url";
|
|
16
|
+
|
|
17
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
18
|
+
const __dirname = dirname(__filename);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get token data from the spectrum-tokens package
|
|
22
|
+
* @returns {Promise<Object>} Token data organized by category
|
|
23
|
+
*/
|
|
24
|
+
export async function getTokenData() {
|
|
25
|
+
try {
|
|
26
|
+
// Try to import from the workspace package first
|
|
27
|
+
const spectrumTokens = await import("@adobe/spectrum-tokens");
|
|
28
|
+
|
|
29
|
+
// If the package exports token data directly, use it
|
|
30
|
+
if (spectrumTokens.default || spectrumTokens.tokens) {
|
|
31
|
+
return spectrumTokens.default || spectrumTokens.tokens;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Otherwise, read the token files directly from the package
|
|
35
|
+
return await loadTokenFilesFromPackage();
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error(
|
|
38
|
+
"Failed to load token data from package, trying direct file access:",
|
|
39
|
+
error,
|
|
40
|
+
);
|
|
41
|
+
return await loadTokenFilesDirectly();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Load token files from the spectrum-tokens package structure
|
|
47
|
+
* @returns {Promise<Object>} Token data
|
|
48
|
+
*/
|
|
49
|
+
async function loadTokenFilesFromPackage() {
|
|
50
|
+
// This would be the ideal approach - loading from the actual package
|
|
51
|
+
// For now, we'll fall back to direct file access
|
|
52
|
+
return await loadTokenFilesDirectly();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Load token files directly from the repository structure
|
|
57
|
+
* @returns {Promise<Object>} Token data
|
|
58
|
+
*/
|
|
59
|
+
async function loadTokenFilesDirectly() {
|
|
60
|
+
const tokenData = {};
|
|
61
|
+
|
|
62
|
+
// Path to the tokens source directory
|
|
63
|
+
const tokensPath = join(__dirname, "../../../../packages/tokens/src");
|
|
64
|
+
|
|
65
|
+
// List of token files to load
|
|
66
|
+
const tokenFiles = [
|
|
67
|
+
"color-aliases.json",
|
|
68
|
+
"color-component.json",
|
|
69
|
+
"color-palette.json",
|
|
70
|
+
"icons.json",
|
|
71
|
+
"layout-component.json",
|
|
72
|
+
"layout.json",
|
|
73
|
+
"semantic-color-palette.json",
|
|
74
|
+
"typography.json",
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
for (const fileName of tokenFiles) {
|
|
78
|
+
try {
|
|
79
|
+
const filePath = join(tokensPath, fileName);
|
|
80
|
+
const fileContent = readFileSync(filePath, "utf8");
|
|
81
|
+
tokenData[fileName] = JSON.parse(fileContent);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error(`Failed to load token file ${fileName}:`, error);
|
|
84
|
+
// Continue loading other files even if one fails
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return tokenData;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Get available token categories
|
|
93
|
+
* @returns {Promise<Array<string>>} List of token categories
|
|
94
|
+
*/
|
|
95
|
+
export async function getTokenCategories() {
|
|
96
|
+
const tokenData = await getTokenData();
|
|
97
|
+
return Object.keys(tokenData).map((fileName) =>
|
|
98
|
+
fileName.replace(".json", ""),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get tokens from a specific category
|
|
104
|
+
* @param {string} category - Token category name
|
|
105
|
+
* @returns {Promise<Object|null>} Token data for the category
|
|
106
|
+
*/
|
|
107
|
+
export async function getTokensByCategory(category) {
|
|
108
|
+
const tokenData = await getTokenData();
|
|
109
|
+
const fileName = category.endsWith(".json") ? category : `${category}.json`;
|
|
110
|
+
return tokenData[fileName] || null;
|
|
111
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
14
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
15
|
+
import {
|
|
16
|
+
CallToolRequestSchema,
|
|
17
|
+
ListToolsRequestSchema,
|
|
18
|
+
} from "@modelcontextprotocol/sdk/types.js";
|
|
19
|
+
|
|
20
|
+
import { createTokenTools } from "./tools/tokens.js";
|
|
21
|
+
import { createSchemaTools } from "./tools/schemas.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Create and configure the Spectrum Design Data MCP server
|
|
25
|
+
* @returns {Server} Configured MCP server instance
|
|
26
|
+
*/
|
|
27
|
+
export function createMCPServer() {
|
|
28
|
+
const server = new Server(
|
|
29
|
+
{
|
|
30
|
+
name: "spectrum-design-data",
|
|
31
|
+
version: "0.1.0",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
capabilities: {
|
|
35
|
+
tools: {},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// Combine all available tools
|
|
41
|
+
const allTools = [...createTokenTools(), ...createSchemaTools()];
|
|
42
|
+
|
|
43
|
+
// Register list_tools handler
|
|
44
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
45
|
+
return {
|
|
46
|
+
tools: allTools.map((tool) => ({
|
|
47
|
+
name: tool.name,
|
|
48
|
+
description: tool.description,
|
|
49
|
+
inputSchema: tool.inputSchema,
|
|
50
|
+
})),
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Register call_tool handler
|
|
55
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
56
|
+
const { name, arguments: args } = request.params;
|
|
57
|
+
|
|
58
|
+
const tool = allTools.find((t) => t.name === name);
|
|
59
|
+
if (!tool) {
|
|
60
|
+
throw new Error(`Tool not found: ${name}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const result = await tool.handler(args || {});
|
|
65
|
+
return {
|
|
66
|
+
content: [
|
|
67
|
+
{
|
|
68
|
+
type: "text",
|
|
69
|
+
text:
|
|
70
|
+
typeof result === "string"
|
|
71
|
+
? result
|
|
72
|
+
: JSON.stringify(result, null, 2),
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
};
|
|
76
|
+
} catch (error) {
|
|
77
|
+
throw new Error(`Tool execution failed: ${error.message}`);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return server;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Start the MCP server with stdio transport
|
|
86
|
+
*/
|
|
87
|
+
export async function startServer() {
|
|
88
|
+
const server = createMCPServer();
|
|
89
|
+
const transport = new StdioServerTransport();
|
|
90
|
+
await server.connect(transport);
|
|
91
|
+
|
|
92
|
+
// Log server start for debugging (this goes to stderr, not stdout which is used for MCP)
|
|
93
|
+
console.error("Spectrum Design Data MCP server started");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Export for testing
|
|
97
|
+
export { createTokenTools, createSchemaTools };
|