@primer/mcp 1.1.3-rc.481d07fca → 1.1.3-rc.58c05ffce
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 +1 -1
- package/dist/{server-CXK_nt9p.js → server-wukIf9d-.js} +12 -5
- package/dist/stdio.js +1 -1
- package/package.json +2 -2
- package/src/server.test.ts +32 -0
- package/src/server.ts +24 -5
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";
|
|
@@ -720,6 +720,11 @@ var version = "1.1.3";
|
|
|
720
720
|
// src/server.ts
|
|
721
721
|
const turndownService = new TurndownService();
|
|
722
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
|
+
}
|
|
723
728
|
function createServer() {
|
|
724
729
|
const server = new McpServer({
|
|
725
730
|
name: "Primer",
|
|
@@ -872,10 +877,11 @@ ${turndownService.turndown(source)}`
|
|
|
872
877
|
}] };
|
|
873
878
|
const url = new URL(`/product/components/${match.slug}/guidelines`, "https://primer.style");
|
|
874
879
|
const response = await fetch(url);
|
|
875
|
-
|
|
876
|
-
|
|
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: [{
|
|
877
883
|
type: "text",
|
|
878
|
-
text: `There are no
|
|
884
|
+
text: `There are no usage guidelines for the \`${name}\` component in the @primer/react package.`
|
|
879
885
|
}] };
|
|
880
886
|
throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
|
|
881
887
|
}
|
|
@@ -904,8 +910,9 @@ ${turndownService.turndown(source)}`
|
|
|
904
910
|
}] };
|
|
905
911
|
const url = new URL(`/product/components/${match.slug}/accessibility`, "https://primer.style");
|
|
906
912
|
const response = await fetch(url);
|
|
907
|
-
|
|
908
|
-
|
|
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: [{
|
|
909
916
|
type: "text",
|
|
910
917
|
text: `There are no accessibility guidelines for the \`${name}\` component in the @primer/react package.`
|
|
911
918
|
}] };
|
package/dist/stdio.js
CHANGED
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.3-rc.
|
|
4
|
+
"version": "1.1.3-rc.58c05ffce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"mcp": "./bin/mcp.js"
|
|
@@ -41,7 +41,7 @@
|
|
|
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": "^
|
|
44
|
+
"@primer/react": "^38.47.0",
|
|
45
45
|
"cheerio": "^1.0.0",
|
|
46
46
|
"turndown": "^7.2.0",
|
|
47
47
|
"zod": "^4.6.6"
|
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
|
{
|