Skip to main content
Glama

test_html_string

Analyze HTML content for accessibility compliance with WCAG standards using the Axe-core API. Input HTML strings and optional tags to test for specific accessibility issues.

Instructions

Test an HTML string for accessibility issues

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
htmlYesHTML content to test
tagsNoOptional array of accessibility tags to test (e.g., "wcag2a", "wcag2aa", "wcag21a")

Implementation Reference

  • The main handler function that launches Puppeteer, loads the provided HTML string into a page, runs Axe accessibility analysis, formats the results, and returns them.
    async testHtmlString(args: any) { const { html, tags } = args; if (!html) { throw new McpError( ErrorCode.InvalidParams, 'Missing required parameter: html' ); } let browser; try { browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] }); const page = await browser.newPage(); // Set a reasonable viewport await page.setViewport({ width: 1280, height: 800 }); await page.setContent(html, { waitUntil: 'networkidle0' }); // Run axe analysis const axe = new AxePuppeteer(page); if (tags && tags.length > 0) { axe.withTags(tags); } const result = await axe.analyze(); return { content: [ { type: 'text', text: JSON.stringify(this.formatResults(result), null, 2), }, ], }; } finally { if (browser) { await browser.close(); } } }
  • src/index.ts:66-85 (registration)
    Registers the test_html_string tool in the ListTools response, including name, description, and input schema.
    { name: 'test_html_string', description: 'Test an HTML string for accessibility issues', inputSchema: { type: 'object', properties: { html: { type: 'string', description: 'HTML content to test', }, tags: { type: 'array', items: { type: 'string' }, description: 'Optional array of accessibility tags to test (e.g., "wcag2a", "wcag2aa", "wcag21a")', default: ['wcag2aa'] } }, required: ['html'], }, },
  • src/index.ts:164-165 (registration)
    Maps the tool name to its handler function in the CallToolRequestSchema switch statement.
    case 'test_html_string': return await this.testHtmlString(request.params.arguments);
  • Input schema defining required 'html' string and optional 'tags' array for filtering Axe rules.
    inputSchema: { type: 'object', properties: { html: { type: 'string', description: 'HTML content to test', }, tags: { type: 'array', items: { type: 'string' }, description: 'Optional array of accessibility tags to test (e.g., "wcag2a", "wcag2aa", "wcag21a")', default: ['wcag2aa'] } }, required: ['html'], },
  • Helper function used by the handler to format AxeResults into a structured JSON response.
    private formatResults(result: AxeResults) { return { violations: result.violations.map((violation: Result) => ({ id: violation.id, impact: violation.impact || 'unknown', description: violation.description, help: violation.help, helpUrl: violation.helpUrl, affectedNodes: violation.nodes.map((node: NodeResult) => ({ html: node.html, target: node.target, failureSummary: node.failureSummary || '' })) })), passes: result.passes.length, incomplete: result.incomplete.length, inapplicable: result.inapplicable.length, timestamp: result.timestamp, url: result.url, testEngine: { name: result.testEngine.name, version: result.testEngine.version }, testRunner: result.testRunner, testEnvironment: result.testEnvironment, }; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ronantakizawa/a11ymcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server