a11y-test-mcp 1.0.0

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 ADDED
@@ -0,0 +1,50 @@
1
+ # a11y test MCP
2
+ 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
+ ## Features
5
+
6
+ * Perform detailed accessibility testing on any web pages
7
+ * Get an overview of accessibility issues
8
+ * Violations
9
+ * Provides information on which DOM was at fault
10
+ * Passes
11
+ * Incomplete
12
+ * Inapplicable
13
+ * Can specify specific WCAG criteria
14
+
15
+ ## Installation
16
+
17
+ ```
18
+ # Global install
19
+ npm install -g a11y-test-mcp
20
+
21
+ # With npx command
22
+ npx a11y-test-mcp
23
+ ```
24
+
25
+ ## Configuration
26
+
27
+ Add the following to the mcpServers object:
28
+
29
+ ```json
30
+ {
31
+ "servers": {
32
+ "a11y-test": {
33
+ "type": "stdio",
34
+ "command": "npx",
35
+ "args": ["a11y-test-mcp"]
36
+ }
37
+ }
38
+ }
39
+ ```
40
+
41
+ ## Example prompt
42
+
43
+ ```
44
+ Please perform accessibility testing on the following sites.
45
+ Tests should be performed at WCAG Level A.
46
+ If there are problems, please indicate which HTML elements are at fault.
47
+
48
+ * https://example.com
49
+ * https://example.com/home
50
+ ```
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.convertTestResultToText = exports.execTest = void 0;
7
+ const playwright_1 = __importDefault(require("playwright"));
8
+ const playwright_2 = __importDefault(require("@axe-core/playwright"));
9
+ /**
10
+ * Enhance WCAG tag conversion
11
+ * @param {string[]} tags - Array of WCAG tags
12
+ * @returns {string[]} Converted array of WCAG tags
13
+ */
14
+ const convertWcagTag = (tags) => {
15
+ return tags.map(tag => {
16
+ const lowerTag = tag.toLowerCase().replace(/[\s.]/g, '');
17
+ switch (lowerTag) {
18
+ case 'wcag2a':
19
+ case 'a':
20
+ case 'wcag20a':
21
+ return 'wcag2a';
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 '';
40
+ }
41
+ }).filter(tag => tag !== '');
42
+ };
43
+ /**
44
+ * Execute a11y test
45
+ * @param {string[]} urls - URLs
46
+ * @param {string[] | undefined} wcagStandards - WCAG standards to apply
47
+ * @returns {AccessibilityTestOutput[]} - Results of the accessibility tests
48
+ */
49
+ const execTest = async (urls, wcagStandards) => {
50
+ const results = [];
51
+ const browser = await playwright_1.default.chromium.launch();
52
+ const context = await browser.newContext();
53
+ try {
54
+ for (const url of urls) {
55
+ let page;
56
+ try {
57
+ page = await context.newPage();
58
+ await page.goto(url, { waitUntil: 'networkidle' });
59
+ const axeBuilder = new playwright_2.default({ page });
60
+ const tagsToUse = (wcagStandards && wcagStandards.length > 0)
61
+ ? convertWcagTag(wcagStandards)
62
+ : ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"];
63
+ if (tagsToUse.length > 0) {
64
+ axeBuilder.withTags(tagsToUse);
65
+ }
66
+ else {
67
+ console.warn("No valid WCAG tags specified, running Axe with default rules.");
68
+ }
69
+ const axeResults = await axeBuilder.analyze();
70
+ // Summarize results, handling null impact
71
+ const summarizedViolations = axeResults.violations.map(v => ({
72
+ id: v.id,
73
+ // Handle null impact from axe-core
74
+ impact: v.impact === null ? undefined : v.impact,
75
+ description: v.description,
76
+ helpUrl: v.helpUrl,
77
+ nodes: v.nodes
78
+ }));
79
+ results.push({
80
+ url: url,
81
+ violations: summarizedViolations,
82
+ passesCount: axeResults.passes.length,
83
+ incompleteCount: axeResults.incomplete.length,
84
+ inapplicableCount: axeResults.inapplicable.length,
85
+ });
86
+ }
87
+ catch (error) {
88
+ results.push({
89
+ url: url,
90
+ error: `Failed to test: ${error instanceof Error ? error.message : String(error)}`,
91
+ });
92
+ }
93
+ finally {
94
+ if (page) {
95
+ await page.close();
96
+ }
97
+ }
98
+ }
99
+ }
100
+ finally {
101
+ await browser.close();
102
+ }
103
+ return results;
104
+ };
105
+ exports.execTest = execTest;
106
+ /**
107
+ * Convert structured results to text format
108
+ * @param {AccessibilityTestOutput[]} structuredResults - Structured results from the tests
109
+ * @returns {string} - Text representation of the results
110
+ */
111
+ const convertTestResultToText = (structuredResults) => {
112
+ return structuredResults
113
+ .map((result) => {
114
+ const resultTextList = [`URL: ${result.url}`];
115
+ if (result.error) {
116
+ resultTextList.push(` Error: ${result.error}`);
117
+ }
118
+ else {
119
+ resultTextList.push(` Violations: ${result.violations?.length ?? 0}`);
120
+ const resultViolationText = result.violations?.map((v) => {
121
+ return [
122
+ ` - [${v.impact?.toUpperCase()}] ${v.id}: ${v.description} (Nodes: ${v.nodes.length}, Help: ${v.helpUrl})`,
123
+ v.nodes
124
+ .map((node, index) => {
125
+ return ` Node ${index + 1}: ${node.html}`;
126
+ })
127
+ .join('\n')
128
+ ].join('\n');
129
+ });
130
+ if (resultViolationText !== undefined) {
131
+ resultTextList.push(...resultViolationText);
132
+ }
133
+ resultTextList.push(` Passes: ${result.passesCount ?? 0}`);
134
+ resultTextList.push(` Incomplete: ${result.incompleteCount ?? 0}`);
135
+ resultTextList.push(` Inapplicable: ${result.inapplicableCount ?? 0}`);
136
+ }
137
+ return resultTextList.join('\n');
138
+ })
139
+ .join('\n')
140
+ .trim();
141
+ };
142
+ exports.convertTestResultToText = convertTestResultToText;
package/build/index.js ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
5
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
6
+ const zod_1 = require("zod");
7
+ const functions_1 = require("./functions");
8
+ /** Create an MCP server instance */
9
+ const server = new mcp_js_1.McpServer({
10
+ name: 'accessibility-tester',
11
+ version: '0.1.1',
12
+ });
13
+ server.tool('exec-a11y-test', 'Obtains a list of specified list of URL and a list of WCAG indicators and returns the results', { urls: zod_1.z.array(zod_1.z.string().url()), wcagStandards: zod_1.z.array(zod_1.z.string()).optional() }, async ({ urls, wcagStandards }) => {
14
+ const structuredResults = await (0, functions_1.execTest)(urls, wcagStandards);
15
+ return {
16
+ content: [{
17
+ type: 'text',
18
+ text: (0, functions_1.convertTestResultToText)(structuredResults)
19
+ }]
20
+ };
21
+ });
22
+ /**
23
+ * Main function to start the server
24
+ */
25
+ const main = async () => {
26
+ const transport = new stdio_js_1.StdioServerTransport();
27
+ await server.connect(transport);
28
+ console.error('A11y Accessibility MCP server running on stdio');
29
+ };
30
+ process.on('SIGINT', async () => {
31
+ await server.close();
32
+ process.exit(0);
33
+ });
34
+ main().catch(console.error);
package/build/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "a11y-test-mcp",
3
+ "version": "1.0.0",
4
+ "main": "build/index.js",
5
+ "scripts": {
6
+ "build": "tsc && chmod 755 build/index.js",
7
+ "start": "node build/index.js"
8
+ },
9
+ "bin": {
10
+ "a11y-mcp": "build/index.js"
11
+ },
12
+ "keywords": [
13
+ "accessibility",
14
+ "a11y",
15
+ "mcp",
16
+ "playwright",
17
+ "axe-core"
18
+ ],
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git@github.com:noriyuki-shimizu/a11y-test-mcp.git"
22
+ },
23
+ "author": "Noriyuki Shimizu",
24
+ "license": "ISC",
25
+ "type": "commonjs",
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "files": [
30
+ "build"
31
+ ],
32
+ "description": "",
33
+ "homepage": "https://github.com/noriyuki-shimizu/a11y-test-mcp/blob/main/README.md",
34
+ "dependencies": {
35
+ "@axe-core/playwright": "^4.10.1",
36
+ "@modelcontextprotocol/sdk": "^1.10.2",
37
+ "playwright": "^1.52.0",
38
+ "zod": "^3.24.3"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^22.15.2",
42
+ "typescript": "^5.8.3"
43
+ },
44
+ "volta": {
45
+ "node": "22.15.0",
46
+ "npm": "10.9.2"
47
+ }
48
+ }