@primer/mcp 0.0.2 → 0.0.3
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/README.md +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/primer.d.ts +8 -1
- package/dist/primer.d.ts.map +1 -1
- package/dist/server-BdIvJFTO.js +645 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/stdio.js +7 -519
- package/package.json +12 -7
- package/src/index.ts +1 -0
- package/src/primer.ts +22 -1
- package/src/server.ts +139 -6
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import * as cheerio from 'cheerio';
|
|
3
|
+
import { 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
|
+
|
|
8
|
+
const components = Object.entries(componentsMetadata.components).map(([id, component]) => {
|
|
9
|
+
return {
|
|
10
|
+
id,
|
|
11
|
+
name: component.name,
|
|
12
|
+
importPath: component.importPath,
|
|
13
|
+
slug: id.replaceAll('_', '-')
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
function listComponents() {
|
|
17
|
+
return components;
|
|
18
|
+
}
|
|
19
|
+
const patterns = [{
|
|
20
|
+
id: 'data-visualization',
|
|
21
|
+
name: 'Data Visualization'
|
|
22
|
+
}, {
|
|
23
|
+
id: 'degraded-experiences',
|
|
24
|
+
name: 'Degraded Experiences'
|
|
25
|
+
}, {
|
|
26
|
+
id: 'empty-states',
|
|
27
|
+
name: 'Empty States'
|
|
28
|
+
}, {
|
|
29
|
+
id: 'feature-onboarding',
|
|
30
|
+
name: 'Feature Onboarding'
|
|
31
|
+
}, {
|
|
32
|
+
id: 'forms',
|
|
33
|
+
name: 'Forms'
|
|
34
|
+
}, {
|
|
35
|
+
id: 'loading',
|
|
36
|
+
name: 'Loading'
|
|
37
|
+
}, {
|
|
38
|
+
id: 'navigation',
|
|
39
|
+
name: 'Navigation'
|
|
40
|
+
}, {
|
|
41
|
+
id: 'notification-messaging',
|
|
42
|
+
name: 'Notification message'
|
|
43
|
+
}, {
|
|
44
|
+
id: 'progressive-disclosure',
|
|
45
|
+
name: 'Progressive disclosure'
|
|
46
|
+
}, {
|
|
47
|
+
id: 'saving',
|
|
48
|
+
name: 'Saving'
|
|
49
|
+
}];
|
|
50
|
+
function listPatterns() {
|
|
51
|
+
return patterns;
|
|
52
|
+
}
|
|
53
|
+
const icons = Object.values(octicons).map(icon => {
|
|
54
|
+
return {
|
|
55
|
+
name: icon.name,
|
|
56
|
+
keywords: icon.keywords,
|
|
57
|
+
heights: Object.keys(icon.heights)
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
function listIcons() {
|
|
61
|
+
return icons;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var version = "0.0.3";
|
|
65
|
+
var packageJson = {
|
|
66
|
+
version: version};
|
|
67
|
+
|
|
68
|
+
const server = new McpServer({
|
|
69
|
+
name: 'Primer',
|
|
70
|
+
version: packageJson.version
|
|
71
|
+
});
|
|
72
|
+
const turndownService = new TurndownService();
|
|
73
|
+
|
|
74
|
+
// -----------------------------------------------------------------------------
|
|
75
|
+
// Project setup
|
|
76
|
+
// -----------------------------------------------------------------------------
|
|
77
|
+
server.tool('init', 'Setup or create a project that includes Primer React', async () => {
|
|
78
|
+
const url = new URL(`/product/getting-started/react`, 'https://primer.style');
|
|
79
|
+
const response = await fetch(url);
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
82
|
+
}
|
|
83
|
+
const html = await response.text();
|
|
84
|
+
if (!html) {
|
|
85
|
+
return {
|
|
86
|
+
content: []
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const $ = cheerio.load(html);
|
|
90
|
+
const source = $('main').html();
|
|
91
|
+
if (!source) {
|
|
92
|
+
return {
|
|
93
|
+
content: []
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const text = turndownService.turndown(source);
|
|
97
|
+
return {
|
|
98
|
+
content: [{
|
|
99
|
+
type: 'text',
|
|
100
|
+
text: `The getting started documentation for Primer React is included below. It's important that the project:
|
|
101
|
+
|
|
102
|
+
- 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
|
|
103
|
+
- Installs the latest version of \`@primer/react\` from \`npm\`
|
|
104
|
+
- Correctly adds the \`ThemeProvider\` and \`BaseStyles\` components to the root of the application
|
|
105
|
+
- Includes an import to a theme from \`@primer/primitives\`
|
|
106
|
+
- If the project wants to use icons, also install the \`@primer/octicons-react\` from \`npm\`
|
|
107
|
+
- Add appropriate agent instructions (like for copilot) to the project to prefer using components, tokens, icons, and more from Primer packages
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
${text}
|
|
112
|
+
`
|
|
113
|
+
}]
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// -----------------------------------------------------------------------------
|
|
118
|
+
// Components
|
|
119
|
+
// -----------------------------------------------------------------------------
|
|
120
|
+
server.tool('list_components', 'List all of the components available from Primer React', async () => {
|
|
121
|
+
const components = listComponents().map(component => {
|
|
122
|
+
return `- ${component.name}`;
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
content: [{
|
|
126
|
+
type: 'text',
|
|
127
|
+
text: `The following components are available in the @primer/react in TypeScript projects:
|
|
128
|
+
|
|
129
|
+
${components.join('\n')}
|
|
130
|
+
|
|
131
|
+
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.`
|
|
132
|
+
}]
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
server.tool('get_component', 'Get a specific component by name', {
|
|
136
|
+
name: z.string().describe('The name of the component to retrieve')
|
|
137
|
+
}, async ({
|
|
138
|
+
name
|
|
139
|
+
}) => {
|
|
140
|
+
const components = listComponents();
|
|
141
|
+
const match = components.find(component => {
|
|
142
|
+
return component.name === name || component.name.toLowerCase() === name.toLowerCase();
|
|
143
|
+
});
|
|
144
|
+
if (!match) {
|
|
145
|
+
return {
|
|
146
|
+
content: [{
|
|
147
|
+
type: 'text',
|
|
148
|
+
text: `There is no component named \`${name}\` in the @primer/react package. For a full list of components, use the \`get_components\` tool.`
|
|
149
|
+
}]
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const url = new URL(`/product/components/${match.slug}`, 'https://primer.style');
|
|
153
|
+
const response = await fetch(url);
|
|
154
|
+
if (!response.ok) {
|
|
155
|
+
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
156
|
+
}
|
|
157
|
+
const html = await response.text();
|
|
158
|
+
if (!html) {
|
|
159
|
+
return {
|
|
160
|
+
content: []
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const $ = cheerio.load(html);
|
|
164
|
+
const source = $('main').html();
|
|
165
|
+
if (!source) {
|
|
166
|
+
return {
|
|
167
|
+
content: []
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const text = turndownService.turndown(source);
|
|
171
|
+
return {
|
|
172
|
+
content: [{
|
|
173
|
+
type: 'text',
|
|
174
|
+
text: `Here is the documentation for the \`${name}\` component from the @primer/react package:
|
|
175
|
+
${text}`
|
|
176
|
+
}]
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
server.tool('get_component_examples', 'Get examples for how to use a component from Primer React', {
|
|
180
|
+
name: z.string().describe('The name of the component to retrieve')
|
|
181
|
+
}, async ({
|
|
182
|
+
name
|
|
183
|
+
}) => {
|
|
184
|
+
const components = listComponents();
|
|
185
|
+
const match = components.find(component => {
|
|
186
|
+
return component.name === name;
|
|
187
|
+
});
|
|
188
|
+
if (!match) {
|
|
189
|
+
return {
|
|
190
|
+
content: [{
|
|
191
|
+
type: 'text',
|
|
192
|
+
text: `There is no component named \`${name}\` in the @primer/react package. For a full list of components, use the \`get_components\` tool.`
|
|
193
|
+
}]
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const url = new URL(`/product/components/${match.id}`, 'https://primer.style');
|
|
197
|
+
const response = await fetch(url);
|
|
198
|
+
if (!response.ok) {
|
|
199
|
+
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
200
|
+
}
|
|
201
|
+
const html = await response.text();
|
|
202
|
+
if (!html) {
|
|
203
|
+
return {
|
|
204
|
+
content: []
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const $ = cheerio.load(html);
|
|
208
|
+
const source = $('main').html();
|
|
209
|
+
if (!source) {
|
|
210
|
+
return {
|
|
211
|
+
content: []
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
const text = turndownService.turndown(source);
|
|
215
|
+
return {
|
|
216
|
+
content: [{
|
|
217
|
+
type: 'text',
|
|
218
|
+
text: `Here are some examples of how to use the \`${name}\` component from the @primer/react package:
|
|
219
|
+
|
|
220
|
+
${text}`
|
|
221
|
+
}]
|
|
222
|
+
};
|
|
223
|
+
});
|
|
224
|
+
server.tool('get_component_usage_guidelines', 'Get usage information for how to use a component from Primer', {
|
|
225
|
+
name: z.string().describe('The name of the component to retrieve')
|
|
226
|
+
}, async ({
|
|
227
|
+
name
|
|
228
|
+
}) => {
|
|
229
|
+
const components = listComponents();
|
|
230
|
+
const match = components.find(component => {
|
|
231
|
+
return component.name === name;
|
|
232
|
+
});
|
|
233
|
+
if (!match) {
|
|
234
|
+
return {
|
|
235
|
+
content: [{
|
|
236
|
+
type: 'text',
|
|
237
|
+
text: `There is no component named \`${name}\` in the @primer/react package. For a full list of components, use the \`get_components\` tool.`
|
|
238
|
+
}]
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const url = new URL(`/product/components/${match.id}/guidelines`, 'https://primer.style');
|
|
242
|
+
const response = await fetch(url);
|
|
243
|
+
if (!response.ok) {
|
|
244
|
+
if (response.status >= 400 && response.status < 500 || response.status >= 300 && response.status < 400) {
|
|
245
|
+
return {
|
|
246
|
+
content: [{
|
|
247
|
+
type: 'text',
|
|
248
|
+
text: `There are no accessibility guidelines for the \`${name}\` component in the @primer/react package.`
|
|
249
|
+
}]
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
253
|
+
}
|
|
254
|
+
const html = await response.text();
|
|
255
|
+
if (!html) {
|
|
256
|
+
return {
|
|
257
|
+
content: []
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
const $ = cheerio.load(html);
|
|
261
|
+
const source = $('main').html();
|
|
262
|
+
if (!source) {
|
|
263
|
+
return {
|
|
264
|
+
content: []
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
const text = turndownService.turndown(source);
|
|
268
|
+
return {
|
|
269
|
+
content: [{
|
|
270
|
+
type: 'text',
|
|
271
|
+
text: `Here are the usage guidelines for the \`${name}\` component from the @primer/react package:
|
|
272
|
+
|
|
273
|
+
${text}`
|
|
274
|
+
}]
|
|
275
|
+
};
|
|
276
|
+
});
|
|
277
|
+
server.tool('get_component_accessibility_guidelines', 'Get accessibility information for how to use a component from Primer React', {
|
|
278
|
+
name: z.string().describe('The name of the component to retrieve')
|
|
279
|
+
}, async ({
|
|
280
|
+
name
|
|
281
|
+
}) => {
|
|
282
|
+
const components = listComponents();
|
|
283
|
+
const match = components.find(component => {
|
|
284
|
+
return component.name === name;
|
|
285
|
+
});
|
|
286
|
+
if (!match) {
|
|
287
|
+
return {
|
|
288
|
+
content: [{
|
|
289
|
+
type: 'text',
|
|
290
|
+
text: `There is no component named \`${name}\` in the @primer/react package. For a full list of components, use the \`get_components\` tool.`
|
|
291
|
+
}]
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
const url = new URL(`/product/components/${match.id}/accessibility`, 'https://primer.style');
|
|
295
|
+
const response = await fetch(url);
|
|
296
|
+
if (!response.ok) {
|
|
297
|
+
if (response.status >= 400 && response.status < 500 || response.status >= 300 && response.status < 400) {
|
|
298
|
+
return {
|
|
299
|
+
content: [{
|
|
300
|
+
type: 'text',
|
|
301
|
+
text: `There are no accessibility guidelines for the \`${name}\` component in the @primer/react package.`
|
|
302
|
+
}]
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
306
|
+
}
|
|
307
|
+
const html = await response.text();
|
|
308
|
+
if (!html) {
|
|
309
|
+
return {
|
|
310
|
+
content: []
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
const $ = cheerio.load(html);
|
|
314
|
+
const source = $('main').html();
|
|
315
|
+
if (!source) {
|
|
316
|
+
return {
|
|
317
|
+
content: []
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
const text = turndownService.turndown(source);
|
|
321
|
+
return {
|
|
322
|
+
content: [{
|
|
323
|
+
type: 'text',
|
|
324
|
+
text: `Here are the accessibility guidelines for the \`${name}\` component from the @primer/react package:
|
|
325
|
+
|
|
326
|
+
${text}`
|
|
327
|
+
}]
|
|
328
|
+
};
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
// -----------------------------------------------------------------------------
|
|
332
|
+
// Patterns
|
|
333
|
+
// -----------------------------------------------------------------------------
|
|
334
|
+
server.tool('list_patterns', 'List all of the patterns available from Primer React', async () => {
|
|
335
|
+
const patterns = listPatterns().map(pattern => {
|
|
336
|
+
return `- ${pattern.name}`;
|
|
337
|
+
});
|
|
338
|
+
return {
|
|
339
|
+
content: [{
|
|
340
|
+
type: 'text',
|
|
341
|
+
text: `The following patterns are available in the @primer/react in TypeScript projects:
|
|
342
|
+
|
|
343
|
+
${patterns.join('\n')}`
|
|
344
|
+
}]
|
|
345
|
+
};
|
|
346
|
+
});
|
|
347
|
+
server.tool('get_pattern', 'Get a specific pattern by name', {
|
|
348
|
+
name: z.string().describe('The name of the pattern to retrieve')
|
|
349
|
+
}, async ({
|
|
350
|
+
name
|
|
351
|
+
}) => {
|
|
352
|
+
const patterns = listPatterns();
|
|
353
|
+
const match = patterns.find(pattern => {
|
|
354
|
+
return pattern.name === name;
|
|
355
|
+
});
|
|
356
|
+
if (!match) {
|
|
357
|
+
return {
|
|
358
|
+
content: [{
|
|
359
|
+
type: 'text',
|
|
360
|
+
text: `There is no pattern named \`${name}\` in the @primer/react package. For a full list of patterns, use the \`list_patterns\` tool.`
|
|
361
|
+
}]
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
const url = new URL(`/product/ui-patterns/${match.id}`, 'https://primer.style');
|
|
365
|
+
const response = await fetch(url);
|
|
366
|
+
if (!response.ok) {
|
|
367
|
+
throw new Error(`Failed to fetch ${url} - ${response.statusText}`);
|
|
368
|
+
}
|
|
369
|
+
const html = await response.text();
|
|
370
|
+
if (!html) {
|
|
371
|
+
return {
|
|
372
|
+
content: []
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
const $ = cheerio.load(html);
|
|
376
|
+
const source = $('main').html();
|
|
377
|
+
if (!source) {
|
|
378
|
+
return {
|
|
379
|
+
content: []
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
const text = turndownService.turndown(source);
|
|
383
|
+
return {
|
|
384
|
+
content: [{
|
|
385
|
+
type: 'text',
|
|
386
|
+
text: `Here are the guidelines for the \`${name}\` pattern for Primer:
|
|
387
|
+
|
|
388
|
+
${text}`
|
|
389
|
+
}]
|
|
390
|
+
};
|
|
391
|
+
});
|
|
392
|
+
const tokens = [{
|
|
393
|
+
category: 'color',
|
|
394
|
+
tokens: [{
|
|
395
|
+
category: 'foreground',
|
|
396
|
+
tokens: ['--fgColor-accent', '--fgColor-attention', '--fgColor-black', '--fgColor-closed', '--fgColor-danger', '--fgColor-default', '--fgColor-disabled', '--fgColor-done', '--fgColor-link', '--fgColor-muted', '--fgColor-neutral', '--fgColor-onEmphasis', '--fgColor-onInverse', '--fgColor-open', '--fgColor-severe', '--fgColor-sponsors', '--fgColor-success', '--fgColor-upsell', '--fgColor-white']
|
|
397
|
+
}, {
|
|
398
|
+
category: 'background',
|
|
399
|
+
tokens: ['--bgColor-accent-emphasis', '--bgColor-accent-muted', '--bgColor-attention-emphasis', '--bgColor-attention-muted', '--bgColor-black', '--bgColor-closed-emphasis', '--bgColor-closed-muted', '--bgColor-danger-emphasis', '--bgColor-danger-muted', '--bgColor-default', '--bgColor-disabled', '--bgColor-done-emphasis', '--bgColor-done-muted', '--bgColor-emphasis', '--bgColor-inset', '--bgColor-inverse', '--bgColor-muted', '--bgColor-neutral-emphasis', '--bgColor-neutral-muted', '--bgColor-open-emphasis', '--bgColor-open-muted', '--bgColor-severe-emphasis', '--bgColor-severe-muted', '--bgColor-sponsors-emphasis', '--bgColor-sponsors-muted', '--bgColor-success-emphasis', '--bgColor-success-muted', '--bgColor-transparent', '--bgColor-upsell-emphasis', '--bgColor-upsell-muted', '--bgColor-white']
|
|
400
|
+
}, {
|
|
401
|
+
category: 'border',
|
|
402
|
+
tokens: ['--borderColor-accent-emphasis', '--borderColor-accent-muted', '--borderColor-attention-emphasis', '--borderColor-attention-muted', '--borderColor-closed-emphasis', '--borderColor-closed-muted', '--borderColor-danger-emphasis', '--borderColor-danger-muted', '--borderColor-default', '--borderColor-disabled', '--borderColor-done-emphasis', '--borderColor-done-muted', '--borderColor-emphasis', '--borderColor-muted', '--borderColor-neutral-emphasis', '--borderColor-neutral-muted', '--borderColor-open-emphasis', '--borderColor-open-muted', '--borderColor-severe-emphasis', '--borderColor-severe-muted', '--borderColor-sponsors-emphasis', '--borderColor-sponsors-muted', '--borderColor-success-emphasis', '--borderColor-success-muted', '--borderColor-translucent', '--borderColor-transparent', '--borderColor-upsell-emphasis', '--borderColor-upsell-muted']
|
|
403
|
+
}, {
|
|
404
|
+
category: 'shadow',
|
|
405
|
+
tokens: ['--shadow-floating-large', '--shadow-floating-legacy', '--shadow-floating-medium', '--shadow-floating-small', '--shadow-floating-xlarge', '--shadow-inset', '--shadow-resting-medium', '--shadow-resting-small', '--shadow-resting-xsmall']
|
|
406
|
+
}, {
|
|
407
|
+
category: 'control',
|
|
408
|
+
tokens: ['--control-bgColor-active', '--control-bgColor-disabled', '--control-bgColor-hover', '--control-bgColor-rest', '--control-bgColor-selected', '--control-borderColor-danger', '--control-borderColor-disabled', '--control-borderColor-emphasis', '--control-borderColor-rest', '--control-borderColor-selected', '--control-borderColor-success', '--control-borderColor-warning', '--control-checked-bgColor-active', '--control-checked-bgColor-disabled', '--control-checked-bgColor-hover', '--control-checked-bgColor-rest', '--control-checked-borderColor-active', '--control-checked-borderColor-disabled', '--control-checked-borderColor-hover', '--control-checked-borderColor-rest', '--control-checked-fgColor-disabled', '--control-checked-fgColor-rest', '--control-danger-bgColor-active', '--control-danger-bgColor-hover', '--control-danger-fgColor-hover', '--control-danger-fgColor-rest', '--control-fgColor-disabled', '--control-fgColor-placeholder', '--control-fgColor-rest', '--control-iconColor-rest', '--control-transparent-bgColor-active', '--control-transparent-bgColor-disabled', '--control-transparent-bgColor-hover', '--control-transparent-bgColor-rest', '--control-transparent-bgColor-selected', '--control-transparent-borderColor-active', '--control-transparent-borderColor-hover', '--control-transparent-borderColor-rest']
|
|
409
|
+
}, {
|
|
410
|
+
category: 'focus',
|
|
411
|
+
tokens: ['--focus-outlineColor']
|
|
412
|
+
}, {
|
|
413
|
+
category: 'overlay',
|
|
414
|
+
tokens: ['--overlay-background-bgColor', '--overlay-bgColor', '--overlay-borderColor']
|
|
415
|
+
}]
|
|
416
|
+
}, {
|
|
417
|
+
category: 'size',
|
|
418
|
+
tokens: [{
|
|
419
|
+
category: 'base',
|
|
420
|
+
tokens: ['--base-size-2', '--base-size-4', '--base-size-6', '--base-size-8', '--base-size-12', '--base-size-16', '--base-size-20', '--base-size-24', '--base-size-28', '--base-size-32', '--base-size-36', '--base-size-40', '--base-size-44', '--base-size-48', '--base-size-64', '--base-size-80', '--base-size-96', '--base-size-112', '--base-size-128']
|
|
421
|
+
}, {
|
|
422
|
+
category: 'border',
|
|
423
|
+
tokens: [{
|
|
424
|
+
category: 'border-size',
|
|
425
|
+
tokens: ['--boxShadow-thick', '--boxShadow-thicker', '--boxShadow-thin', '--borderWidth-default', '--borderWidth-thick', '--borderWidth-thicker', '--borderWidth-thin']
|
|
426
|
+
}, {
|
|
427
|
+
category: 'border-radius',
|
|
428
|
+
tokens: ['--borderRadius-default', '--borderRadius-full', '--borderRadius-large', '--borderRadius-medium', '--borderRadius-small']
|
|
429
|
+
}, {
|
|
430
|
+
category: 'outline',
|
|
431
|
+
tokens: ['--outline-focus-offset', '--outline-focus-width']
|
|
432
|
+
}]
|
|
433
|
+
}, {
|
|
434
|
+
category: 'layout',
|
|
435
|
+
tokens: [{
|
|
436
|
+
category: 'stack',
|
|
437
|
+
tokens: ['--stack-gap-condensed', '--stack-gap-normal', '--stack-gap-spacious', '--stack-padding-condensed', '--stack-padding-normal', '--stack-padding-spacious']
|
|
438
|
+
}, {
|
|
439
|
+
category: 'controls',
|
|
440
|
+
tokens: ['--controlStack-large-gap-auto', '--controlStack-large-gap-condensed', '--controlStack-large-gap-spacious', '--controlStack-medium-gap-condensed', '--controlStack-medium-gap-spacious', '--controlStack-small-gap-condensed', '--controlStack-small-gap-spacious', '--controlStack-medium-gap-auto', '--controlStack-small-gap-auto', '--control-xsmall-gap', '--control-small-gap', '--control-medium-gap', '--control-large-gap', '--control-xlarge-gap', '--control-xsmall-lineBoxHeight', '--control-small-lineBoxHeight', '--control-medium-lineBoxHeight', '--control-large-lineBoxHeight', '--control-xlarge-lineBoxHeight', '--control-xsmall-paddingBlock', '--control-small-paddingBlock', '--control-medium-paddingBlock', '--control-large-paddingBlock', '--control-xlarge-paddingBlock', '--control-xsmall-paddingInline-condensed', '--control-small-paddingInline-condensed', '--control-medium-paddingInline-condensed', '--control-large-paddingInline-condensed', '--control-xlarge-paddingInline-condensed', '--control-xsmall-paddingInline-normal', '--control-small-paddingInline-normal', '--control-medium-paddingInline-normal', '--control-large-paddingInline-normal', '--control-xlarge-paddingInline-normal', '--control-xsmall-paddingInline-spacious', '--control-small-paddingInline-spacious', '--control-medium-paddingInline-spacious', '--control-large-paddingInline-spacious', '--control-xlarge-paddingInline-spacious', '--control-xsmall-size', '--control-small-size', '--control-medium-size', '--control-large-size', '--control-xlarge-size']
|
|
441
|
+
}, {
|
|
442
|
+
category: 'overlay',
|
|
443
|
+
tokens: ['--overlay-borderRadius', '--overlay-height-large', '--overlay-height-medium', '--overlay-height-small', '--overlay-height-xlarge', '--overlay-offset', '--overlay-padding-condensed', '--overlay-padding-normal', '--overlay-paddingBlock-condensed', '--overlay-paddingBlock-normal', '--overlay-width-large', '--overlay-width-medium', '--overlay-width-small', '--overlay-width-xlarge', '--overlay-width-xsmall']
|
|
444
|
+
}]
|
|
445
|
+
}]
|
|
446
|
+
}, {
|
|
447
|
+
category: 'typography',
|
|
448
|
+
tokens: [{
|
|
449
|
+
category: 'weight',
|
|
450
|
+
tokens: ['--base-text-weight-light', '--base-text-weight-normal', '--base-text-weight-medium', '--base-text-weight-semibold']
|
|
451
|
+
}, {
|
|
452
|
+
category: 'font-family',
|
|
453
|
+
tokens: ['--fontStack-monospace', '--fontStack-sansSerif', '--fontStack-sansSerifDisplay', '--fontStack-system']
|
|
454
|
+
}, {
|
|
455
|
+
category: 'font-shorthand',
|
|
456
|
+
tokens: ['--text-body-shorthand-large', '--text-body-shorthand-medium', '--text-body-shorthand-small', '--text-caption-shorthand', '--text-codeBlock-shorthand', '--text-codeInline-shorthand', '--text-display-shorthand', '--text-subtitle-shorthand', '--text-title-shorthand-large', '--text-title-shorthand-medium', '--text-title-shorthand-small']
|
|
457
|
+
}, {
|
|
458
|
+
category: 'display',
|
|
459
|
+
tokens: ['--text-display-lineBoxHeight', '--text-display-lineHeight', '--text-display-size', '--text-display-weight']
|
|
460
|
+
}, {
|
|
461
|
+
category: 'title-large',
|
|
462
|
+
tokens: ['--text-title-lineHeight-large', '--text-title-size-large', '--text-title-weight-large']
|
|
463
|
+
}, {
|
|
464
|
+
category: 'title-medium',
|
|
465
|
+
tokens: ['--text-title-lineHeight-medium', '--text-title-size-medium', '--text-title-weight-medium']
|
|
466
|
+
}, {
|
|
467
|
+
category: 'title-small',
|
|
468
|
+
tokens: ['--text-title-lineHeight-small', '--text-title-size-small', '--text-title-weight-small']
|
|
469
|
+
}, {
|
|
470
|
+
category: 'subtitle',
|
|
471
|
+
tokens: ['--text-subtitle-lineHeight', '--text-subtitle-size', '--text-subtitle-weight']
|
|
472
|
+
}, {
|
|
473
|
+
category: 'body-large',
|
|
474
|
+
tokens: ['--text-body-lineHeight-large', '--text-body-size-large']
|
|
475
|
+
}, {
|
|
476
|
+
category: 'body-medium',
|
|
477
|
+
tokens: ['--text-body-lineHeight-medium', '--text-body-size-medium']
|
|
478
|
+
}, {
|
|
479
|
+
category: 'body-small',
|
|
480
|
+
tokens: ['--text-body-lineHeight-small', '--text-body-size-small']
|
|
481
|
+
}, {
|
|
482
|
+
category: 'caption',
|
|
483
|
+
tokens: ['--text-caption-lineHeight', '--text-caption-size', '--text-caption-weight']
|
|
484
|
+
}, {
|
|
485
|
+
category: 'code-block',
|
|
486
|
+
tokens: ['--text-codeBlock-lineHeight', '--text-codeBlock-size', '--text-codeBlock-weight']
|
|
487
|
+
}, {
|
|
488
|
+
category: 'inline-code-block',
|
|
489
|
+
tokens: ['--text-codeInline-size', '--text-codeInline-weight']
|
|
490
|
+
}]
|
|
491
|
+
}];
|
|
492
|
+
function serialize(token) {
|
|
493
|
+
if (typeof token === 'string') {
|
|
494
|
+
return `<token name="${token}"></token>`;
|
|
495
|
+
}
|
|
496
|
+
return `<token-category name="${token.category}">\n${token.tokens.map(serialize).join('\n')}\n</token-category>`;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// -----------------------------------------------------------------------------
|
|
500
|
+
// Design Tokens
|
|
501
|
+
// -----------------------------------------------------------------------------
|
|
502
|
+
server.tool('list_tokens', 'List all of the design tokens available from Primer', async () => {
|
|
503
|
+
let text = 'Below is a list of all designs tokens available from Primer. They are organized by category. Tokens are used in CSS and CSS Modules. They can also be referred to in JavaScript files using the style attribute or prop in React components. 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';
|
|
504
|
+
for (const token of tokens) {
|
|
505
|
+
text += serialize(token);
|
|
506
|
+
text += '\n';
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
content: [{
|
|
510
|
+
type: 'text',
|
|
511
|
+
text
|
|
512
|
+
}]
|
|
513
|
+
};
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
// -----------------------------------------------------------------------------
|
|
517
|
+
// Foundations
|
|
518
|
+
// -----------------------------------------------------------------------------
|
|
519
|
+
server.tool('get_color_usage', 'Get the guidelines for how to apply color to a user interface', async () => {
|
|
520
|
+
const url = new URL(`/product/getting-started/foundations/color-usage`, 'https://primer.style');
|
|
521
|
+
const response = await fetch(url);
|
|
522
|
+
if (!response.ok) {
|
|
523
|
+
throw new Error(`Failed to fetch ${url} - ${response.statusText}`);
|
|
524
|
+
}
|
|
525
|
+
const html = await response.text();
|
|
526
|
+
if (!html) {
|
|
527
|
+
return {
|
|
528
|
+
content: []
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
const $ = cheerio.load(html);
|
|
532
|
+
const source = $('main').html();
|
|
533
|
+
if (!source) {
|
|
534
|
+
return {
|
|
535
|
+
content: []
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
const text = turndownService.turndown(source);
|
|
539
|
+
return {
|
|
540
|
+
content: [{
|
|
541
|
+
type: 'text',
|
|
542
|
+
text: `Here is the documentation for color usage in Primer:\n\n${text}`
|
|
543
|
+
}]
|
|
544
|
+
};
|
|
545
|
+
});
|
|
546
|
+
server.tool('get_typography_usage', 'Get the guidelines for how to apply typography to a user interface', async () => {
|
|
547
|
+
const url = new URL(`/product/getting-started/foundations/typography`, 'https://primer.style');
|
|
548
|
+
const response = await fetch(url);
|
|
549
|
+
if (!response.ok) {
|
|
550
|
+
throw new Error(`Failed to fetch ${url} - ${response.statusText}`);
|
|
551
|
+
}
|
|
552
|
+
const html = await response.text();
|
|
553
|
+
if (!html) {
|
|
554
|
+
return {
|
|
555
|
+
content: []
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
const $ = cheerio.load(html);
|
|
559
|
+
const source = $('main').html();
|
|
560
|
+
if (!source) {
|
|
561
|
+
return {
|
|
562
|
+
content: []
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
const text = turndownService.turndown(source);
|
|
566
|
+
return {
|
|
567
|
+
content: [{
|
|
568
|
+
type: 'text',
|
|
569
|
+
text: `Here is the documentation for typography usage in Primer:\n\n${text}`
|
|
570
|
+
}]
|
|
571
|
+
};
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
// -----------------------------------------------------------------------------
|
|
575
|
+
// Icons
|
|
576
|
+
// -----------------------------------------------------------------------------
|
|
577
|
+
server.tool('list_icons', 'List all of the icons (octicons) available from Primer Octicons React', async () => {
|
|
578
|
+
const icons = listIcons().map(icon => {
|
|
579
|
+
const keywords = icon.keywords.map(keyword => {
|
|
580
|
+
return `<keyword>${keyword}</keyword>`;
|
|
581
|
+
});
|
|
582
|
+
const sizes = icon.heights.map(height => {
|
|
583
|
+
return `<size value="${height}"></size>`;
|
|
584
|
+
});
|
|
585
|
+
return [`<icon name="${icon.name}">`, ...keywords, ...sizes, `</icon>`].join('\n');
|
|
586
|
+
});
|
|
587
|
+
return {
|
|
588
|
+
content: [{
|
|
589
|
+
type: 'text',
|
|
590
|
+
text: `The following icons are available in the @primer/octicons-react package in TypeScript projects:
|
|
591
|
+
|
|
592
|
+
${icons.join('\n')}
|
|
593
|
+
|
|
594
|
+
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.`
|
|
595
|
+
}]
|
|
596
|
+
};
|
|
597
|
+
});
|
|
598
|
+
server.tool('get_icon', 'Get a specific icon (octicon) by name from Primer', {
|
|
599
|
+
name: z.string().describe('The name of the icon to retrieve'),
|
|
600
|
+
size: z.string().optional().describe('The size of the icon to retrieve, e.g. "16"').default('16')
|
|
601
|
+
}, async ({
|
|
602
|
+
name,
|
|
603
|
+
size
|
|
604
|
+
}) => {
|
|
605
|
+
const icons = listIcons();
|
|
606
|
+
const match = icons.find(icon => {
|
|
607
|
+
return icon.name === name || icon.name.toLowerCase() === name.toLowerCase();
|
|
608
|
+
});
|
|
609
|
+
if (!match) {
|
|
610
|
+
return {
|
|
611
|
+
content: [{
|
|
612
|
+
type: 'text',
|
|
613
|
+
text: `There is no icon named \`${name}\` in the @primer/octicons-react package. For a full list of icons, use the \`get_icon\` tool.`
|
|
614
|
+
}]
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
const url = new URL(`/octicons/icon/${match.name}-${size}`, 'https://primer.style');
|
|
618
|
+
const response = await fetch(url);
|
|
619
|
+
if (!response.ok) {
|
|
620
|
+
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
621
|
+
}
|
|
622
|
+
const html = await response.text();
|
|
623
|
+
if (!html) {
|
|
624
|
+
return {
|
|
625
|
+
content: []
|
|
626
|
+
};
|
|
627
|
+
}
|
|
628
|
+
const $ = cheerio.load(html);
|
|
629
|
+
const source = $('main').html();
|
|
630
|
+
if (!source) {
|
|
631
|
+
return {
|
|
632
|
+
content: []
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
const text = turndownService.turndown(source);
|
|
636
|
+
return {
|
|
637
|
+
content: [{
|
|
638
|
+
type: 'text',
|
|
639
|
+
text: `Here is the documentation for the \`${name}\` icon at size: \`${size}\`:
|
|
640
|
+
${text}`
|
|
641
|
+
}]
|
|
642
|
+
};
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
export { server as s };
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAA;AAQjE,QAAA,MAAM,MAAM,WAGV,CAAA;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAA;AAQjE,QAAA,MAAM,MAAM,WAGV,CAAA;AAo+BF,OAAO,EAAC,MAAM,EAAC,CAAA"}
|