-
Notifications
You must be signed in to change notification settings - Fork 658
[MCP] Add support for the /llms.txt component endpoint
#7495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a499568
f873384
82d8637
0035fd1
a543100
ff13cc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: [], | ||
| } | ||
| } | ||
|
|
||
| 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 | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These were throwing errors during testing: |
||
| ]) | ||
| .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}) => { | ||
|
|
||
There was a problem hiding this comment.
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
isErroranderrorMessageis 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 standardcontentarray 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
isErroranderrorMessagefields.