@primer/mcp 0.3.0 → 0.3.1
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/dist/index.js +2 -1
- package/dist/primitives.d.ts +80 -4
- package/dist/primitives.d.ts.map +1 -1
- package/dist/{server-Cwz0naYT.js → server-owUZMSeG.js} +130 -49
- package/dist/server.d.ts.map +1 -1
- package/dist/stdio.js +2 -1
- package/package.json +2 -2
- package/src/primitives.ts +113 -45
- package/src/server.ts +38 -1
- package/dist/server-CjO5UCV7.js +0 -766
package/dist/server-CjO5UCV7.js
DELETED
|
@@ -1,766 +0,0 @@
|
|
|
1
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
import * as cheerio from 'cheerio';
|
|
3
|
-
import * as z from 'zod';
|
|
4
|
-
import TurndownService from 'turndown';
|
|
5
|
-
import componentsMetadata from '@primer/react/generated/components.json' with { type: 'json' };
|
|
6
|
-
import octicons from '@primer/octicons/build/data.json' with { type: 'json' };
|
|
7
|
-
import baseMotion from '@primer/primitives/dist/docs/base/motion/motion.json' with { type: 'json' };
|
|
8
|
-
import baseSize from '@primer/primitives/dist/docs/base/size/size.json' with { type: 'json' };
|
|
9
|
-
import baseTypography from '@primer/primitives/dist/docs/base/typography/typography.json' with { type: 'json' };
|
|
10
|
-
import functionalSizeBorder from '@primer/primitives/dist/docs/functional/size/border.json' with { type: 'json' };
|
|
11
|
-
import functionalSizeCoarse from '@primer/primitives/dist/docs/functional/size/size-coarse.json' with { type: 'json' };
|
|
12
|
-
import functionalSizeFine from '@primer/primitives/dist/docs/functional/size/size-fine.json' with { type: 'json' };
|
|
13
|
-
import functionalSize from '@primer/primitives/dist/docs/functional/size/size.json' with { type: 'json' };
|
|
14
|
-
import light from '@primer/primitives/dist/docs/functional/themes/light.json' with { type: 'json' };
|
|
15
|
-
import functionalTypography from '@primer/primitives/dist/docs/functional/typography/typography.json' with { type: 'json' };
|
|
16
|
-
|
|
17
|
-
function idToSlug(id) {
|
|
18
|
-
if (id === 'actionbar') {
|
|
19
|
-
return 'action-bar';
|
|
20
|
-
}
|
|
21
|
-
if (id === 'tooltip-v2') {
|
|
22
|
-
return 'tooltip';
|
|
23
|
-
}
|
|
24
|
-
if (id === 'dialog_v2') {
|
|
25
|
-
return 'dialog';
|
|
26
|
-
}
|
|
27
|
-
return id.replaceAll('_', '-');
|
|
28
|
-
}
|
|
29
|
-
const components = Object.entries(componentsMetadata.components).map(([id, component]) => {
|
|
30
|
-
return {
|
|
31
|
-
id,
|
|
32
|
-
name: component.name,
|
|
33
|
-
importPath: component.importPath,
|
|
34
|
-
slug: idToSlug(id)
|
|
35
|
-
};
|
|
36
|
-
});
|
|
37
|
-
function listComponents() {
|
|
38
|
-
return components;
|
|
39
|
-
}
|
|
40
|
-
const patterns = [{
|
|
41
|
-
id: 'data-visualization',
|
|
42
|
-
name: 'Data Visualization'
|
|
43
|
-
}, {
|
|
44
|
-
id: 'degraded-experiences',
|
|
45
|
-
name: 'Degraded Experiences'
|
|
46
|
-
}, {
|
|
47
|
-
id: 'empty-states',
|
|
48
|
-
name: 'Empty States'
|
|
49
|
-
}, {
|
|
50
|
-
id: 'feature-onboarding',
|
|
51
|
-
name: 'Feature Onboarding'
|
|
52
|
-
}, {
|
|
53
|
-
id: 'forms',
|
|
54
|
-
name: 'Forms'
|
|
55
|
-
}, {
|
|
56
|
-
id: 'loading',
|
|
57
|
-
name: 'Loading'
|
|
58
|
-
}, {
|
|
59
|
-
id: 'navigation',
|
|
60
|
-
name: 'Navigation'
|
|
61
|
-
}, {
|
|
62
|
-
id: 'notification-messaging',
|
|
63
|
-
name: 'Notification message'
|
|
64
|
-
}, {
|
|
65
|
-
id: 'progressive-disclosure',
|
|
66
|
-
name: 'Progressive disclosure'
|
|
67
|
-
}, {
|
|
68
|
-
id: 'saving',
|
|
69
|
-
name: 'Saving'
|
|
70
|
-
}];
|
|
71
|
-
function listPatterns() {
|
|
72
|
-
return patterns;
|
|
73
|
-
}
|
|
74
|
-
const icons = Object.values(octicons).map(icon => {
|
|
75
|
-
return {
|
|
76
|
-
name: icon.name,
|
|
77
|
-
keywords: icon.keywords,
|
|
78
|
-
heights: Object.keys(icon.heights)
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
function listIcons() {
|
|
82
|
-
return icons;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const categories = {
|
|
86
|
-
base: {
|
|
87
|
-
motion: Object.values(baseMotion).map(token => {
|
|
88
|
-
return {
|
|
89
|
-
name: token.name,
|
|
90
|
-
type: token.type,
|
|
91
|
-
value: token.value
|
|
92
|
-
};
|
|
93
|
-
}),
|
|
94
|
-
size: Object.values(baseSize).map(token => {
|
|
95
|
-
return {
|
|
96
|
-
name: token.name,
|
|
97
|
-
type: token.type,
|
|
98
|
-
value: token.value
|
|
99
|
-
};
|
|
100
|
-
}),
|
|
101
|
-
typography: Object.values(baseTypography).map(token => {
|
|
102
|
-
return {
|
|
103
|
-
name: token.name,
|
|
104
|
-
type: token.type,
|
|
105
|
-
value: token.value
|
|
106
|
-
};
|
|
107
|
-
})
|
|
108
|
-
},
|
|
109
|
-
functional: {
|
|
110
|
-
border: Object.values(functionalSizeBorder).map(token => {
|
|
111
|
-
return {
|
|
112
|
-
name: token.name,
|
|
113
|
-
type: token.type,
|
|
114
|
-
value: token.value
|
|
115
|
-
};
|
|
116
|
-
}),
|
|
117
|
-
sizeCoarse: Object.values(functionalSizeCoarse).map(token => {
|
|
118
|
-
return {
|
|
119
|
-
name: token.name,
|
|
120
|
-
type: token.type,
|
|
121
|
-
value: token.value
|
|
122
|
-
};
|
|
123
|
-
}),
|
|
124
|
-
sizeFine: Object.values(functionalSizeFine).map(token => {
|
|
125
|
-
return {
|
|
126
|
-
name: token.name,
|
|
127
|
-
type: token.type,
|
|
128
|
-
value: token.value
|
|
129
|
-
};
|
|
130
|
-
}),
|
|
131
|
-
size: Object.values(functionalSize).map(token => {
|
|
132
|
-
return {
|
|
133
|
-
name: token.name,
|
|
134
|
-
type: token.type,
|
|
135
|
-
value: token.value
|
|
136
|
-
};
|
|
137
|
-
}),
|
|
138
|
-
themes: {
|
|
139
|
-
light: Object.values(light).map(token => {
|
|
140
|
-
return {
|
|
141
|
-
name: token.name,
|
|
142
|
-
type: token.type,
|
|
143
|
-
value: token.value
|
|
144
|
-
};
|
|
145
|
-
})
|
|
146
|
-
},
|
|
147
|
-
typography: Object.values(functionalTypography).map(token => {
|
|
148
|
-
return {
|
|
149
|
-
name: token.name,
|
|
150
|
-
type: token.type,
|
|
151
|
-
value: token.value
|
|
152
|
-
};
|
|
153
|
-
})
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
const tokens = [...categories.base.motion, ...categories.base.size, ...categories.base.typography, ...categories.functional.border, ...categories.functional.sizeCoarse, ...categories.functional.sizeFine, ...categories.functional.size, ...categories.functional.themes.light, ...categories.functional.typography];
|
|
157
|
-
function serialize(value) {
|
|
158
|
-
return value.map(token => {
|
|
159
|
-
return `<token name="${token.name}" value="${token.value}" type="${token.type}"></token>`;
|
|
160
|
-
}).join('\n');
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
var version = "0.2.0";
|
|
164
|
-
var packageJson = {
|
|
165
|
-
version: version};
|
|
166
|
-
|
|
167
|
-
const server = new McpServer({
|
|
168
|
-
name: 'Primer',
|
|
169
|
-
version: packageJson.version
|
|
170
|
-
});
|
|
171
|
-
const turndownService = new TurndownService();
|
|
172
|
-
|
|
173
|
-
// -----------------------------------------------------------------------------
|
|
174
|
-
// Project setup
|
|
175
|
-
// -----------------------------------------------------------------------------
|
|
176
|
-
server.registerTool('init', {
|
|
177
|
-
description: 'Setup or create a project that includes Primer React'
|
|
178
|
-
}, async () => {
|
|
179
|
-
const url = new URL(`/product/getting-started/react`, 'https://primer.style');
|
|
180
|
-
const response = await fetch(url);
|
|
181
|
-
if (!response.ok) {
|
|
182
|
-
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
183
|
-
}
|
|
184
|
-
const html = await response.text();
|
|
185
|
-
if (!html) {
|
|
186
|
-
return {
|
|
187
|
-
content: []
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
const $ = cheerio.load(html);
|
|
191
|
-
const source = $('main').html();
|
|
192
|
-
if (!source) {
|
|
193
|
-
return {
|
|
194
|
-
content: []
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
const text = turndownService.turndown(source);
|
|
198
|
-
return {
|
|
199
|
-
content: [{
|
|
200
|
-
type: 'text',
|
|
201
|
-
text: `The getting started documentation for Primer React is included below. It's important that the project:
|
|
202
|
-
|
|
203
|
-
- Is using a tool like Vite, Next.js, etc that supports TypeScript and React. If the project does not have support for that, generate an appropriate project scaffold
|
|
204
|
-
- Installs the latest version of \`@primer/react\` from \`npm\`
|
|
205
|
-
- Correctly adds the \`ThemeProvider\` and \`BaseStyles\` components to the root of the application
|
|
206
|
-
- Includes an import to a theme from \`@primer/primitives\`
|
|
207
|
-
- If the project wants to use icons, also install the \`@primer/octicons-react\` from \`npm\`
|
|
208
|
-
- Add appropriate agent instructions (like for copilot) to the project to prefer using components, tokens, icons, and more from Primer packages
|
|
209
|
-
|
|
210
|
-
---
|
|
211
|
-
|
|
212
|
-
${text}
|
|
213
|
-
`
|
|
214
|
-
}]
|
|
215
|
-
};
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
// -----------------------------------------------------------------------------
|
|
219
|
-
// Components
|
|
220
|
-
// -----------------------------------------------------------------------------
|
|
221
|
-
server.registerTool('list_components', {
|
|
222
|
-
description: 'List all of the components available from Primer React'
|
|
223
|
-
}, async () => {
|
|
224
|
-
const components = listComponents().map(component => {
|
|
225
|
-
return `- ${component.name}`;
|
|
226
|
-
});
|
|
227
|
-
return {
|
|
228
|
-
content: [{
|
|
229
|
-
type: 'text',
|
|
230
|
-
text: `The following components are available in the @primer/react in TypeScript projects:
|
|
231
|
-
|
|
232
|
-
${components.join('\n')}
|
|
233
|
-
|
|
234
|
-
You can use the \`get_component\` tool to get more information about a specific component. You can use these components from the @primer/react package.`
|
|
235
|
-
}]
|
|
236
|
-
};
|
|
237
|
-
});
|
|
238
|
-
server.registerTool('get_component', {
|
|
239
|
-
description: 'Retrieve documentation and usage details for a specific React component from the @primer/react package by its name. This tool provides the official Primer documentation for any listed component, making it easy to inspect, reuse, or integrate components in your project.',
|
|
240
|
-
inputSchema: {
|
|
241
|
-
name: z.string().describe('The name of the component to retrieve')
|
|
242
|
-
}
|
|
243
|
-
}, async ({
|
|
244
|
-
name
|
|
245
|
-
}) => {
|
|
246
|
-
const components = listComponents();
|
|
247
|
-
const match = components.find(component => {
|
|
248
|
-
return component.name === name || component.name.toLowerCase() === name.toLowerCase();
|
|
249
|
-
});
|
|
250
|
-
if (!match) {
|
|
251
|
-
return {
|
|
252
|
-
isError: true,
|
|
253
|
-
errorMessage: `There is no component named \`${name}\` in the @primer/react package. For a full list of components, use the \`list_components\` tool.`,
|
|
254
|
-
content: []
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
const llmsUrl = new URL(`/product/components/${match.slug}/llms.txt`, 'https://primer.style');
|
|
258
|
-
const llmsResponse = await fetch(llmsUrl);
|
|
259
|
-
if (llmsResponse.ok) {
|
|
260
|
-
try {
|
|
261
|
-
const llmsText = await llmsResponse.text();
|
|
262
|
-
return {
|
|
263
|
-
content: [{
|
|
264
|
-
type: 'text',
|
|
265
|
-
text: llmsText
|
|
266
|
-
}]
|
|
267
|
-
};
|
|
268
|
-
} catch (_) {
|
|
269
|
-
// If there's an error fetching or processing the llms.txt, we fall back to the regular documentation
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
const url = new URL(`/product/components/${match.slug}`, 'https://primer.style');
|
|
273
|
-
const response = await fetch(url);
|
|
274
|
-
if (!response.ok) {
|
|
275
|
-
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
276
|
-
}
|
|
277
|
-
const html = await response.text();
|
|
278
|
-
if (!html) {
|
|
279
|
-
return {
|
|
280
|
-
content: []
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
const $ = cheerio.load(html);
|
|
284
|
-
const source = $('main').html();
|
|
285
|
-
if (!source) {
|
|
286
|
-
return {
|
|
287
|
-
content: []
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
const text = turndownService.turndown(source);
|
|
291
|
-
return {
|
|
292
|
-
content: [{
|
|
293
|
-
type: 'text',
|
|
294
|
-
text: `Here is the documentation for the \`${name}\` component from the @primer/react package:
|
|
295
|
-
${text}`
|
|
296
|
-
}]
|
|
297
|
-
};
|
|
298
|
-
});
|
|
299
|
-
server.registerTool('get_component_examples', {
|
|
300
|
-
description: 'Get examples for how to use a component from Primer React',
|
|
301
|
-
inputSchema: {
|
|
302
|
-
name: z.string().describe('The name of the component to retrieve')
|
|
303
|
-
}
|
|
304
|
-
}, async ({
|
|
305
|
-
name
|
|
306
|
-
}) => {
|
|
307
|
-
const components = listComponents();
|
|
308
|
-
const match = components.find(component => {
|
|
309
|
-
return component.name === name;
|
|
310
|
-
});
|
|
311
|
-
if (!match) {
|
|
312
|
-
return {
|
|
313
|
-
content: [{
|
|
314
|
-
type: 'text',
|
|
315
|
-
text: `There is no component named \`${name}\` in the @primer/react package. For a full list of components, use the \`get_components\` tool.`
|
|
316
|
-
}]
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
const url = new URL(`/product/components/${match.id}`, 'https://primer.style');
|
|
320
|
-
const response = await fetch(url);
|
|
321
|
-
if (!response.ok) {
|
|
322
|
-
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
323
|
-
}
|
|
324
|
-
const html = await response.text();
|
|
325
|
-
if (!html) {
|
|
326
|
-
return {
|
|
327
|
-
content: []
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
const $ = cheerio.load(html);
|
|
331
|
-
const source = $('main').html();
|
|
332
|
-
if (!source) {
|
|
333
|
-
return {
|
|
334
|
-
content: []
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
const text = turndownService.turndown(source);
|
|
338
|
-
return {
|
|
339
|
-
content: [{
|
|
340
|
-
type: 'text',
|
|
341
|
-
text: `Here are some examples of how to use the \`${name}\` component from the @primer/react package:
|
|
342
|
-
|
|
343
|
-
${text}`
|
|
344
|
-
}]
|
|
345
|
-
};
|
|
346
|
-
});
|
|
347
|
-
server.registerTool('get_component_usage_guidelines', {
|
|
348
|
-
description: 'Get usage information for how to use a component from Primer',
|
|
349
|
-
inputSchema: {
|
|
350
|
-
name: z.string().describe('The name of the component to retrieve')
|
|
351
|
-
}
|
|
352
|
-
}, async ({
|
|
353
|
-
name
|
|
354
|
-
}) => {
|
|
355
|
-
const components = listComponents();
|
|
356
|
-
const match = components.find(component => {
|
|
357
|
-
return component.name === name;
|
|
358
|
-
});
|
|
359
|
-
if (!match) {
|
|
360
|
-
return {
|
|
361
|
-
content: [{
|
|
362
|
-
type: 'text',
|
|
363
|
-
text: `There is no component named \`${name}\` in the @primer/react package. For a full list of components, use the \`get_components\` tool.`
|
|
364
|
-
}]
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
const url = new URL(`/product/components/${match.id}/guidelines`, 'https://primer.style');
|
|
368
|
-
const response = await fetch(url);
|
|
369
|
-
if (!response.ok) {
|
|
370
|
-
if (response.status >= 400 && response.status < 500 || response.status >= 300 && response.status < 400) {
|
|
371
|
-
return {
|
|
372
|
-
content: [{
|
|
373
|
-
type: 'text',
|
|
374
|
-
text: `There are no accessibility guidelines for the \`${name}\` component in the @primer/react package.`
|
|
375
|
-
}]
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
379
|
-
}
|
|
380
|
-
const html = await response.text();
|
|
381
|
-
if (!html) {
|
|
382
|
-
return {
|
|
383
|
-
content: []
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
const $ = cheerio.load(html);
|
|
387
|
-
const source = $('main').html();
|
|
388
|
-
if (!source) {
|
|
389
|
-
return {
|
|
390
|
-
content: []
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
const text = turndownService.turndown(source);
|
|
394
|
-
return {
|
|
395
|
-
content: [{
|
|
396
|
-
type: 'text',
|
|
397
|
-
text: `Here are the usage guidelines for the \`${name}\` component from the @primer/react package:
|
|
398
|
-
|
|
399
|
-
${text}`
|
|
400
|
-
}]
|
|
401
|
-
};
|
|
402
|
-
});
|
|
403
|
-
server.registerTool('get_component_accessibility_guidelines', {
|
|
404
|
-
description: 'Retrieve accessibility guidelines and best practices for a specific component from the @primer/react package by its name. Use this tool to get official accessibility recommendations, usage tips, and requirements to ensure your UI components are inclusive and meet accessibility standards.',
|
|
405
|
-
inputSchema: {
|
|
406
|
-
name: z.string().describe('The name of the component to retrieve')
|
|
407
|
-
}
|
|
408
|
-
}, async ({
|
|
409
|
-
name
|
|
410
|
-
}) => {
|
|
411
|
-
const components = listComponents();
|
|
412
|
-
const match = components.find(component => {
|
|
413
|
-
return component.name === name;
|
|
414
|
-
});
|
|
415
|
-
if (!match) {
|
|
416
|
-
return {
|
|
417
|
-
content: [{
|
|
418
|
-
type: 'text',
|
|
419
|
-
text: `There is no component named \`${name}\` in the @primer/react package. For a full list of components, use the \`list_components\` tool.`
|
|
420
|
-
}]
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
const url = new URL(`/product/components/${match.id}/accessibility`, 'https://primer.style');
|
|
424
|
-
const response = await fetch(url);
|
|
425
|
-
if (!response.ok) {
|
|
426
|
-
if (response.status >= 400 && response.status < 500 || response.status >= 300 && response.status < 400) {
|
|
427
|
-
return {
|
|
428
|
-
content: [{
|
|
429
|
-
type: 'text',
|
|
430
|
-
text: `There are no accessibility guidelines for the \`${name}\` component in the @primer/react package.`
|
|
431
|
-
}]
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
435
|
-
}
|
|
436
|
-
const html = await response.text();
|
|
437
|
-
if (!html) {
|
|
438
|
-
return {
|
|
439
|
-
content: []
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
const $ = cheerio.load(html);
|
|
443
|
-
const source = $('main').html();
|
|
444
|
-
if (!source) {
|
|
445
|
-
return {
|
|
446
|
-
content: []
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
const text = turndownService.turndown(source);
|
|
450
|
-
return {
|
|
451
|
-
content: [{
|
|
452
|
-
type: 'text',
|
|
453
|
-
text: `Here are the accessibility guidelines for the \`${name}\` component from the @primer/react package:
|
|
454
|
-
|
|
455
|
-
${text}`
|
|
456
|
-
}]
|
|
457
|
-
};
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
// -----------------------------------------------------------------------------
|
|
461
|
-
// Patterns
|
|
462
|
-
// -----------------------------------------------------------------------------
|
|
463
|
-
server.registerTool('list_patterns', {
|
|
464
|
-
description: 'List all of the patterns available from Primer React'
|
|
465
|
-
}, async () => {
|
|
466
|
-
const patterns = listPatterns().map(pattern => {
|
|
467
|
-
return `- ${pattern.name}`;
|
|
468
|
-
});
|
|
469
|
-
return {
|
|
470
|
-
content: [{
|
|
471
|
-
type: 'text',
|
|
472
|
-
text: `The following patterns are available in the @primer/react in TypeScript projects:
|
|
473
|
-
|
|
474
|
-
${patterns.join('\n')}`
|
|
475
|
-
}]
|
|
476
|
-
};
|
|
477
|
-
});
|
|
478
|
-
server.registerTool('get_pattern', {
|
|
479
|
-
description: 'Get a specific pattern by name',
|
|
480
|
-
inputSchema: {
|
|
481
|
-
name: z.string().describe('The name of the pattern to retrieve')
|
|
482
|
-
}
|
|
483
|
-
}, async ({
|
|
484
|
-
name
|
|
485
|
-
}) => {
|
|
486
|
-
const patterns = listPatterns();
|
|
487
|
-
const match = patterns.find(pattern => {
|
|
488
|
-
return pattern.name === name;
|
|
489
|
-
});
|
|
490
|
-
if (!match) {
|
|
491
|
-
return {
|
|
492
|
-
content: [{
|
|
493
|
-
type: 'text',
|
|
494
|
-
text: `There is no pattern named \`${name}\` in the @primer/react package. For a full list of patterns, use the \`list_patterns\` tool.`
|
|
495
|
-
}]
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
const url = new URL(`/product/ui-patterns/${match.id}`, 'https://primer.style');
|
|
499
|
-
const response = await fetch(url);
|
|
500
|
-
if (!response.ok) {
|
|
501
|
-
throw new Error(`Failed to fetch ${url} - ${response.statusText}`);
|
|
502
|
-
}
|
|
503
|
-
const html = await response.text();
|
|
504
|
-
if (!html) {
|
|
505
|
-
return {
|
|
506
|
-
content: []
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
const $ = cheerio.load(html);
|
|
510
|
-
const source = $('main').html();
|
|
511
|
-
if (!source) {
|
|
512
|
-
return {
|
|
513
|
-
content: []
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
const text = turndownService.turndown(source);
|
|
517
|
-
return {
|
|
518
|
-
content: [{
|
|
519
|
-
type: 'text',
|
|
520
|
-
text: `Here are the guidelines for the \`${name}\` pattern for Primer:
|
|
521
|
-
|
|
522
|
-
${text}`
|
|
523
|
-
}]
|
|
524
|
-
};
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
// -----------------------------------------------------------------------------
|
|
528
|
-
// Design Tokens
|
|
529
|
-
// -----------------------------------------------------------------------------
|
|
530
|
-
server.registerTool('list_tokens', {
|
|
531
|
-
description: 'List all of the design tokens available from Primer'
|
|
532
|
-
}, async () => {
|
|
533
|
-
let text = 'Below is a list of all design tokens available from Primer. Tokens are used in CSS and CSS Modules. To refer to the CSS Custom Property for a design token, wrap it in var(--{name-of-token}). To learn how to use a specific token, use a corresponding usage tool for the category of the token. For example, if a token is a color token look for the get_color_usage tool. \n\n';
|
|
534
|
-
text += serialize(tokens);
|
|
535
|
-
return {
|
|
536
|
-
content: [{
|
|
537
|
-
type: 'text',
|
|
538
|
-
text
|
|
539
|
-
}]
|
|
540
|
-
};
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
// -----------------------------------------------------------------------------
|
|
544
|
-
// Foundations
|
|
545
|
-
// -----------------------------------------------------------------------------
|
|
546
|
-
server.registerTool('get_color_usage', {
|
|
547
|
-
description: 'Get the guidelines for how to apply color to a user interface'
|
|
548
|
-
}, async () => {
|
|
549
|
-
const url = new URL(`/product/getting-started/foundations/color-usage`, 'https://primer.style');
|
|
550
|
-
const response = await fetch(url);
|
|
551
|
-
if (!response.ok) {
|
|
552
|
-
throw new Error(`Failed to fetch ${url} - ${response.statusText}`);
|
|
553
|
-
}
|
|
554
|
-
const html = await response.text();
|
|
555
|
-
if (!html) {
|
|
556
|
-
return {
|
|
557
|
-
content: []
|
|
558
|
-
};
|
|
559
|
-
}
|
|
560
|
-
const $ = cheerio.load(html);
|
|
561
|
-
const source = $('main').html();
|
|
562
|
-
if (!source) {
|
|
563
|
-
return {
|
|
564
|
-
content: []
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
const text = turndownService.turndown(source);
|
|
568
|
-
return {
|
|
569
|
-
content: [{
|
|
570
|
-
type: 'text',
|
|
571
|
-
text: `Here is the documentation for color usage in Primer:\n\n${text}`
|
|
572
|
-
}]
|
|
573
|
-
};
|
|
574
|
-
});
|
|
575
|
-
server.registerTool('get_typography_usage', {
|
|
576
|
-
description: 'Get the guidelines for how to apply typography to a user interface'
|
|
577
|
-
}, async () => {
|
|
578
|
-
const url = new URL(`/product/getting-started/foundations/typography`, 'https://primer.style');
|
|
579
|
-
const response = await fetch(url);
|
|
580
|
-
if (!response.ok) {
|
|
581
|
-
throw new Error(`Failed to fetch ${url} - ${response.statusText}`);
|
|
582
|
-
}
|
|
583
|
-
const html = await response.text();
|
|
584
|
-
if (!html) {
|
|
585
|
-
return {
|
|
586
|
-
content: []
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
const $ = cheerio.load(html);
|
|
590
|
-
const source = $('main').html();
|
|
591
|
-
if (!source) {
|
|
592
|
-
return {
|
|
593
|
-
content: []
|
|
594
|
-
};
|
|
595
|
-
}
|
|
596
|
-
const text = turndownService.turndown(source);
|
|
597
|
-
return {
|
|
598
|
-
content: [{
|
|
599
|
-
type: 'text',
|
|
600
|
-
text: `Here is the documentation for typography usage in Primer:\n\n${text}`
|
|
601
|
-
}]
|
|
602
|
-
};
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
// -----------------------------------------------------------------------------
|
|
606
|
-
// Icons
|
|
607
|
-
// -----------------------------------------------------------------------------
|
|
608
|
-
server.registerTool('list_icons', {
|
|
609
|
-
description: 'List all of the icons (octicons) available from Primer Octicons React'
|
|
610
|
-
}, async () => {
|
|
611
|
-
const icons = listIcons().map(icon => {
|
|
612
|
-
const keywords = icon.keywords.map(keyword => {
|
|
613
|
-
return `<keyword>${keyword}</keyword>`;
|
|
614
|
-
});
|
|
615
|
-
const sizes = icon.heights.map(height => {
|
|
616
|
-
return `<size value="${height}"></size>`;
|
|
617
|
-
});
|
|
618
|
-
return [`<icon name="${icon.name}">`, ...keywords, ...sizes, `</icon>`].join('\n');
|
|
619
|
-
});
|
|
620
|
-
return {
|
|
621
|
-
content: [{
|
|
622
|
-
type: 'text',
|
|
623
|
-
text: `The following icons are available in the @primer/octicons-react package in TypeScript projects:
|
|
624
|
-
|
|
625
|
-
${icons.join('\n')}
|
|
626
|
-
|
|
627
|
-
You can use the \`get_icon\` tool to get more information about a specific icon. You can use these components from the @primer/octicons-react package.`
|
|
628
|
-
}]
|
|
629
|
-
};
|
|
630
|
-
});
|
|
631
|
-
server.registerTool('get_icon', {
|
|
632
|
-
description: 'Get a specific icon (octicon) by name from Primer',
|
|
633
|
-
inputSchema: {
|
|
634
|
-
name: z.string().describe('The name of the icon to retrieve'),
|
|
635
|
-
size: z.string().optional().describe('The size of the icon to retrieve, e.g. "16"').default('16')
|
|
636
|
-
}
|
|
637
|
-
}, async ({
|
|
638
|
-
name,
|
|
639
|
-
size
|
|
640
|
-
}) => {
|
|
641
|
-
const icons = listIcons();
|
|
642
|
-
const match = icons.find(icon => {
|
|
643
|
-
return icon.name === name || icon.name.toLowerCase() === name.toLowerCase();
|
|
644
|
-
});
|
|
645
|
-
if (!match) {
|
|
646
|
-
return {
|
|
647
|
-
content: [{
|
|
648
|
-
type: 'text',
|
|
649
|
-
text: `There is no icon named \`${name}\` in the @primer/octicons-react package. For a full list of icons, use the \`get_icon\` tool.`
|
|
650
|
-
}]
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
const url = new URL(`/octicons/icon/${match.name}-${size}`, 'https://primer.style');
|
|
654
|
-
const response = await fetch(url);
|
|
655
|
-
if (!response.ok) {
|
|
656
|
-
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
657
|
-
}
|
|
658
|
-
const html = await response.text();
|
|
659
|
-
if (!html) {
|
|
660
|
-
return {
|
|
661
|
-
content: []
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
const $ = cheerio.load(html);
|
|
665
|
-
const source = $('main').html();
|
|
666
|
-
if (!source) {
|
|
667
|
-
return {
|
|
668
|
-
content: []
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
const text = turndownService.turndown(source);
|
|
672
|
-
return {
|
|
673
|
-
content: [{
|
|
674
|
-
type: 'text',
|
|
675
|
-
text: `Here is the documentation for the \`${name}\` icon at size: \`${size}\`:
|
|
676
|
-
${text}`
|
|
677
|
-
}]
|
|
678
|
-
};
|
|
679
|
-
});
|
|
680
|
-
|
|
681
|
-
// -----------------------------------------------------------------------------
|
|
682
|
-
// Coding guidelines
|
|
683
|
-
// -----------------------------------------------------------------------------
|
|
684
|
-
server.registerTool('primer_coding_guidelines', {
|
|
685
|
-
description: 'Get the guidelines when writing code that uses Primer or for UI code that you are creating'
|
|
686
|
-
}, async () => {
|
|
687
|
-
return {
|
|
688
|
-
content: [{
|
|
689
|
-
type: 'text',
|
|
690
|
-
text: `When writing code that uses Primer, follow these guidelines:
|
|
691
|
-
|
|
692
|
-
## Design Tokens
|
|
693
|
-
|
|
694
|
-
- Prefer design tokens over hard-coded values. For example, use \`var(--fgColor-default)\` instead of \`#24292f\`. Use the \`list_tokens\` tool to find the design token you need.
|
|
695
|
-
- Prefer recommending design tokens in the same group for related CSS properties. For example, when styling background and border color, use tokens from the same group/category
|
|
696
|
-
|
|
697
|
-
## Authoring & Using Components
|
|
698
|
-
|
|
699
|
-
- Prefer re-using a component from Primer when possible over writing a new component.
|
|
700
|
-
- Prefer using existing props for a component for styling instead of adding styling to a component
|
|
701
|
-
- Prefer using icons from Primer instead of creating new icons. Use the \`list_icons\` tool to find the icon you need.
|
|
702
|
-
- Follow patterns from Primer when creating new components. Use the \`list_patterns\` tool to find the pattern you need, if one exists
|
|
703
|
-
- When using a component from Primer, make sure to follow the component's usage and accessibility guidelines
|
|
704
|
-
|
|
705
|
-
## Coding guidelines
|
|
706
|
-
|
|
707
|
-
The following list of coding guidelines must be followed:
|
|
708
|
-
|
|
709
|
-
- Do not use the sx prop for styling components. Instead, use CSS Modules.
|
|
710
|
-
- Do not use the Box component for styling components. Instead, use CSS Modules.
|
|
711
|
-
`
|
|
712
|
-
}]
|
|
713
|
-
};
|
|
714
|
-
});
|
|
715
|
-
|
|
716
|
-
// -----------------------------------------------------------------------------
|
|
717
|
-
// Accessibility
|
|
718
|
-
// -----------------------------------------------------------------------------
|
|
719
|
-
|
|
720
|
-
/**
|
|
721
|
-
* The `review_alt_text` tool is experimental and may be removed in future versions.
|
|
722
|
-
*
|
|
723
|
-
* The intent of this tool is to assist products like Copilot Code Review and Copilot Coding Agent
|
|
724
|
-
* in reviewing both user- and AI-generated alt text for images, ensuring compliance with accessibility guidelines.
|
|
725
|
-
* This tool is not intended to replace human-generated alt text; rather, it supports the review process
|
|
726
|
-
* by providing suggestions for improvement. It should be used alongside human review, not as a substitute.
|
|
727
|
-
*
|
|
728
|
-
*
|
|
729
|
-
**/
|
|
730
|
-
server.registerTool('review_alt_text', {
|
|
731
|
-
description: 'Evaluates image alt text against accessibility best practices and context relevance.',
|
|
732
|
-
inputSchema: {
|
|
733
|
-
surroundingText: z.string().describe('Text surrounding the image, relevant to the image.'),
|
|
734
|
-
alt: z.string().describe('The alt text of the image being evaluated'),
|
|
735
|
-
image: z.string().describe('The image URL or file path being evaluated')
|
|
736
|
-
}
|
|
737
|
-
}, async ({
|
|
738
|
-
surroundingText,
|
|
739
|
-
alt,
|
|
740
|
-
image
|
|
741
|
-
}) => {
|
|
742
|
-
// Call the LLM through MCP sampling
|
|
743
|
-
const response = await server.server.createMessage({
|
|
744
|
-
messages: [{
|
|
745
|
-
role: 'user',
|
|
746
|
-
content: {
|
|
747
|
-
type: 'text',
|
|
748
|
-
text: `Does this alt text: '${alt}' meet accessibility guidelines and describe the image: ${image} accurately in context of this surrounding text: '${surroundingText}'?\n\n`
|
|
749
|
-
}
|
|
750
|
-
}],
|
|
751
|
-
sampling: {
|
|
752
|
-
temperature: 0.4
|
|
753
|
-
},
|
|
754
|
-
maxTokens: 500
|
|
755
|
-
});
|
|
756
|
-
return {
|
|
757
|
-
content: [{
|
|
758
|
-
type: 'text',
|
|
759
|
-
text: response.content.type === 'text' ? response.content.text : 'Unable to generate summary'
|
|
760
|
-
}],
|
|
761
|
-
altTextEvaluation: response.content.type === 'text' ? response.content.text : 'Unable to generate summary',
|
|
762
|
-
nextSteps: `If the evaluation indicates issues with the alt text, provide more meaningful alt text based on the feedback. DO NOT run this tool repeatedly on the same image - evaluations may vary slightly with each run.`
|
|
763
|
-
};
|
|
764
|
-
});
|
|
765
|
-
|
|
766
|
-
export { server as s };
|