a11y-test-mcp 1.0.7 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -8
- package/build/constants.js +21 -0
- package/build/functions.js +50 -66
- package/build/index.js +2 -2
- package/package.json +6 -3
- package/build/functions.d.ts +0 -14
- package/build/index.d.ts +0 -2
- package/build/types.d.ts +0 -17
- package/build/types.js +0 -2
package/README.md
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
# a11y test MCP
|
|
2
|
+
|
|
2
3
|
An MCP (Model Context Protocol) server for performing a11y test on webpages using playwright axe-core. The results are then used in an agent loop with your favorite AI assistant (Cline/Cursor/GH Copilot) to find problems with a11y and suggest improvements.
|
|
3
4
|
|
|
4
5
|
## Features
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
- Perform detailed accessibility testing on any web pages
|
|
8
|
+
- Get an overview of accessibility issues
|
|
9
|
+
- Violations
|
|
10
|
+
- Provides information on which DOM was at fault
|
|
11
|
+
- Passes
|
|
12
|
+
- Incomplete
|
|
13
|
+
- Inapplicable
|
|
14
|
+
- Can specify specific WCAG criteria(Default WCAG 2.0 level A, WCAG 2.0 level AA, WCAG 2.1 level A, WCAG 2.1 level AA)
|
|
14
15
|
|
|
15
16
|
## Installation
|
|
16
17
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_WCAG_TAGS = exports.ALLOWED_PREFIXES_OR_TAGS = exports.WCAG_TAG_MAP = void 0;
|
|
4
|
+
/** WCAG tag map */
|
|
5
|
+
exports.WCAG_TAG_MAP = {
|
|
6
|
+
'a': 'wcag2a',
|
|
7
|
+
'wcag20a': 'wcag2a',
|
|
8
|
+
'wcag2a': 'wcag2a',
|
|
9
|
+
'aa': 'wcag2aa',
|
|
10
|
+
'wcag20aa': 'wcag2aa',
|
|
11
|
+
'wcag2aa': 'wcag2aa',
|
|
12
|
+
'wcag21a': 'wcag21a',
|
|
13
|
+
'wcag21aa': 'wcag21aa',
|
|
14
|
+
'wcag22a': 'wcag22a',
|
|
15
|
+
'wcag22aa': 'wcag22aa',
|
|
16
|
+
// Add other known tags or aliases here
|
|
17
|
+
};
|
|
18
|
+
/** Allow prefixes or tags */
|
|
19
|
+
exports.ALLOWED_PREFIXES_OR_TAGS = ['wcag', 'best-practice', 'section508'];
|
|
20
|
+
/** default WCAG tags */
|
|
21
|
+
exports.DEFAULT_WCAG_TAGS = ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'];
|
package/build/functions.js
CHANGED
|
@@ -4,8 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.convertTestResultToText = exports.execTest = void 0;
|
|
7
|
-
const playwright_1 = __importDefault(require("playwright"));
|
|
8
|
-
const playwright_2 =
|
|
7
|
+
const playwright_1 = __importDefault(require("@axe-core/playwright"));
|
|
8
|
+
const playwright_2 = require("playwright");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
9
10
|
/**
|
|
10
11
|
* Enhance WCAG tag conversion
|
|
11
12
|
* @param {string[]} tags - Array of WCAG tags
|
|
@@ -14,33 +15,28 @@ const playwright_2 = __importDefault(require("@axe-core/playwright"));
|
|
|
14
15
|
const convertWcagTag = (tags) => {
|
|
15
16
|
return tags.map(tag => {
|
|
16
17
|
const lowerTag = tag.toLowerCase().replace(/[\s.]/g, '');
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
case 'wcag2aa':
|
|
23
|
-
case 'aa':
|
|
24
|
-
case 'wcag20aa':
|
|
25
|
-
return 'wcag2aa';
|
|
26
|
-
case 'wcag21a':
|
|
27
|
-
return 'wcag21a';
|
|
28
|
-
case 'wcag21aa':
|
|
29
|
-
return 'wcag21aa';
|
|
30
|
-
case 'wcag22a':
|
|
31
|
-
return 'wcag22a';
|
|
32
|
-
case 'wcag22aa':
|
|
33
|
-
return 'wcag22aa';
|
|
34
|
-
default:
|
|
35
|
-
if (lowerTag.startsWith('wcag') || ['best-practice', 'section508'].includes(lowerTag)) {
|
|
36
|
-
return lowerTag;
|
|
37
|
-
}
|
|
38
|
-
console.warn(`Unrecognized WCAG tag: ${tag}`);
|
|
39
|
-
return '';
|
|
18
|
+
if (lowerTag in constants_1.WCAG_TAG_MAP) {
|
|
19
|
+
return constants_1.WCAG_TAG_MAP[lowerTag];
|
|
20
|
+
}
|
|
21
|
+
if (constants_1.ALLOWED_PREFIXES_OR_TAGS.some(prefixOrTag => lowerTag.startsWith(prefixOrTag) || lowerTag === prefixOrTag)) {
|
|
22
|
+
return lowerTag;
|
|
40
23
|
}
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
});
|
|
24
|
+
console.warn(`Unrecognized WCAG tag: ${tag}`);
|
|
25
|
+
return '';
|
|
26
|
+
}).filter(tag => tag !== '');
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Formats a single accessibility violation into a human-readable string.
|
|
30
|
+
* Includes impact level, ID, description, node count, help URL, and details of each affected node.
|
|
31
|
+
* @param {ViolationSummary} v - The violation summary object containing details about the violation.
|
|
32
|
+
* @returns {string} A formatted string representing the violation, suitable for display in reports or logs.
|
|
33
|
+
*/
|
|
34
|
+
const formatViolation = (v) => {
|
|
35
|
+
const violationHeader = ` - [${String(v.impact?.toUpperCase() ?? 'N/A')}] ${v.id}: ${v.description} (Nodes: ${String(v.nodes.length)}, Help: ${v.helpUrl})`;
|
|
36
|
+
const violationNodes = v.nodes
|
|
37
|
+
.map((node, index) => ` Node ${String(index + 1)}: ${node.html}`)
|
|
38
|
+
.join('\n');
|
|
39
|
+
return `${violationHeader}\n${violationNodes}`;
|
|
44
40
|
};
|
|
45
41
|
/**
|
|
46
42
|
* Execute a11y test
|
|
@@ -49,55 +45,52 @@ const convertWcagTag = (tags) => {
|
|
|
49
45
|
* @returns {AccessibilityTestOutput[]} - Results of the accessibility tests
|
|
50
46
|
*/
|
|
51
47
|
const execTest = async (urls, wcagStandards) => {
|
|
52
|
-
const
|
|
53
|
-
const browser = await playwright_1.default.chromium.launch();
|
|
48
|
+
const browser = await playwright_2.chromium.launch();
|
|
54
49
|
const context = await browser.newContext();
|
|
55
50
|
const tagsToUse = (wcagStandards && wcagStandards.length > 0)
|
|
56
51
|
? convertWcagTag(wcagStandards)
|
|
57
|
-
:
|
|
52
|
+
: constants_1.DEFAULT_WCAG_TAGS;
|
|
58
53
|
try {
|
|
59
|
-
|
|
54
|
+
const results = await Promise.all(urls.map(async (url) => {
|
|
60
55
|
let page = null;
|
|
61
56
|
try {
|
|
62
57
|
page = await context.newPage();
|
|
63
58
|
await page.goto(url, { waitUntil: 'networkidle' });
|
|
64
|
-
const axeBuilder = new
|
|
59
|
+
const axeBuilder = new playwright_1.default({ page });
|
|
65
60
|
axeBuilder.withTags(tagsToUse);
|
|
66
61
|
const axeResults = await axeBuilder.analyze();
|
|
67
|
-
// Summarize results, handling null impact
|
|
68
62
|
const summarizedViolations = axeResults.violations.map(v => ({
|
|
69
63
|
id: v.id,
|
|
70
|
-
// Handle null impact from axe-core
|
|
71
64
|
impact: v.impact === null ? undefined : v.impact,
|
|
72
65
|
description: v.description,
|
|
73
66
|
helpUrl: v.helpUrl,
|
|
74
|
-
nodes: v.nodes
|
|
67
|
+
nodes: v.nodes,
|
|
75
68
|
}));
|
|
76
|
-
|
|
69
|
+
return {
|
|
77
70
|
url: url,
|
|
78
71
|
violations: summarizedViolations,
|
|
79
72
|
passesCount: axeResults.passes.length,
|
|
80
73
|
incompleteCount: axeResults.incomplete.length,
|
|
81
74
|
inapplicableCount: axeResults.inapplicable.length,
|
|
82
|
-
}
|
|
75
|
+
};
|
|
83
76
|
}
|
|
84
77
|
catch (error) {
|
|
85
|
-
|
|
78
|
+
return {
|
|
86
79
|
url: url,
|
|
87
80
|
error: `Failed to test: ${error instanceof Error ? error.message : String(error)}`,
|
|
88
|
-
}
|
|
81
|
+
};
|
|
89
82
|
}
|
|
90
83
|
finally {
|
|
91
84
|
if (page !== null) {
|
|
92
85
|
await page.close();
|
|
93
86
|
}
|
|
94
87
|
}
|
|
95
|
-
}
|
|
88
|
+
}));
|
|
89
|
+
return results;
|
|
96
90
|
}
|
|
97
91
|
finally {
|
|
98
92
|
await browser.close();
|
|
99
93
|
}
|
|
100
|
-
return results;
|
|
101
94
|
};
|
|
102
95
|
exports.execTest = execTest;
|
|
103
96
|
/**
|
|
@@ -106,34 +99,25 @@ exports.execTest = execTest;
|
|
|
106
99
|
* @returns {string} - Text representation of the results
|
|
107
100
|
*/
|
|
108
101
|
const convertTestResultToText = (structuredResults) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
let outputText = '';
|
|
103
|
+
for (const result of structuredResults) {
|
|
104
|
+
let resultText = `URL: ${result.url}\n`;
|
|
112
105
|
if (result.error) {
|
|
113
|
-
|
|
106
|
+
resultText += ` Error: ${result.error}\n`;
|
|
114
107
|
}
|
|
115
108
|
else {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
.map((node, index) => {
|
|
122
|
-
return ` Node ${String(index + 1)}: ${node.html}`;
|
|
123
|
-
})
|
|
124
|
-
.join('\n')
|
|
125
|
-
].join('\n');
|
|
126
|
-
});
|
|
127
|
-
if (resultViolationText !== undefined) {
|
|
128
|
-
resultTextList.push(...resultViolationText);
|
|
109
|
+
resultText += ` Violations: ${String(result.violations?.length ?? 0)}\n`;
|
|
110
|
+
if (result.violations && result.violations.length > 0) {
|
|
111
|
+
for (const violation of result.violations) {
|
|
112
|
+
resultText += `${formatViolation(violation)}\n`;
|
|
113
|
+
}
|
|
129
114
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
115
|
+
resultText += ` Passes: ${String(result.passesCount ?? 0)}\n`;
|
|
116
|
+
resultText += ` Incomplete: ${String(result.incompleteCount ?? 0)}\n`;
|
|
117
|
+
resultText += ` Inapplicable: ${String(result.inapplicableCount ?? 0)}\n`;
|
|
133
118
|
}
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
.trim();
|
|
119
|
+
outputText += resultText + '\n';
|
|
120
|
+
}
|
|
121
|
+
return outputText.trim();
|
|
138
122
|
};
|
|
139
123
|
exports.convertTestResultToText = convertTestResultToText;
|
package/build/index.js
CHANGED
|
@@ -15,8 +15,8 @@ server.tool('exec-a11y-test', 'Obtains a list of specified list of URL and a lis
|
|
|
15
15
|
return {
|
|
16
16
|
content: [{
|
|
17
17
|
type: 'text',
|
|
18
|
-
text: (0, functions_1.convertTestResultToText)(structuredResults)
|
|
19
|
-
}]
|
|
18
|
+
text: (0, functions_1.convertTestResultToText)(structuredResults),
|
|
19
|
+
}],
|
|
20
20
|
};
|
|
21
21
|
});
|
|
22
22
|
/**
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "a11y-test-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"postinstall": "npx -y playwright install",
|
|
7
7
|
"build": "tsc && chmod 755 build/index.js",
|
|
8
8
|
"start": "node build/index.js",
|
|
9
|
-
"lint": "
|
|
10
|
-
"
|
|
9
|
+
"lint": "npm run lint:e && npm run lint:d",
|
|
10
|
+
"lint:e": "eslint .",
|
|
11
|
+
"lint:d": "dprint check",
|
|
12
|
+
"format": "dprint fmt"
|
|
11
13
|
},
|
|
12
14
|
"bin": {
|
|
13
15
|
"a11y-test-mcp": "build/index.js"
|
|
@@ -43,6 +45,7 @@
|
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"@eslint/js": "^9.25.1",
|
|
45
47
|
"@types/node": "^22.15.2",
|
|
48
|
+
"dprint": "^0.49.1",
|
|
46
49
|
"eslint": "^9.25.1",
|
|
47
50
|
"eslint-config-flat-gitignore": "^2.1.0",
|
|
48
51
|
"typescript": "^5.8.3",
|
package/build/functions.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { AccessibilityTestOutput } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Execute a11y test
|
|
4
|
-
* @param {string[]} urls - URLs
|
|
5
|
-
* @param {string[] | undefined} wcagStandards - WCAG standards to apply
|
|
6
|
-
* @returns {AccessibilityTestOutput[]} - Results of the accessibility tests
|
|
7
|
-
*/
|
|
8
|
-
export declare const execTest: (urls: string[], wcagStandards: string[] | undefined) => Promise<AccessibilityTestOutput[]>;
|
|
9
|
-
/**
|
|
10
|
-
* Convert structured results to text format
|
|
11
|
-
* @param {AccessibilityTestOutput[]} structuredResults - Structured results from the tests
|
|
12
|
-
* @returns {string} - Text representation of the results
|
|
13
|
-
*/
|
|
14
|
-
export declare const convertTestResultToText: (structuredResults: AccessibilityTestOutput[]) => string;
|
package/build/index.d.ts
DELETED
package/build/types.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { NodeResult } from 'axe-core';
|
|
2
|
-
export interface ViolationSummary {
|
|
3
|
-
id: string;
|
|
4
|
-
impact?: 'minor' | 'moderate' | 'serious' | 'critical';
|
|
5
|
-
description: string;
|
|
6
|
-
helpUrl: string;
|
|
7
|
-
nodes: NodeResult[];
|
|
8
|
-
}
|
|
9
|
-
/** Update the main output structure */
|
|
10
|
-
export interface AccessibilityTestOutput {
|
|
11
|
-
url: string;
|
|
12
|
-
violations?: ViolationSummary[];
|
|
13
|
-
passesCount?: number;
|
|
14
|
-
incompleteCount?: number;
|
|
15
|
-
inapplicableCount?: number;
|
|
16
|
-
error?: string;
|
|
17
|
-
}
|
package/build/types.js
DELETED