Skip to content
Open
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/swift-ads-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/mcp': patch
---

Removes fallback for legacy documentation for components using `get_component`
8 changes: 4 additions & 4 deletions package-lock.json

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

46 changes: 9 additions & 37 deletions packages/mcp/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,10 @@ server.registerTool(
content: [],
}
}

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

const url = new URL(`/product/components/${match.slug}`, 'https://primer.style')
const response = await fetch(url)
if (!response.ok) {
throw new Error(`Failed to fetch ${url}: ${response.statusText}`)
}

const html = await response.text()
if (!html) {
return {
content: [],
}
}

const $ = cheerio.load(html)
const source = $('main').html()
if (!source) {
return {
content: [],
}
} catch (_: unknown) {
// If there's an error fetching or processing the llms.txt, we fall back to a generic error message.
}

const text = turndownService.turndown(source)

return {
content: [
{
type: 'text',
text: `Here is the documentation for the \`${name}\` component from the @primer/react package:
${text}`,
},
],
isError: true,
errorMessage: `There was an error fetching documentation for ${name}. Ensure the component exists.`,
content: [],
Comment on lines 154 to +157
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

The final error message is misleading now that the component is already validated (match exists). This path can also happen when llms.txt is simply missing (e.g. 404) rather than a fetch/processing error, so “Ensure the component exists” and “error fetching documentation” are inaccurate. Consider returning a message that explicitly states that llms.txt documentation is unavailable for this component (and optionally include llmsResponse.status/statusText or treat 404 separately) so tool consumers understand what failed.

Copilot uses AI. Check for mistakes.
}
},
)
Expand Down
Loading