diff --git a/.changeset/swift-ads-matter.md b/.changeset/swift-ads-matter.md new file mode 100644 index 00000000000..1b3da848a91 --- /dev/null +++ b/.changeset/swift-ads-matter.md @@ -0,0 +1,5 @@ +--- +'@primer/mcp': patch +--- + +Removes fallback for legacy documentation for components using `get_component` diff --git a/packages/mcp/src/server.ts b/packages/mcp/src/server.ts index 7cda805d255..915e565fd69 100644 --- a/packages/mcp/src/server.ts +++ b/packages/mcp/src/server.ts @@ -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: [ @@ -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: [], } }, )