@fragments-sdk/context 0.2.0 → 0.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.
@@ -58,7 +58,6 @@ function mergeOverlapping(chunks) {
58
58
  if (next.startLine <= current.endLine + 1) {
59
59
  const currentLines = current.content.split("\n");
60
60
  const nextLines = next.content.split("\n");
61
- const overlapStart = next.startLine - current.startLine;
62
61
  const newLines = nextLines.slice(current.endLine - next.startLine + 1);
63
62
  if (newLines.length > 0) {
64
63
  current = {
@@ -0,0 +1,310 @@
1
+ // src/mcp-tools/index.ts
2
+ var MCP_TOOL_DEFINITIONS = [
3
+ {
4
+ key: "discover",
5
+ description: "Discover components in the design system. Use with no params to list all components. Use 'useCase' for AI-powered suggestions. Use 'component' to find alternatives. Use 'compact' for a token-efficient overview.",
6
+ params: {
7
+ useCase: {
8
+ type: "string",
9
+ description: 'Description of what you want to build \u2014 returns ranked suggestions (e.g., "form for user email input", "button to submit data")'
10
+ },
11
+ component: {
12
+ type: "string",
13
+ description: 'Component name to find alternatives for (e.g., "Button")'
14
+ },
15
+ category: {
16
+ type: "string",
17
+ description: 'Filter by category (e.g., "actions", "forms", "layout")'
18
+ },
19
+ search: {
20
+ type: "string",
21
+ description: "Search term to filter by name, description, or tags"
22
+ },
23
+ status: {
24
+ type: "string",
25
+ enum: ["stable", "beta", "deprecated", "experimental"],
26
+ description: "Filter by component status"
27
+ },
28
+ format: {
29
+ type: "string",
30
+ enum: ["markdown", "json"],
31
+ description: "Output format for context mode (default: markdown)"
32
+ },
33
+ compact: {
34
+ type: "boolean",
35
+ description: "If true, returns minimal output (just component names and categories)"
36
+ },
37
+ includeCode: {
38
+ type: "boolean",
39
+ description: "If true, includes code examples for each variant"
40
+ },
41
+ includeRelations: {
42
+ type: "boolean",
43
+ description: "If true, includes component relationships"
44
+ }
45
+ }
46
+ },
47
+ {
48
+ key: "inspect",
49
+ description: "Get detailed information about a specific component: props, usage guidelines, code examples, accessibility \u2014 all in one call. Use 'fields' to request only specific data for token efficiency.",
50
+ params: {
51
+ component: {
52
+ type: "string",
53
+ description: 'Component name (e.g., "Button", "Input")'
54
+ },
55
+ fields: {
56
+ type: "array",
57
+ items: { type: "string" },
58
+ description: 'Specific fields to return (e.g., ["meta", "usage.when", "contract.propsSummary", "props", "examples", "guidelines"]). If omitted, returns everything. Supports dot notation.'
59
+ },
60
+ variant: {
61
+ type: "string",
62
+ description: 'Filter examples to a specific variant name (e.g., "Default", "Primary")'
63
+ },
64
+ maxExamples: {
65
+ type: "number",
66
+ description: "Maximum number of code examples to return (default: all)"
67
+ },
68
+ maxLines: {
69
+ type: "number",
70
+ description: "Maximum lines per code example (truncates longer examples)"
71
+ }
72
+ },
73
+ required: ["component"]
74
+ },
75
+ {
76
+ key: "blocks",
77
+ description: 'Search and retrieve composition blocks \u2014 named patterns showing how design system components wire together for common use cases (e.g., "Login Form", "Settings Page"). Returns the block with its code pattern.',
78
+ params: {
79
+ name: {
80
+ type: "string",
81
+ description: 'Exact block name to retrieve (e.g., "Login Form")'
82
+ },
83
+ search: {
84
+ type: "string",
85
+ description: "Free-text search across block names, descriptions, tags, and components"
86
+ },
87
+ component: {
88
+ type: "string",
89
+ description: 'Filter blocks that use a specific component (e.g., "Button")'
90
+ },
91
+ category: {
92
+ type: "string",
93
+ description: 'Filter by category (e.g., "authentication", "marketing", "dashboard", "settings", "ecommerce", "ai")'
94
+ }
95
+ }
96
+ },
97
+ {
98
+ key: "tokens",
99
+ description: "List available CSS design tokens (custom properties) by category. Use this when you need to style custom elements or override defaults \u2014 no more guessing variable names. Filter by category or search by keyword.",
100
+ params: {
101
+ category: {
102
+ type: "string",
103
+ description: 'Filter by category (e.g., "colors", "spacing", "typography", "surfaces", "shadows", "radius", "borders", "text", "focus", "layout", "code", "component-sizing")'
104
+ },
105
+ search: {
106
+ type: "string",
107
+ description: 'Search token names (e.g., "accent", "hover", "padding")'
108
+ }
109
+ }
110
+ },
111
+ {
112
+ key: "implement",
113
+ description: "One-shot implementation helper. Describe what you want to build and get everything needed in a single call: best-matching component(s) with full props and code examples, relevant composition blocks, and applicable CSS tokens. Saves multiple round-trips.",
114
+ params: {
115
+ useCase: {
116
+ type: "string",
117
+ description: 'What you want to implement (e.g., "login form", "data table with sorting", "streaming chat messages")'
118
+ }
119
+ },
120
+ required: ["useCase"]
121
+ },
122
+ {
123
+ key: "render",
124
+ description: "Render a component and return a screenshot. Optionally compare against a Figma design ('figmaUrl'). Requires a running Fragments dev server (viewer URL). Use this to verify your implementation looks correct.",
125
+ params: {
126
+ component: {
127
+ type: "string",
128
+ description: 'Component name (e.g., "Button", "Card", "Input")'
129
+ },
130
+ props: {
131
+ type: "object",
132
+ description: 'Props to pass to the component (e.g., { "variant": "primary", "children": "Click me" })'
133
+ },
134
+ viewport: {
135
+ type: "object",
136
+ properties: {
137
+ width: {
138
+ type: "number",
139
+ description: "Viewport width (default: 800)"
140
+ },
141
+ height: {
142
+ type: "number",
143
+ description: "Viewport height (default: 600)"
144
+ }
145
+ },
146
+ description: "Optional viewport size for the render"
147
+ },
148
+ figmaUrl: {
149
+ type: "string",
150
+ description: "Figma frame URL \u2014 if provided, compares the render against the Figma design"
151
+ },
152
+ variant: {
153
+ type: "string",
154
+ description: "Variant name for compare mode"
155
+ },
156
+ threshold: {
157
+ type: "number",
158
+ description: "Diff threshold percentage (default: 1 for Figma)"
159
+ }
160
+ },
161
+ required: ["component"]
162
+ },
163
+ {
164
+ key: "fix",
165
+ description: "Generate patches to fix token compliance issues in a component. Returns unified diff patches that replace hardcoded CSS values with design token references. Requires a running Fragments dev server.",
166
+ params: {
167
+ component: {
168
+ type: "string",
169
+ description: 'Component name to generate fixes for (e.g., "Button", "Card")'
170
+ },
171
+ variant: {
172
+ type: "string",
173
+ description: "Specific variant to fix (optional, fixes all variants if omitted)"
174
+ },
175
+ fixType: {
176
+ type: "string",
177
+ enum: ["token", "all"],
178
+ description: 'Type of fixes to generate: "token" for hardcoded\u2192token replacements, "all" for all available fixes (default: "all")'
179
+ }
180
+ },
181
+ required: ["component"]
182
+ },
183
+ {
184
+ key: "graph",
185
+ description: 'Query the component relationship graph. Understand dependencies, impact analysis, composition trees, alternatives, and design system health. Use "health" for an overview, "dependencies"/"dependents" for direct relationships, "impact" for change analysis, "composition" for compound component trees.',
186
+ params: {
187
+ mode: {
188
+ type: "string",
189
+ enum: ["dependencies", "dependents", "impact", "path", "composition", "alternatives", "islands", "health"],
190
+ description: "Query mode"
191
+ },
192
+ component: {
193
+ type: "string",
194
+ description: "Component name (required for most modes)"
195
+ },
196
+ target: {
197
+ type: "string",
198
+ description: 'Target component for "path" mode'
199
+ },
200
+ edgeTypes: {
201
+ type: "array",
202
+ items: { type: "string" },
203
+ description: "Filter by edge types (imports, hook-depends, renders, composes, parent-of, alternative-to, sibling-of)"
204
+ },
205
+ maxDepth: {
206
+ type: "number",
207
+ description: "Max traversal depth for impact mode (default: 3)"
208
+ }
209
+ },
210
+ required: ["mode"]
211
+ },
212
+ {
213
+ key: "a11y",
214
+ description: "Run an accessibility audit on a component. Returns axe-core violations, a WCAG compliance score, and optional fix suggestions. Requires a running Fragments dev server.",
215
+ params: {
216
+ component: {
217
+ type: "string",
218
+ description: 'Component name to audit (e.g., "Button", "Card")'
219
+ },
220
+ variant: {
221
+ type: "string",
222
+ description: "Specific variant to audit (optional, audits all variants if omitted)"
223
+ },
224
+ standard: {
225
+ type: "string",
226
+ enum: ["AA", "AAA"],
227
+ description: "WCAG compliance level to check against (default: AA)"
228
+ },
229
+ includeFixPatches: {
230
+ type: "boolean",
231
+ description: "If true, includes auto-fix suggestions for each violation"
232
+ }
233
+ },
234
+ required: ["component"]
235
+ }
236
+ ];
237
+ var CLI_TOOL_EXTENSIONS = [
238
+ {
239
+ key: "render",
240
+ description: "Render a component and return a screenshot. Optionally compare against a stored baseline ('baseline: true') or against a Figma design ('figmaUrl'). Use this to verify your implementation looks correct.",
241
+ params: {
242
+ baseline: {
243
+ type: "boolean",
244
+ description: "If true, compares the render against the stored baseline screenshot (requires variant)"
245
+ },
246
+ theme: {
247
+ type: "string",
248
+ enum: ["light", "dark"],
249
+ description: "Theme for baseline verification (default: light)"
250
+ }
251
+ }
252
+ },
253
+ {
254
+ key: "fix",
255
+ description: "Generate patches to fix token compliance issues in a component. Returns unified diff patches that replace hardcoded CSS values with design token references. Use this after fragments_render identifies issues to automatically fix them.",
256
+ params: {}
257
+ }
258
+ ];
259
+ function buildToolNames(prefix) {
260
+ const map = {};
261
+ for (const def of MCP_TOOL_DEFINITIONS) {
262
+ map[def.key] = `${prefix}_${def.key}`;
263
+ }
264
+ return map;
265
+ }
266
+ function buildMcpTools(prefix, extensions) {
267
+ const extMap = /* @__PURE__ */ new Map();
268
+ if (extensions) {
269
+ for (const ext of extensions) {
270
+ extMap.set(ext.key, ext);
271
+ }
272
+ }
273
+ return MCP_TOOL_DEFINITIONS.map((def) => {
274
+ const ext = extMap.get(def.key);
275
+ const mergedParams = ext ? { ...def.params, ...ext.params } : def.params;
276
+ const properties = {};
277
+ for (const [name, param] of Object.entries(mergedParams)) {
278
+ const prop = {
279
+ type: param.type,
280
+ description: param.description
281
+ };
282
+ if (param.enum) prop.enum = param.enum;
283
+ if (param.items) prop.items = param.items;
284
+ if (param.properties) {
285
+ const nested = {};
286
+ for (const [k, v] of Object.entries(param.properties)) {
287
+ nested[k] = { type: v.type, description: v.description };
288
+ }
289
+ prop.properties = nested;
290
+ }
291
+ properties[name] = prop;
292
+ }
293
+ return {
294
+ name: `${prefix}_${def.key}`,
295
+ description: ext?.description ?? def.description,
296
+ inputSchema: {
297
+ type: "object",
298
+ properties,
299
+ ...def.required && { required: def.required }
300
+ }
301
+ };
302
+ });
303
+ }
304
+
305
+ export {
306
+ MCP_TOOL_DEFINITIONS,
307
+ CLI_TOOL_EXTENSIONS,
308
+ buildToolNames,
309
+ buildMcpTools
310
+ };