Skip to content

Commit 3e47602

Browse files
Add a MCP tool that helps review alt text in context of surrounding text (#6820)
1 parent 5f5fe57 commit 3e47602

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

.changeset/strong-lions-tan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/mcp': minor
3+
---
4+
5+
Adds review_alt_text tool to the Primer MCP

packages/mcp/src/server.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,4 +629,61 @@ The following list of coding guidelines must be followed:
629629
},
630630
)
631631

632+
// -----------------------------------------------------------------------------
633+
// Accessibility
634+
// -----------------------------------------------------------------------------
635+
636+
/**
637+
* The `review_alt_text` tool is experimental and may be removed in future versions.
638+
*
639+
* The intent of this tool is to assist products like Copilot Code Review and Copilot Coding Agent
640+
* in reviewing both user- and AI-generated alt text for images, ensuring compliance with accessibility guidelines.
641+
* This tool is not intended to replace human-generated alt text; rather, it supports the review process
642+
* by providing suggestions for improvement. It should be used alongside human review, not as a substitute.
643+
*
644+
*
645+
**/
646+
server.tool(
647+
'review_alt_text',
648+
'Evaluates image alt text against accessibility best practices and context relevance.',
649+
{
650+
surroundingText: z.string().describe('Text surrounding the image, relevant to the image.'),
651+
alt: z.string().describe('The alt text of the image being evaluated'),
652+
image: z
653+
.union([
654+
z.instanceof(File).describe('The image src file being evaluated'),
655+
z.string().url().describe('The URL of the image src being evaluated'),
656+
z.string().describe('The file path of the image src being evaluated'),
657+
])
658+
.describe('The image file, file path, or URL being evaluated'),
659+
},
660+
async ({surroundingText, alt, image}) => {
661+
// Call the LLM through MCP sampling
662+
const response = await server.server.createMessage({
663+
messages: [
664+
{
665+
role: 'user',
666+
content: {
667+
type: 'text',
668+
text: `Does this alt text: '${alt}' meet accessibility guidelines and describe the image: ${image} accurately in context of this surrounding text: '${surroundingText}'?\n\n`,
669+
},
670+
},
671+
],
672+
sampling: {temperature: 0.4},
673+
maxTokens: 500,
674+
})
675+
676+
return {
677+
content: [
678+
{
679+
type: 'text',
680+
text: response.content.type === 'text' ? response.content.text : 'Unable to generate summary',
681+
},
682+
],
683+
altTextEvaluation: response.content.type === 'text' ? response.content.text : 'Unable to generate summary',
684+
nextSteps: `If the evaluation indicates issues with the alt text, provide more meaningful alt text based on the feedback. DO NOT run this tool repeatedly on the same image - evaluations may vary slightly with each run.`,
685+
}
686+
},
687+
)
688+
632689
export {server}

0 commit comments

Comments
 (0)