|

Building Custom MCP Servers for Test Automation: Connect AI to Your Test Infrastructure

MCP lets AI agents interact with external tools via standardized protocol. Build custom servers connecting agents to Playwright, databases, CI/CD.

🤖 Learning AI-powered testing? Go hands-on with LLM, RAG, and AI-agent testing in the AI-Powered Testing Mastery course at The Testing Academy.

Contents

Architecture

AI Agent (Claude/GPT)
    |
    v
MCP Client
    |
    v
Your MCP Server
    +---> Playwright (run tests)
    +---> Database (query state)
    +---> CI/CD (trigger pipeline)
    +---> Jira (file bugs)

Playwright MCP Server

import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';

const server = new Server({ name: 'playwright-qa', version: '1.0.0' }, {
  capabilities: { tools: {} }
});

server.setRequestHandler('tools/list', async () => ({
  tools: [
    {
      name: 'run_test',
      description: 'Run a Playwright test file',
      inputSchema: {
        type: 'object',
        properties: {
          testFile: { type: 'string' },
          headed: { type: 'boolean' }
        },
        required: ['testFile']
      }
    },
    {
      name: 'get_results',
      description: 'Get last test run results',
      inputSchema: { type: 'object', properties: {} }
    },
    {
      name: 'analyze_failure',
      description: 'Analyze why a test failed using trace',
      inputSchema: {
        type: 'object',
        properties: { testName: { type: 'string' } },
        required: ['testName']
      }
    }
  ]
}));

server.setRequestHandler('tools/call', async (request) => {
  const { name, arguments: args } = request.params;
  if (name === 'run_test') {
    const { execSync } = require('child_process');
    try {
      const out = execSync('npx playwright test ' + args.testFile, { encoding: 'utf-8' });
      return { content: [{ type: 'text', text: 'Passed:\n' + out }] };
    } catch (e) {
      return { content: [{ type: 'text', text: 'Failed:\n' + e.stdout }] };
    }
  }
  if (name === 'get_results') {
    const fs = require('fs');
    const r = JSON.parse(fs.readFileSync('test-results/results.json', 'utf-8'));
    return { content: [{ type: 'text', text: JSON.stringify(r, null, 2) }] };
  }
});

const transport = new StdioServerTransport();
await server.connect(transport);

🚀 Build Real AI Testing Skills

Stop testing AI by guesswork. Learn DeepEval, RAG evaluation, and agent testing with guided projects.

MCP Config

{
  "mcpServers": {
    "playwright-qa": {
      "command": "npx",
      "args": ["tsx", "mcp-servers/playwright-qa.ts"]
    }
  }
}

QA MCP Server Catalog

ServerToolsAgent Can
Playwrightrun_test, get_results, analyzeRun tests, debug failures
Databasequery, seed, cleanupCheck state, create fixtures
Jiracreate_bug, update, searchAuto-file bugs from failures
CI/CDtrigger, get_statusRun pipelines, check results
Allureget_report, trendsAnalyze test health

🎓 Become an AI-Powered QA Engineer

Join hundreds of SDETs mastering LLM, RAG, and agent testing. Lifetime access, hands-on labs, and a job-ready portfolio.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.