validate_accessibility_wave
Test website accessibility compliance by analyzing WCAG standards, identifying errors, and detecting contrast issues using WAVE evaluation tool.
Instructions
Analyze website accessibility using WAVE. Tests WCAG compliance, errors, and contrast issues. Requires API key.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apiKey | Yes | WAVE API key (required) | |
| reporttype | No | Detail level (1-4) | |
| url | Yes |
Implementation Reference
- src/accessibility/wave.ts:68-129 (handler)Core handler function that implements the validate_accessibility_wave tool logic by querying the WAVE API, parsing results, and returning accessibility metrics (errors, contrast issues, alerts).export async function analyzeWAVE( url: string, options: WAVEOptions ): Promise<WAVEResult> { try { if (!options.apiKey) { throw new Error('WAVE API key is required. Get one at https://wave.webaim.org/api/'); } // Build API URL const params = new URLSearchParams({ key: options.apiKey, url, }); if (options.reporttype) { params.set('reporttype', options.reporttype.toString()); } if (options.viewportwidth) { params.set('viewportwidth', options.viewportwidth.toString()); } const apiUrl = `https://wave.webaim.org/api/request?${params.toString()}`; const response = await fetch(apiUrl); if (!response.ok) { throw new Error(`WAVE API error: ${response.status} ${response.statusText}`); } const data: WAVEResponse = await response.json(); if (!data.status.success) { throw new Error(`WAVE analysis failed with HTTP status: ${data.status.httpstatuscode}`); } return { tool: 'wave', success: true, url, errors: data.categories.error.count, contrast_errors: data.categories.contrast.count, alerts: data.categories.alert.count, total_issues: data.categories.error.count + data.categories.contrast.count + data.categories.alert.count, wave_report_url: data.statistics.waveurl, credits_remaining: data.statistics.creditsremaining, raw: data, }; } catch (error) { return { tool: 'wave', success: false, url, errors: 0, contrast_errors: 0, alerts: 0, total_issues: 0, error: error instanceof Error ? error.message : String(error), }; } }
- index.ts:175-187 (registration)Registration of the tool in the MCP tools array, defining its name, description, and input schema for the Model Context Protocol server.{ name: 'validate_accessibility_wave', description: 'Analyze website accessibility using WAVE. Tests WCAG compliance, errors, and contrast issues. Requires API key.', inputSchema: { type: 'object', properties: { url: { type: 'string' }, apiKey: { type: 'string', description: 'WAVE API key (required)' }, reporttype: { type: 'number', enum: [1, 2, 3, 4], description: 'Detail level (1-4)' }, }, required: ['url', 'apiKey'], }, },
- index.ts:55-59 (schema)Zod schema used for input validation of tool arguments in the dispatch handler.const WAVEArgsSchema = z.object({ url: z.string().url(), apiKey: z.string(), reporttype: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).optional(), });
- index.ts:353-360 (handler)Dispatch handler case in the main tool router that validates inputs and invokes the analyzeWAVE core handler.case 'validate_accessibility_wave': { const validatedArgs = WAVEArgsSchema.parse(args); const result = await analyzeWAVE(validatedArgs.url, { apiKey: validatedArgs.apiKey, reporttype: validatedArgs.reporttype, }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }