@muloka/figma-console-mcp 0.5.1 → 0.5.4

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 (107) hide show
  1. package/README.md +5 -4
  2. package/dist/apps/design-system-dashboard/mcp-app.html +521 -0
  3. package/dist/apps/token-browser/mcp-app.html +410 -0
  4. package/dist/cloudflare/apps/design-system-dashboard/scoring/accessibility.js +277 -0
  5. package/dist/cloudflare/apps/design-system-dashboard/scoring/component-metadata.js +357 -0
  6. package/dist/cloudflare/apps/design-system-dashboard/scoring/consistency.js +341 -0
  7. package/dist/cloudflare/apps/design-system-dashboard/scoring/coverage.js +230 -0
  8. package/dist/cloudflare/apps/design-system-dashboard/scoring/engine.js +92 -0
  9. package/dist/cloudflare/apps/design-system-dashboard/scoring/naming-semantics.js +308 -0
  10. package/dist/cloudflare/apps/design-system-dashboard/scoring/token-architecture.js +349 -0
  11. package/dist/cloudflare/apps/design-system-dashboard/scoring/types.js +40 -0
  12. package/dist/cloudflare/apps/design-system-dashboard/server.js +159 -0
  13. package/dist/cloudflare/apps/token-browser/server.js +136 -0
  14. package/dist/cloudflare/browser-manager.js +157 -0
  15. package/dist/cloudflare/core/accessibility-tools.js +361 -0
  16. package/dist/cloudflare/core/annotation-tools.js +230 -0
  17. package/dist/cloudflare/core/cloud-websocket-connector.js +419 -0
  18. package/dist/cloudflare/core/cloud-websocket-relay.js +198 -0
  19. package/dist/cloudflare/core/comment-tools.js +292 -0
  20. package/dist/cloudflare/core/config.js +153 -0
  21. package/dist/cloudflare/core/console-monitor.js +427 -0
  22. package/dist/cloudflare/core/deep-component-tools.js +128 -0
  23. package/dist/cloudflare/core/design-code-tools.js +2793 -0
  24. package/dist/cloudflare/core/design-system-manifest.js +265 -0
  25. package/dist/cloudflare/core/design-system-tools.js +882 -0
  26. package/dist/cloudflare/core/diagnose-tool.js +100 -0
  27. package/dist/cloudflare/core/diff/changelog-formatter.js +275 -0
  28. package/dist/cloudflare/core/diff/diff-engine.js +334 -0
  29. package/dist/cloudflare/core/diff/property-compare.js +36 -0
  30. package/dist/cloudflare/core/diff/version-cache.js +74 -0
  31. package/dist/cloudflare/core/enrichment/enrichment-service.js +374 -0
  32. package/dist/cloudflare/core/enrichment/index.js +7 -0
  33. package/dist/cloudflare/core/enrichment/relationship-mapper.js +351 -0
  34. package/dist/cloudflare/core/enrichment/style-resolver.js +346 -0
  35. package/dist/cloudflare/core/figjam-tools.js +547 -0
  36. package/dist/cloudflare/core/figma-api.js +509 -0
  37. package/dist/cloudflare/core/figma-connector.js +7 -0
  38. package/dist/cloudflare/core/figma-reconstruction-spec.js +402 -0
  39. package/dist/cloudflare/core/figma-style-extractor.js +311 -0
  40. package/dist/cloudflare/core/figma-tools.js +3353 -0
  41. package/dist/cloudflare/core/identity.js +96 -0
  42. package/dist/cloudflare/core/library-tools.js +580 -0
  43. package/dist/cloudflare/core/logger.js +53 -0
  44. package/dist/cloudflare/core/port-discovery.js +935 -0
  45. package/dist/cloudflare/core/resolve-package-root.js +11 -0
  46. package/dist/cloudflare/core/slides-tools.js +714 -0
  47. package/dist/cloudflare/core/slot-tools.js +334 -0
  48. package/dist/cloudflare/core/snippet-injector.js +96 -0
  49. package/dist/cloudflare/core/tokens/alias-resolver.js +205 -0
  50. package/dist/cloudflare/core/tokens/config.js +294 -0
  51. package/dist/cloudflare/core/tokens/dialect.js +232 -0
  52. package/dist/cloudflare/core/tokens/figma-converter.js +323 -0
  53. package/dist/cloudflare/core/tokens/formatters/css-vars.js +338 -0
  54. package/dist/cloudflare/core/tokens/formatters/dtcg.js +376 -0
  55. package/dist/cloudflare/core/tokens/formatters/index.js +45 -0
  56. package/dist/cloudflare/core/tokens/formatters/json.js +205 -0
  57. package/dist/cloudflare/core/tokens/formatters/less.js +4 -0
  58. package/dist/cloudflare/core/tokens/formatters/scss.js +258 -0
  59. package/dist/cloudflare/core/tokens/formatters/stubs.js +13 -0
  60. package/dist/cloudflare/core/tokens/formatters/style-dictionary-v3.js +213 -0
  61. package/dist/cloudflare/core/tokens/formatters/tailwind-v3.js +237 -0
  62. package/dist/cloudflare/core/tokens/formatters/tailwind-v4.js +335 -0
  63. package/dist/cloudflare/core/tokens/formatters/tokens-studio.js +256 -0
  64. package/dist/cloudflare/core/tokens/formatters/ts-module.js +198 -0
  65. package/dist/cloudflare/core/tokens/index.js +16 -0
  66. package/dist/cloudflare/core/tokens/parsers/css-vars.js +4 -0
  67. package/dist/cloudflare/core/tokens/parsers/dtcg.js +280 -0
  68. package/dist/cloudflare/core/tokens/parsers/index.js +138 -0
  69. package/dist/cloudflare/core/tokens/parsers/json.js +7 -0
  70. package/dist/cloudflare/core/tokens/parsers/scss.js +4 -0
  71. package/dist/cloudflare/core/tokens/parsers/stubs.js +20 -0
  72. package/dist/cloudflare/core/tokens/parsers/style-dictionary-v3.js +4 -0
  73. package/dist/cloudflare/core/tokens/parsers/tailwind-v3.js +4 -0
  74. package/dist/cloudflare/core/tokens/parsers/tailwind-v4.js +4 -0
  75. package/dist/cloudflare/core/tokens/parsers/tokens-studio.js +4 -0
  76. package/dist/cloudflare/core/tokens/schemas.js +152 -0
  77. package/dist/cloudflare/core/tokens/transforms/color.js +12 -0
  78. package/dist/cloudflare/core/tokens/transforms/index.js +29 -0
  79. package/dist/cloudflare/core/tokens/transforms/size.js +7 -0
  80. package/dist/cloudflare/core/tokens/types.js +18 -0
  81. package/dist/cloudflare/core/tokens-tools.js +1788 -0
  82. package/dist/cloudflare/core/types/design-code.js +4 -0
  83. package/dist/cloudflare/core/types/enriched.js +5 -0
  84. package/dist/cloudflare/core/types/index.js +4 -0
  85. package/dist/cloudflare/core/variable-resolver.js +85 -0
  86. package/dist/cloudflare/core/version-tools.js +1199 -0
  87. package/dist/cloudflare/core/websocket-connector.js +436 -0
  88. package/dist/cloudflare/core/websocket-server.js +1009 -0
  89. package/dist/cloudflare/core/write-tools.js +2506 -0
  90. package/dist/cloudflare/index.js +3010 -0
  91. package/dist/core/accessibility-tools.d.ts.map +1 -1
  92. package/dist/core/accessibility-tools.js +7 -6
  93. package/dist/core/accessibility-tools.js.map +1 -1
  94. package/dist/core/http-request-guard.d.ts +20 -0
  95. package/dist/core/http-request-guard.d.ts.map +1 -0
  96. package/dist/core/http-request-guard.js +61 -0
  97. package/dist/core/http-request-guard.js.map +1 -0
  98. package/dist/core/port-discovery.d.ts +9 -0
  99. package/dist/core/port-discovery.d.ts.map +1 -1
  100. package/dist/core/port-discovery.js +40 -14
  101. package/dist/core/port-discovery.js.map +1 -1
  102. package/dist/core/tokens/schemas.d.ts +6 -6
  103. package/dist/local.d.ts.map +1 -1
  104. package/dist/local.js +9 -10
  105. package/dist/local.js.map +1 -1
  106. package/figma-desktop-bridge/ui.html +7 -0
  107. package/package.json +2 -2
@@ -0,0 +1,265 @@
1
+ /**
2
+ * Design System Manifest Types
3
+ *
4
+ * A structured representation of a Figma design system that enables
5
+ * high-fidelity AI-assisted design generation.
6
+ */
7
+ /**
8
+ * Cache for design system manifests with TTL-based invalidation.
9
+ * Singleton pattern to share cache across tool calls.
10
+ */
11
+ export class DesignSystemManifestCache {
12
+ constructor() {
13
+ this.cache = new Map();
14
+ this.TTL_MS = 5 * 60 * 1000; // 5 minutes
15
+ }
16
+ static getInstance() {
17
+ if (!DesignSystemManifestCache.instance) {
18
+ DesignSystemManifestCache.instance = new DesignSystemManifestCache();
19
+ }
20
+ return DesignSystemManifestCache.instance;
21
+ }
22
+ get(fileKey) {
23
+ const entry = this.cache.get(fileKey);
24
+ if (!entry)
25
+ return null;
26
+ if (!this.isValid(entry)) {
27
+ this.cache.delete(fileKey);
28
+ return null;
29
+ }
30
+ return entry;
31
+ }
32
+ set(fileKey, manifest, rawComponents) {
33
+ this.cache.set(fileKey, {
34
+ manifest,
35
+ timestamp: Date.now(),
36
+ fileKey,
37
+ rawComponents,
38
+ });
39
+ }
40
+ invalidate(fileKey) {
41
+ this.cache.delete(fileKey);
42
+ }
43
+ invalidateAll() {
44
+ this.cache.clear();
45
+ }
46
+ isValid(entry) {
47
+ return Date.now() - entry.timestamp < this.TTL_MS;
48
+ }
49
+ getStats() {
50
+ const stats = [];
51
+ for (const [fileKey, entry] of this.cache) {
52
+ stats.push({
53
+ fileKey,
54
+ age: Math.round((Date.now() - entry.timestamp) / 1000),
55
+ componentCount: entry.manifest.summary.totalComponents + entry.manifest.summary.totalComponentSets,
56
+ tokenCount: entry.manifest.summary.totalTokens,
57
+ });
58
+ }
59
+ return stats;
60
+ }
61
+ }
62
+ /**
63
+ * Search components by name, category, or description
64
+ */
65
+ export function searchComponents(manifest, query, options) {
66
+ const limit = options?.limit ?? 10;
67
+ const offset = options?.offset ?? 0;
68
+ const queryLower = query.toLowerCase();
69
+ const categoryLower = options?.category?.toLowerCase();
70
+ const allResults = [];
71
+ // Search component sets first (they're typically the main design system components).
72
+ // Manifest maps are keyed by component key — always read names from the entry.
73
+ for (const compSet of Object.values(manifest.componentSets)) {
74
+ const nameLower = compSet.name.toLowerCase();
75
+ const descLower = compSet.description?.toLowerCase() || '';
76
+ const matchesQuery = !query || nameLower.includes(queryLower) || descLower.includes(queryLower);
77
+ const matchesCategory = !categoryLower || inferCategory(compSet.name).toLowerCase().includes(categoryLower);
78
+ if (matchesQuery && matchesCategory) {
79
+ allResults.push({
80
+ name: compSet.name,
81
+ key: compSet.key,
82
+ nodeId: compSet.nodeId,
83
+ type: 'componentSet',
84
+ description: compSet.description,
85
+ category: inferCategory(compSet.name),
86
+ variantCount: compSet.variants?.length || 0,
87
+ });
88
+ }
89
+ }
90
+ // Then search standalone components
91
+ for (const comp of Object.values(manifest.components)) {
92
+ const nameLower = comp.name.toLowerCase();
93
+ const descLower = comp.description?.toLowerCase() || '';
94
+ const matchesQuery = !query || nameLower.includes(queryLower) || descLower.includes(queryLower);
95
+ const matchesCategory = !categoryLower || inferCategory(comp.name).toLowerCase().includes(categoryLower);
96
+ if (matchesQuery && matchesCategory) {
97
+ allResults.push({
98
+ name: comp.name,
99
+ key: comp.key,
100
+ nodeId: comp.nodeId,
101
+ type: 'component',
102
+ description: comp.description,
103
+ category: inferCategory(comp.name),
104
+ defaultSize: comp.defaultSize,
105
+ });
106
+ }
107
+ }
108
+ const total = allResults.length;
109
+ // Truncate long doc blocks in search hits — full text is available via
110
+ // figma_get_component_details.
111
+ const paginatedResults = allResults.slice(offset, offset + limit).map((r) => r.description && r.description.length > 200
112
+ ? { ...r, description: `${r.description.slice(0, 200)}…`, descriptionTruncated: true }
113
+ : r);
114
+ const hasMore = offset + limit < total;
115
+ return { results: paginatedResults, total, hasMore };
116
+ }
117
+ /**
118
+ * Infer category from component name (e.g., "Button/Primary" -> "Button")
119
+ */
120
+ function inferCategory(name) {
121
+ const parts = name.split('/');
122
+ return parts[0] || 'Uncategorized';
123
+ }
124
+ /**
125
+ * Get unique categories from manifest
126
+ */
127
+ export function getCategories(manifest) {
128
+ const categories = new Map();
129
+ for (const compSet of Object.values(manifest.componentSets)) {
130
+ const cat = inferCategory(compSet.name);
131
+ const existing = categories.get(cat) || { componentCount: 0, componentSetCount: 0 };
132
+ existing.componentSetCount++;
133
+ categories.set(cat, existing);
134
+ }
135
+ for (const comp of Object.values(manifest.components)) {
136
+ const cat = inferCategory(comp.name);
137
+ const existing = categories.get(cat) || { componentCount: 0, componentSetCount: 0 };
138
+ existing.componentCount++;
139
+ categories.set(cat, existing);
140
+ }
141
+ return Array.from(categories.entries())
142
+ .map(([name, counts]) => ({ name, ...counts }))
143
+ .sort((a, b) => (b.componentCount + b.componentSetCount) - (a.componentCount + a.componentSetCount));
144
+ }
145
+ /**
146
+ * Get token categories and counts for summary
147
+ */
148
+ export function getTokenSummary(manifest) {
149
+ // Group colors by prefix (e.g., "primary/500" -> "primary")
150
+ const colorGroups = new Set();
151
+ for (const name of Object.keys(manifest.tokens.colors)) {
152
+ const group = name.split('/')[0];
153
+ colorGroups.add(group);
154
+ }
155
+ // Group typography by prefix
156
+ const typographyGroups = new Set();
157
+ for (const name of Object.keys(manifest.tokens.typography)) {
158
+ const group = name.split('/')[0];
159
+ typographyGroups.add(group);
160
+ }
161
+ // Get spacing scale values
162
+ const spacingValues = Object.values(manifest.tokens.spacing)
163
+ .map(t => t.value)
164
+ .filter((v, i, arr) => arr.indexOf(v) === i)
165
+ .sort((a, b) => a - b);
166
+ return {
167
+ colors: {
168
+ count: Object.keys(manifest.tokens.colors).length,
169
+ groups: Array.from(colorGroups).slice(0, 10),
170
+ },
171
+ spacing: {
172
+ count: Object.keys(manifest.tokens.spacing).length,
173
+ scale: spacingValues.slice(0, 15),
174
+ },
175
+ typography: {
176
+ count: Object.keys(manifest.tokens.typography).length,
177
+ groups: Array.from(typographyGroups).slice(0, 10),
178
+ },
179
+ effects: {
180
+ count: Object.keys(manifest.tokens.effects).length,
181
+ },
182
+ collections: manifest.collections.map(c => c.name),
183
+ };
184
+ }
185
+ // ============================================================================
186
+ // HELPER FUNCTIONS
187
+ // ============================================================================
188
+ /**
189
+ * Convert RGB color object to hex string
190
+ */
191
+ export function rgbToHex(color) {
192
+ const toHex = (n) => Math.round(n * 255).toString(16).padStart(2, '0');
193
+ return `#${toHex(color.r)}${toHex(color.g)}${toHex(color.b)}`.toUpperCase();
194
+ }
195
+ /**
196
+ * Parse a Figma color value to hex
197
+ */
198
+ export function figmaColorToHex(value) {
199
+ if (typeof value === 'string')
200
+ return value;
201
+ if (value && typeof value === 'object' && 'r' in value) {
202
+ return rgbToHex(value);
203
+ }
204
+ return '#000000';
205
+ }
206
+ /**
207
+ * Generate a human-readable summary of the manifest
208
+ */
209
+ export function generateManifestSummary(manifest) {
210
+ const lines = [
211
+ `# Design System Manifest`,
212
+ ``,
213
+ `**File:** ${manifest.fileName || manifest.fileKey}`,
214
+ `**Generated:** ${new Date(manifest.generatedAt).toISOString()}`,
215
+ ``,
216
+ `## Summary`,
217
+ `- **${manifest.summary.totalTokens}** design tokens`,
218
+ `- **${manifest.summary.totalComponents}** components`,
219
+ `- **${manifest.summary.totalComponentSets}** component sets`,
220
+ ``,
221
+ `## Color Palette`,
222
+ manifest.summary.colorPalette.slice(0, 10).map(c => `- ${c}`).join('\n'),
223
+ ``,
224
+ `## Spacing Scale`,
225
+ `${manifest.summary.spacingScale.join('px, ')}px`,
226
+ ``,
227
+ `## Typography`,
228
+ manifest.summary.typographyScale.slice(0, 10).map(t => `- ${t}`).join('\n'),
229
+ ``,
230
+ `## Component Categories`,
231
+ manifest.summary.componentCategories.map(c => `- ${c}`).join('\n'),
232
+ ];
233
+ return lines.join('\n');
234
+ }
235
+ /**
236
+ * Create an empty manifest template
237
+ */
238
+ export function createEmptyManifest(fileKey) {
239
+ return {
240
+ version: '1.0.0',
241
+ generatedAt: Date.now(),
242
+ fileKey,
243
+ collections: [],
244
+ tokens: {
245
+ colors: {},
246
+ spacing: {},
247
+ typography: {},
248
+ effects: {},
249
+ other: {},
250
+ },
251
+ components: {},
252
+ componentSets: {},
253
+ patterns: {},
254
+ rules: [],
255
+ summary: {
256
+ totalTokens: 0,
257
+ totalComponents: 0,
258
+ totalComponentSets: 0,
259
+ colorPalette: [],
260
+ spacingScale: [],
261
+ typographyScale: [],
262
+ componentCategories: [],
263
+ },
264
+ };
265
+ }