@primer/mcp 1.1.2 → 1.1.3-rc.0b39c7236
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.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/{server-CZDOBVxP.js → server-wukIf9d-.js} +17 -14
- package/dist/stdio.js +2 -3
- package/package.json +4 -4
- package/src/server.test.ts +32 -0
- package/src/server.ts +24 -5
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as createServer, n as server } from "./server-
|
|
1
|
+
export { t as createServer, n as server } from "./server-wukIf9d-.js";
|
|
@@ -16,7 +16,7 @@ import functionalSizeFine from "@primer/primitives/dist/docs/functional/size/siz
|
|
|
16
16
|
import functionalSize from "@primer/primitives/dist/docs/functional/size/size.json" with { type: "json" };
|
|
17
17
|
import light from "@primer/primitives/dist/docs/functional/themes/light.json" with { type: "json" };
|
|
18
18
|
import functionalTypography from "@primer/primitives/dist/docs/functional/typography/typography.json" with { type: "json" };
|
|
19
|
-
|
|
19
|
+
// src/primer.ts
|
|
20
20
|
function idToSlug(id) {
|
|
21
21
|
if (id === "actionbar") return "action-bar";
|
|
22
22
|
if (id === "confirmationdialog") return "confirmation-dialog";
|
|
@@ -145,8 +145,7 @@ const icons = Object.values(octicons).map((icon) => {
|
|
|
145
145
|
function listIcons() {
|
|
146
146
|
return icons;
|
|
147
147
|
}
|
|
148
|
-
|
|
149
|
-
//#region src/primitives.ts
|
|
148
|
+
// src/primitives.ts
|
|
150
149
|
let functionalSizeRadius = {};
|
|
151
150
|
try {
|
|
152
151
|
const radiusPath = createRequire(import.meta.url).resolve("@primer/primitives/dist/docs/functional/size/radius.json");
|
|
@@ -716,13 +715,16 @@ function runStylelint(css) {
|
|
|
716
715
|
proc.stdin.end();
|
|
717
716
|
});
|
|
718
717
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
//#endregion
|
|
723
|
-
//#region src/server.ts
|
|
718
|
+
// package.json
|
|
719
|
+
var version = "1.1.3";
|
|
720
|
+
// src/server.ts
|
|
724
721
|
const turndownService = new TurndownService();
|
|
725
722
|
const allTokensWithGuidelines = loadAllTokensWithGuidelines();
|
|
723
|
+
function hasRedirectedToDifferentPage(response, url) {
|
|
724
|
+
if (!response.url) return false;
|
|
725
|
+
const finalUrl = new URL(response.url);
|
|
726
|
+
return finalUrl.origin !== url.origin || finalUrl.pathname.replace(/\/$/, "") !== url.pathname.replace(/\/$/, "");
|
|
727
|
+
}
|
|
726
728
|
function createServer() {
|
|
727
729
|
const server = new McpServer({
|
|
728
730
|
name: "Primer",
|
|
@@ -875,10 +877,11 @@ ${turndownService.turndown(source)}`
|
|
|
875
877
|
}] };
|
|
876
878
|
const url = new URL(`/product/components/${match.slug}/guidelines`, "https://primer.style");
|
|
877
879
|
const response = await fetch(url);
|
|
878
|
-
|
|
879
|
-
|
|
880
|
+
const redirected = hasRedirectedToDifferentPage(response, url);
|
|
881
|
+
if (!response.ok || redirected) {
|
|
882
|
+
if (redirected || response.status >= 400 && response.status < 500 || response.status >= 300 && response.status < 400) return { content: [{
|
|
880
883
|
type: "text",
|
|
881
|
-
text: `There are no
|
|
884
|
+
text: `There are no usage guidelines for the \`${name}\` component in the @primer/react package.`
|
|
882
885
|
}] };
|
|
883
886
|
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
884
887
|
}
|
|
@@ -907,8 +910,9 @@ ${turndownService.turndown(source)}`
|
|
|
907
910
|
}] };
|
|
908
911
|
const url = new URL(`/product/components/${match.slug}/accessibility`, "https://primer.style");
|
|
909
912
|
const response = await fetch(url);
|
|
910
|
-
|
|
911
|
-
|
|
913
|
+
const redirected = hasRedirectedToDifferentPage(response, url);
|
|
914
|
+
if (!response.ok || redirected) {
|
|
915
|
+
if (redirected || response.status >= 400 && response.status < 500 || response.status >= 300 && response.status < 400) return { content: [{
|
|
912
916
|
type: "text",
|
|
913
917
|
text: `There are no accessibility guidelines for the \`${name}\` component in the @primer/react package.`
|
|
914
918
|
}] };
|
|
@@ -1262,5 +1266,4 @@ The following list of coding guidelines must be followed:
|
|
|
1262
1266
|
return server;
|
|
1263
1267
|
}
|
|
1264
1268
|
const server = createServer();
|
|
1265
|
-
//#endregion
|
|
1266
1269
|
export { server as n, createServer as t };
|
package/dist/stdio.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { t as createServer } from "./server-
|
|
1
|
+
import { t as createServer } from "./server-wukIf9d-.js";
|
|
2
2
|
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
3
|
-
|
|
3
|
+
// src/transports/stdio.ts
|
|
4
4
|
serveStdio(createServer);
|
|
5
|
-
//#endregion
|
|
6
5
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primer/mcp",
|
|
3
3
|
"description": "An MCP server that connects AI tools to the Primer Design System",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.3-rc.0b39c7236",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"mcp": "./bin/mcp.js"
|
|
@@ -41,17 +41,17 @@
|
|
|
41
41
|
"@modelcontextprotocol/server": "^2.3.0",
|
|
42
42
|
"@primer/octicons": "^19.15.5",
|
|
43
43
|
"@primer/primitives": "10.x || 11.x",
|
|
44
|
-
"@primer/react": "^38.
|
|
44
|
+
"@primer/react": "^38.47.0",
|
|
45
45
|
"cheerio": "^1.0.0",
|
|
46
46
|
"turndown": "^7.2.0",
|
|
47
|
-
"zod": "^4.
|
|
47
|
+
"zod": "^4.6.6"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@modelcontextprotocol/inspector": "^0.16.6",
|
|
51
51
|
"@primer/vitest-config": "^0.0.0",
|
|
52
52
|
"@types/turndown": "^5.0.5",
|
|
53
53
|
"rimraf": "^6.0.1",
|
|
54
|
-
"rolldown": "^1.2.
|
|
54
|
+
"rolldown": "^1.2.16",
|
|
55
55
|
"rolldown-plugin-dts": "^0.26.0",
|
|
56
56
|
"typescript": "^6.0.3"
|
|
57
57
|
}
|
package/src/server.test.ts
CHANGED
|
@@ -532,6 +532,38 @@ describe('MCP server', () => {
|
|
|
532
532
|
expect(fetchMock.mock.calls[0]?.[0].toString()).toBe(expectedUrl)
|
|
533
533
|
})
|
|
534
534
|
|
|
535
|
+
it.each([
|
|
536
|
+
{
|
|
537
|
+
tool: 'get_component_usage_guidelines',
|
|
538
|
+
expectedPath: '/product/components/card/guidelines',
|
|
539
|
+
expectedMessage: 'There are no usage guidelines for the `Card` component',
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
tool: 'get_component_accessibility_guidelines',
|
|
543
|
+
expectedPath: '/product/components/card/accessibility',
|
|
544
|
+
expectedMessage: 'There are no accessibility guidelines for the `Card` component',
|
|
545
|
+
},
|
|
546
|
+
])('$tool does not return homepage content after a redirect', async ({tool, expectedPath, expectedMessage}) => {
|
|
547
|
+
const fetchMock = vi.mocked(fetch)
|
|
548
|
+
fetchMock.mockResolvedValue(responseWithFinalUrl('<main><h1>Primer homepage</h1></main>', 'https://primer.style/'))
|
|
549
|
+
|
|
550
|
+
const result = await client.callTool({name: tool, arguments: {name: 'Card'}})
|
|
551
|
+
|
|
552
|
+
expect(fetchMock).toHaveBeenCalledWith(new URL(expectedPath, 'https://primer.style'))
|
|
553
|
+
expect(result.content).toContainEqual(
|
|
554
|
+
expect.objectContaining({
|
|
555
|
+
type: 'text',
|
|
556
|
+
text: expect.stringContaining(expectedMessage),
|
|
557
|
+
}),
|
|
558
|
+
)
|
|
559
|
+
expect(result.content).not.toContainEqual(
|
|
560
|
+
expect.objectContaining({
|
|
561
|
+
type: 'text',
|
|
562
|
+
text: expect.stringContaining('Primer homepage'),
|
|
563
|
+
}),
|
|
564
|
+
)
|
|
565
|
+
})
|
|
566
|
+
|
|
535
567
|
it.each(['ConfirmationDialog', 'confirmationdialog'])(
|
|
536
568
|
'retrieves ConfirmationDialog documentation for %s from its published URL',
|
|
537
569
|
async name => {
|
package/src/server.ts
CHANGED
|
@@ -28,6 +28,15 @@ const turndownService = new TurndownService()
|
|
|
28
28
|
// Load all tokens with guidelines from primitives
|
|
29
29
|
const allTokensWithGuidelines: TokenWithGuidelines[] = loadAllTokensWithGuidelines()
|
|
30
30
|
|
|
31
|
+
function hasRedirectedToDifferentPage(response: Response, url: URL): boolean {
|
|
32
|
+
if (!response.url) {
|
|
33
|
+
return false
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const finalUrl = new URL(response.url)
|
|
37
|
+
return finalUrl.origin !== url.origin || finalUrl.pathname.replace(/\/$/, '') !== url.pathname.replace(/\/$/, '')
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
function createServer() {
|
|
32
41
|
const server = new McpServer({
|
|
33
42
|
name: 'Primer',
|
|
@@ -316,13 +325,18 @@ ${text}`,
|
|
|
316
325
|
|
|
317
326
|
const url = new URL(`/product/components/${match.slug}/guidelines`, 'https://primer.style')
|
|
318
327
|
const response = await fetch(url)
|
|
319
|
-
|
|
320
|
-
|
|
328
|
+
const redirected = hasRedirectedToDifferentPage(response, url)
|
|
329
|
+
if (!response.ok || redirected) {
|
|
330
|
+
if (
|
|
331
|
+
redirected ||
|
|
332
|
+
(response.status >= 400 && response.status < 500) ||
|
|
333
|
+
(response.status >= 300 && response.status < 400)
|
|
334
|
+
) {
|
|
321
335
|
return {
|
|
322
336
|
content: [
|
|
323
337
|
{
|
|
324
338
|
type: 'text',
|
|
325
|
-
text: `There are no
|
|
339
|
+
text: `There are no usage guidelines for the \`${name}\` component in the @primer/react package.`,
|
|
326
340
|
},
|
|
327
341
|
],
|
|
328
342
|
}
|
|
@@ -389,8 +403,13 @@ ${text}`,
|
|
|
389
403
|
|
|
390
404
|
const url = new URL(`/product/components/${match.slug}/accessibility`, 'https://primer.style')
|
|
391
405
|
const response = await fetch(url)
|
|
392
|
-
|
|
393
|
-
|
|
406
|
+
const redirected = hasRedirectedToDifferentPage(response, url)
|
|
407
|
+
if (!response.ok || redirected) {
|
|
408
|
+
if (
|
|
409
|
+
redirected ||
|
|
410
|
+
(response.status >= 400 && response.status < 500) ||
|
|
411
|
+
(response.status >= 300 && response.status < 400)
|
|
412
|
+
) {
|
|
394
413
|
return {
|
|
395
414
|
content: [
|
|
396
415
|
{
|