Skip to main content
Glama
bilhasry-deriv

Web Accessibility MCP Server

simulate_colorblind

Simulate webpage appearance for colorblind users to test accessibility. Input a URL and color blindness type to generate visual simulations.

Instructions

Simulate how a webpage looks for colorblind users

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to capture
typeYesType of color blindness to simulate
outputPathNoOptional path to save the screenshot
userAgentNoOptional user agent string to use for the request

Implementation Reference

  • Main handler function for simulate_colorblind tool. Launches headless browser with Puppeteer, loads the webpage, injects JavaScript to simulate colorblindness by applying color transformation matrices to all elements' text and background colors, takes a full-page screenshot, and saves it.
    private async handleColorBlindSimulation(request: any) {
      if (!request.params.arguments || 
          typeof request.params.arguments.url !== 'string' ||
          typeof request.params.arguments.type !== 'string') {
        throw new McpError(
          ErrorCode.InvalidParams,
          'URL and type parameters are required'
        );
      }
    
      const args: SimulateColorblindArgs = {
        url: request.params.arguments.url,
        type: request.params.arguments.type as 'protanopia' | 'deuteranopia' | 'tritanopia',
        outputPath: request.params.arguments.outputPath,
        userAgent: request.params.arguments.userAgent
      };
    
      let browser;
      try {
        console.error('[Debug] Launching browser...');
        browser = await puppeteer.launch({
          headless: true,
          args: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
            '--disable-dev-shm-usage',
            '--disable-accelerated-2d-canvas',
            '--disable-gpu',
            '--window-size=1920,1080'
          ]
        });
    
        console.error('[Debug] Creating new page...');
        const page = await browser.newPage();
        await page.setViewport({ width: 1920, height: 1080 });
        await page.setUserAgent(args.userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
    
        // Enable request interception for debugging
        await page.setRequestInterception(true);
        page.on('request', request => {
          console.error(`[Debug] Request: ${request.url()}`);
          request.continue();
        });
        page.on('response', response => {
          console.error(`[Debug] Response: ${response.url()} - ${response.status()}`);
        });
        page.on('console', msg => {
          console.error(`[Page Console] ${msg.text()}`);
        });
    
        console.error('[Debug] Navigating to URL...');
        const urlToUse = args.url.replace(/^(https?:\/\/)?(www\.)?/, 'https://www.');
        console.error(`[Debug] Modified URL: ${urlToUse}`);
        
        const response = await page.goto(urlToUse, { 
          waitUntil: 'networkidle2',
          timeout: 120000 // Increased timeout to 2 minutes
        });
        
        console.error(`[Debug] Page loaded with status: ${response?.status()}`);
    
        // Wait for the page to be fully loaded
        console.error('[Debug] Waiting for page load...');
        await page.waitForSelector('body', { timeout: 120000 });
        
        // Give extra time for dynamic content
        console.error('[Debug] Waiting for dynamic content...');
        await new Promise(resolve => setTimeout(resolve, 5000));
    
        // Inject the colorblind simulation code
        console.error('[Debug] Injecting colorblind simulation...');
        await page.evaluate((type) => {
          // Implementation of colorblind simulation
          function multiply(a: number[], b: number[]): number[] {
            return [
              a[0] * b[0] + a[1] * b[3] + a[2] * b[6],
              a[0] * b[1] + a[1] * b[4] + a[2] * b[7],
              a[0] * b[2] + a[1] * b[5] + a[2] * b[8],
            ];
          }
    
          const colorBlindnessMatrices = {
            protanopia: [
              0.567, 0.433, 0, 
              0.558, 0.442, 0, 
              0, 0.242, 0.758
            ],
            deuteranopia: [
              0.625, 0.375, 0, 
              0.7, 0.3, 0, 
              0, 0.3, 0.7
            ],
            tritanopia: [
              0.95, 0.05, 0, 
              0, 0.433, 0.567, 
              0, 0.475, 0.525
            ]
          };
    
          window.simulate = function(rgb: RGB, type: string): RGB {
            const matrix = colorBlindnessMatrices[type as keyof typeof colorBlindnessMatrices];
            const result = multiply([rgb.r / 255, rgb.g / 255, rgb.b / 255], matrix);
            return {
              r: Math.round(result[0] * 255),
              g: Math.round(result[1] * 255),
              b: Math.round(result[2] * 255)
            };
          };
          function parseColor(color: string): RGB {
            color = color.toLowerCase().replace(/\s/g, '');
            if (color.startsWith('rgba(') || color.startsWith('rgb(')) {
              const values = color
                .replace('rgba(', '')
                .replace('rgb(', '')
                .replace(')', '')
                .split(',')
                .map(Number);
              return {
                r: values[0],
                g: values[1],
                b: values[2]
              };
            }
            if (color.startsWith('#')) {
              const hex = color.replace('#', '');
              const r = parseInt(hex.substr(0, 2), 16);
              const g = parseInt(hex.substr(2, 2), 16);
              const b = parseInt(hex.substr(4, 2), 16);
              return { r, g, b };
            }
            return { r: 0, g: 0, b: 0 };
          }
    
          function rgbToString(rgb: RGB): string {
            return `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`;
          }
    
          // Get all elements with background color or color
          const elements = document.querySelectorAll('*');
          elements.forEach(el => {
            const htmlEl = el as HTMLElement;
            const styles = window.getComputedStyle(htmlEl);
            const color = styles.color;
            const backgroundColor = styles.backgroundColor;
    
            if (color !== 'rgba(0, 0, 0, 0)') {
              const rgbColor = parseColor(color);
              const simulatedColor = window.simulate(rgbColor, type);
              htmlEl.style.color = rgbToString(simulatedColor);
            }
            
            if (backgroundColor !== 'rgba(0, 0, 0, 0)') {
              const rgbBgColor = parseColor(backgroundColor);
              const simulatedBgColor = window.simulate(rgbBgColor, type);
              htmlEl.style.backgroundColor = rgbToString(simulatedBgColor);
            }
          });
        }, args.type);
    
        // Wait for the filter to be applied
        console.error('[Debug] Waiting for filter to apply...');
        await new Promise(resolve => setTimeout(resolve, 2000));
    
        // Get output directory from environment variable or use default
        const outputDir = process.env.MCP_OUTPUT_DIR || './output';
        console.error('[Debug] Taking screenshot...');
        const outputPath = join(outputDir, args.outputPath || `colorblind_${args.type}.png`);
        
        await page.screenshot({
          path: outputPath,
          fullPage: true
        });
    
        console.error('[Debug] Screenshot saved successfully');
        await browser.close();
        console.error('[Debug] Browser closed');
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                url: args.url,
                type: args.type,
                outputPath: outputPath,
                timestamp: new Date().toISOString(),
                message: `Screenshot saved with ${args.type} simulation`
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error('[Debug] Error occurred:', error);
        if (browser) {
          try {
            await browser.close();
            console.error('[Debug] Browser closed after error');
          } catch (closeError) {
            console.error('[Debug] Error closing browser:', closeError);
          }
        }
        return {
          content: [
            {
              type: 'text',
              text: `Error simulating color blindness: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • TypeScript interface defining the input parameters for the simulate_colorblind tool.
    interface SimulateColorblindArgs {
      url: string;
      type: 'protanopia' | 'deuteranopia' | 'tritanopia';
      outputPath?: string;
      userAgent?: string;
    }
  • src/index.ts:130-156 (registration)
    Tool registration in the listTools response, defining name, description, and JSON schema matching the TypeScript interface.
    {
      name: 'simulate_colorblind',
      description: 'Simulate how a webpage looks for colorblind users',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'URL to capture',
          },
          type: {
            type: 'string',
            enum: ['protanopia', 'deuteranopia', 'tritanopia'],
            description: 'Type of color blindness to simulate',
          },
          outputPath: {
            type: 'string',
            description: 'Optional path to save the screenshot',
          },
          userAgent: {
            type: 'string',
            description: 'Optional user agent string to use for the request',
          },
        },
        required: ['url', 'type'],
      },
    },
  • src/index.ts:160-172 (registration)
    Dispatcher in CallToolRequest handler that routes to the specific handler for simulate_colorblind.
      this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
        if (request.params.name === 'check_accessibility') {
          return this.handleAccessibilityCheck(request);
        } else if (request.params.name === 'simulate_colorblind') {
          return this.handleColorBlindSimulation(request);
        } else {
          throw new McpError(
            ErrorCode.MethodNotFound,
            `Unknown tool: ${request.params.name}`
          );
        }
      });
    }
  • Helper function to parse CSS color strings to RGB objects, used in the simulation logic (also redefined in injected JS).
    function parseColor(color: string): RGB {
      // Remove all spaces and convert to lowercase
      color = color.toLowerCase().replace(/\s/g, '');
      
      // Handle rgba/rgb format
      if (color.startsWith('rgba(') || color.startsWith('rgb(')) {
        const values = color
          .replace('rgba(', '')
          .replace('rgb(', '')
          .replace(')', '')
          .split(',')
          .map(Number);
        return {
          r: values[0],
          g: values[1],
          b: values[2]
        };
      }
      
      // Handle hex format
      if (color.startsWith('#')) {
        const hex = color.replace('#', '');
        const r = parseInt(hex.substr(0, 2), 16);
        const g = parseInt(hex.substr(2, 2), 16);
        const b = parseInt(hex.substr(4, 2), 16);
        return { r, g, b };
      }
      
      // Default to black if color format is not recognized
      return { r: 0, g: 0, b: 0 };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool simulates colorblind views but doesn't describe how (e.g., generates a screenshot, modifies display, or returns data), what the output is (e.g., image file, visual report), or any behavioral traits like performance, rate limits, or side effects. This leaves significant gaps for an agent to understand the tool's operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence: 'Simulate how a webpage looks for colorblind users.' It is front-loaded with the core purpose, has zero wasted words, and is appropriately sized for the tool's complexity. Every part of the sentence earns its place by conveying essential information efficiently.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (4 parameters, no output schema, no annotations), the description is incomplete. It lacks details on output (e.g., what is returned or saved), behavioral context (e.g., how simulation works, any limitations), and usage guidelines. While the schema covers parameters well, the description doesn't compensate for missing annotations or output schema, leaving the agent with insufficient context for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, clearly documenting all four parameters (url, type, outputPath, userAgent) with details like enum values for 'type.' The description doesn't add any parameter-specific information beyond what the schema provides, such as explaining the simulation process or output format. Given the high schema coverage, a baseline score of 3 is appropriate as the schema handles the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Simulate how a webpage looks for colorblind users.' It specifies the action (simulate) and resource (webpage appearance for colorblind users), making it easy to understand. However, it doesn't explicitly differentiate from its sibling tool 'check_accessibility,' which might also involve accessibility testing, though the focus here is specifically on colorblind simulation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling tool 'check_accessibility' or any other tools, nor does it specify prerequisites, contexts, or exclusions. Usage is implied from the purpose but lacks explicit direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/bilhasry-deriv/mcp-web-a11y'

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