a11y-test-mcp 1.0.2 → 1.0.4
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/build/functions.d.ts +14 -0
- package/build/functions.js +144 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +34 -0
- package/build/types.d.ts +17 -0
- package/build/types.js +2 -0
- package/package.json +10 -4
|
@@ -0,0 +1,14 @@
|
|
|
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;
|
|
@@ -0,0 +1,144 @@
|
|
|
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 => {
|
|
42
|
+
return tag !== '';
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Execute a11y test
|
|
47
|
+
* @param {string[]} urls - URLs
|
|
48
|
+
* @param {string[] | undefined} wcagStandards - WCAG standards to apply
|
|
49
|
+
* @returns {AccessibilityTestOutput[]} - Results of the accessibility tests
|
|
50
|
+
*/
|
|
51
|
+
const execTest = async (urls, wcagStandards) => {
|
|
52
|
+
const results = [];
|
|
53
|
+
const browser = await playwright_1.default.chromium.launch();
|
|
54
|
+
const context = await browser.newContext();
|
|
55
|
+
try {
|
|
56
|
+
for (const url of urls) {
|
|
57
|
+
let page;
|
|
58
|
+
try {
|
|
59
|
+
page = await context.newPage();
|
|
60
|
+
await page.goto(url, { waitUntil: 'networkidle' });
|
|
61
|
+
const axeBuilder = new playwright_2.default({ page });
|
|
62
|
+
const tagsToUse = (wcagStandards && wcagStandards.length > 0)
|
|
63
|
+
? convertWcagTag(wcagStandards)
|
|
64
|
+
: ["wcag2a", "wcag2aa", "wcag21a", "wcag21aa"];
|
|
65
|
+
if (tagsToUse.length > 0) {
|
|
66
|
+
axeBuilder.withTags(tagsToUse);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
console.warn("No valid WCAG tags specified, running Axe with default rules.");
|
|
70
|
+
}
|
|
71
|
+
const axeResults = await axeBuilder.analyze();
|
|
72
|
+
// Summarize results, handling null impact
|
|
73
|
+
const summarizedViolations = axeResults.violations.map(v => ({
|
|
74
|
+
id: v.id,
|
|
75
|
+
// Handle null impact from axe-core
|
|
76
|
+
impact: v.impact === null ? undefined : v.impact,
|
|
77
|
+
description: v.description,
|
|
78
|
+
helpUrl: v.helpUrl,
|
|
79
|
+
nodes: v.nodes
|
|
80
|
+
}));
|
|
81
|
+
results.push({
|
|
82
|
+
url: url,
|
|
83
|
+
violations: summarizedViolations,
|
|
84
|
+
passesCount: axeResults.passes.length,
|
|
85
|
+
incompleteCount: axeResults.incomplete.length,
|
|
86
|
+
inapplicableCount: axeResults.inapplicable.length,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
results.push({
|
|
91
|
+
url: url,
|
|
92
|
+
error: `Failed to test: ${error instanceof Error ? error.message : String(error)}`,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
if (page) {
|
|
97
|
+
await page.close();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
await browser.close();
|
|
104
|
+
}
|
|
105
|
+
return results;
|
|
106
|
+
};
|
|
107
|
+
exports.execTest = execTest;
|
|
108
|
+
/**
|
|
109
|
+
* Convert structured results to text format
|
|
110
|
+
* @param {AccessibilityTestOutput[]} structuredResults - Structured results from the tests
|
|
111
|
+
* @returns {string} - Text representation of the results
|
|
112
|
+
*/
|
|
113
|
+
const convertTestResultToText = (structuredResults) => {
|
|
114
|
+
return structuredResults
|
|
115
|
+
.map((result) => {
|
|
116
|
+
const resultTextList = [`URL: ${result.url}`];
|
|
117
|
+
if (result.error) {
|
|
118
|
+
resultTextList.push(` Error: ${result.error}`);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
resultTextList.push(` Violations: ${String(result.violations?.length ?? 0)}`);
|
|
122
|
+
const resultViolationText = result.violations?.map((v) => {
|
|
123
|
+
return [
|
|
124
|
+
` - [${String(v.impact?.toUpperCase() ?? 'N/A')}] ${v.id}: ${v.description} (Nodes: ${String(v.nodes.length)}, Help: ${v.helpUrl})`,
|
|
125
|
+
v.nodes
|
|
126
|
+
.map((node, index) => {
|
|
127
|
+
return ` Node ${String(index + 1)}: ${node.html}`;
|
|
128
|
+
})
|
|
129
|
+
.join('\n')
|
|
130
|
+
].join('\n');
|
|
131
|
+
});
|
|
132
|
+
if (resultViolationText !== undefined) {
|
|
133
|
+
resultTextList.push(...resultViolationText);
|
|
134
|
+
}
|
|
135
|
+
resultTextList.push(` Passes: ${String(result.passesCount ?? 0)}`);
|
|
136
|
+
resultTextList.push(` Incomplete: ${String(result.incompleteCount ?? 0)}`);
|
|
137
|
+
resultTextList.push(` Inapplicable: ${String(result.inapplicableCount ?? 0)}`);
|
|
138
|
+
}
|
|
139
|
+
return resultTextList.join('\n');
|
|
140
|
+
})
|
|
141
|
+
.join('\n')
|
|
142
|
+
.trim();
|
|
143
|
+
};
|
|
144
|
+
exports.convertTestResultToText = convertTestResultToText;
|
package/build/index.d.ts
ADDED
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', () => {
|
|
31
|
+
void server.close();
|
|
32
|
+
process.exit(0);
|
|
33
|
+
});
|
|
34
|
+
main().catch(console.error);
|
package/build/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
ADDED
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "a11y-test-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc && chmod 755 build/index.js",
|
|
7
|
-
"start": "node build/index.js"
|
|
7
|
+
"start": "node build/index.js",
|
|
8
|
+
"lint": "eslint .",
|
|
9
|
+
"format": "npm run lint -- --fix"
|
|
8
10
|
},
|
|
9
11
|
"bin": {
|
|
10
|
-
"a11y-mcp": "build/index.js"
|
|
12
|
+
"a11y-test-mcp": "build/index.js"
|
|
11
13
|
},
|
|
12
14
|
"keywords": [
|
|
13
15
|
"accessibility",
|
|
@@ -38,8 +40,12 @@
|
|
|
38
40
|
"zod": "^3.24.3"
|
|
39
41
|
},
|
|
40
42
|
"devDependencies": {
|
|
43
|
+
"@eslint/js": "^9.25.1",
|
|
41
44
|
"@types/node": "^22.15.2",
|
|
42
|
-
"
|
|
45
|
+
"eslint": "^9.25.1",
|
|
46
|
+
"eslint-config-flat-gitignore": "^2.1.0",
|
|
47
|
+
"typescript": "^5.8.3",
|
|
48
|
+
"typescript-eslint": "^8.31.0"
|
|
43
49
|
},
|
|
44
50
|
"volta": {
|
|
45
51
|
"node": "22.15.0",
|