Skip to content

Commit c48b802

Browse files
authored
Change format of component properties in simplified response. (#112)
1 parent 6e99226 commit c48b802

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

.changeset/fancy-bobcats-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"figma-developer-mcp": patch
3+
---
4+
5+
Change format of component properties in simplified response.

src/services/simplify-node-response.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
Paint,
66
Vector,
77
GetFileResponse,
8+
ComponentPropertyType,
89
Component,
910
ComponentSet,
1011
} from "@figma/rest-api-spec";
@@ -61,6 +62,7 @@ type StyleTypes =
6162
type GlobalVars = {
6263
styles: Record<StyleId, StyleTypes>;
6364
};
65+
6466
export interface SimplifiedDesign {
6567
name: string;
6668
lastModified: string;
@@ -71,6 +73,12 @@ export interface SimplifiedDesign {
7173
globalVars: GlobalVars;
7274
}
7375

76+
export interface ComponentProperties {
77+
name: string;
78+
value: string;
79+
type: ComponentPropertyType;
80+
}
81+
7482
export interface SimplifiedNode {
7583
id: string;
7684
name: string;
@@ -92,7 +100,7 @@ export interface SimplifiedNode {
92100
// backgroundColor?: ColorValue; // Deprecated by Figma API
93101
// for rect-specific strokes, etc.
94102
componentId?: string;
95-
componentProperties?: Record<string, any>;
103+
componentProperties?: ComponentProperties[];
96104
// children
97105
children?: SimplifiedNode[];
98106
}
@@ -239,8 +247,16 @@ function parseNode(
239247
if (hasValue("componentId", n)) {
240248
simplified.componentId = n.componentId;
241249
}
250+
251+
// Add specific properties for instances of components
242252
if (hasValue("componentProperties", n)) {
243-
simplified.componentProperties = n.componentProperties;
253+
simplified.componentProperties = Object.entries(n.componentProperties ?? {}).map(
254+
([name, { value, type }]) => ({
255+
name,
256+
value: value.toString(),
257+
type,
258+
}),
259+
);
244260
}
245261
}
246262

@@ -308,8 +324,9 @@ function parseNode(
308324
simplified.borderRadius = `${n.rectangleCornerRadii[0]}px ${n.rectangleCornerRadii[1]}px ${n.rectangleCornerRadii[2]}px ${n.rectangleCornerRadii[3]}px`;
309325
}
310326

311-
// Recursively process child nodes
312-
if (hasValue("children", n) && Array.isArray(n.children) && n.children.length > 0) {
327+
// Recursively process child nodes.
328+
// Include children at the very end so all relevant configuration data for the element is output first and kept together for the AI.
329+
if (hasValue("children", n) && n.children.length > 0) {
313330
const children = n.children
314331
.filter(isVisible)
315332
.map((child) => parseNode(globalVars, child, n))

0 commit comments

Comments
 (0)