Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gold-snakes-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/mcp': minor
---

Adds support for fetching docs via the `/llms.txt` endpoint per-component
27 changes: 12 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions packages/mcp/src/primer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ function idToSlug(id: string): string {
return 'dialog'
}

if (id.startsWith('skeleton')) {
return 'skeleton-loaders'
}

return id.replaceAll('_', '-')
}

Expand Down
35 changes: 22 additions & 13 deletions packages/mcp/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,27 @@ server.registerTool(
})
if (!match) {
return {
content: [
{
type: 'text',
text: `There is no component named \`${name}\` in the @primer/react package. For a full list of components, use the \`list_components\` tool.`,
},
],
isError: true,
errorMessage: `There is no component named \`${name}\` in the @primer/react package. For a full list of components, use the \`list_components\` tool.`,
content: [],
}
Comment on lines 113 to +117
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error response structure using isError and errorMessage is inconsistent with the rest of the codebase. All other error cases in this file (e.g., get_component_examples at lines 186-194, get_component_usage_guidelines at lines 246-254) return error messages within the standard content array structure. This change breaks that established pattern.

Consider changing this to match the existing pattern by returning the error message in a content array instead of using isError and errorMessage fields.

Copilot uses AI. Check for mistakes.
}

const llmsUrl = new URL(`/product/components/${match.slug}/llms.txt`, 'https://primer.style')
const llmsResponse = await fetch(llmsUrl)
if (llmsResponse.ok) {
try {
const llmsText = await llmsResponse.text()
return {
content: [
{
type: 'text',
text: llmsText,
},
],
}
} catch (_: unknown) {
// If there's an error fetching or processing the llms.txt, we fall back to the regular documentation
}
}

Expand Down Expand Up @@ -691,13 +706,7 @@ server.registerTool(
inputSchema: {
surroundingText: z.string().describe('Text surrounding the image, relevant to the image.'),
alt: z.string().describe('The alt text of the image being evaluated'),
image: z
.union([
z.instanceof(File).describe('The image src file being evaluated'),
z.url().describe('The URL of the image src being evaluated'),
z.string().describe('The file path of the image src being evaluated'),
Comment on lines -696 to -698
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were throwing errors during testing: MCP error -32603: Custom types cannot be represented in JSON Schema and they should all be string types in the generated JSON schema

])
.describe('The image file, file path, or URL being evaluated'),
image: z.string().describe('The image URL or file path being evaluated'),
},
},
async ({surroundingText, alt, image}) => {
Expand Down
Loading