a11y-test-mcp 1.0.1 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "a11y-test-mcp",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "build/index.js",
5
5
  "scripts": {
6
6
  "build": "tsc && chmod 755 build/index.js",
@@ -1,142 +0,0 @@
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 DELETED
@@ -1,34 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });