UI Test Gen MCP Server
Generates Playwright visual testing scripts from CSV data with advanced configuration management and environment switching capabilities.
README
UI Test Gen MCP Server
A Model Context Protocol (MCP) server that generates Playwright visual testing scripts from CSV data with advanced configuration management, environment switching capabilities, and organized code structure.
๐ Overview
This MCP server provides automated generation of Playwright visual testing scripts, helping developers quickly create comprehensive UI test suites from CSV test specifications. It includes automatic Playwright configuration validation, organized folder structure creation, intelligent code generation following best practices, and environment switching capabilities for multi-environment testing.
๐ฆ Installation
Option 1: Install from npm (Recommended)
# Install globally for system-wide access
npm install -g ui-test-gen-mcp
# Or install locally in your project
npm install ui-test-gen-mcp
Option 2: Install from source
# Clone the repository
git clone <repository-url>
cd ui-test-gen-mcp
# Install dependencies
npm install
# Build the TypeScript code
npm run build
๐๏ธ Project Structure
ui-test-gen-mcp/
โโโ main.ts # MCP server entry point
โโโ tools/
โ โโโ index.ts # Tool exports
โ โโโ visual-test-generator.ts # Main test generation tool
โ โโโ tool-lister.ts # Tool listing utility
โโโ helper/
โ โโโ index.ts # Helper function exports
โ โโโ template.ts # Test templates and tag definitions
โ โโโ test-tags.ts # Tag utility functions
โ โโโ env-config.ts # Environment configuration helpers
โ โโโ test-data.ts # Test data management
โ โโโ register.ts # Tool registration helper
โโโ data/
โ โโโ core-test-script.content.txt # Test script template
โ โโโ template-usage-guide.md # Template usage documentation
โโโ dist/ # Compiled JavaScript output
๐ ๏ธ Available Tools
1. Visual Test Generator (create_playwright_visual_tests)
Purpose: Generate comprehensive Playwright visual testing scripts from CSV data
Features:
- Automatic Playwright Config Validation: Checks and updates
playwright.config.tsfor propersnapshotDirconfiguration - Organized Folder Structure: Creates
./tests/ui/,./utils/ui/,./data/ui/, and./pages/ui/directories - CSV-Based Test Generation: Processes CSV data to create test files following a strict template
- Environment Switching: NEW - Single test file handles multiple environments (prep, int, qa, prod, etc.)
- Smart Code Organization: Extracts utilities and organizes code during refactoring phase
- Project Style Integration: Analyzes existing code to match project's coding conventions
- Improved Tag System: NEW - Pre-calculated tag constants instead of function calls
Input Schema:
{
csvData: string // CSV content with test information
}
Required CSV Columns:
file_name: Name for the generated test filetest_url: URL to testtest_description: Description of what to testtest_selector: CSS selector for the elementtest_hide: Elements to hide during testing (component-specific)test_action: Action to perform (optional)test_env: NEW - Environment name (prep, int, qa, prod, staging, etc.)
2. Tool Lister (list_tools)
Purpose: Display all available tools with simple descriptions
Usage: Call this tool to see what's available in the MCP server
๐ง Key Features
Playwright Configuration Management
- Automatically validates
playwright.config.tsfiles - Ensures
snapshotDiris set to"./__screenshots__" - Updates configuration if missing or incorrect (only modifies snapshotDir)
Environment Switching Capabilities ๐
- Single Test File: One test file per component handles all environments
- Dynamic Environment Config: Environment configuration generated from CSV data
- User-Controlled Switching: Users manually configure environment selection
- Flexible Environment Support: Supports any environment name (prep, int, qa, prod, staging, etc.)
Improved Screenshot Path Structure ๐
- Clean Paths:
__screenshots__/fileName/fileName.pngformat - No Environment Nesting: Simple, clean structure without unnecessary directories
- Consistent Naming: Predictable and maintainable screenshot organization
Enhanced Tag System ๐
- Pre-calculated Constants: Uses
fullPageTagsandsectionTagsconstants - No Function Calls: Eliminates
getTagsForSelector()function calls - Proper Playwright Syntax: Implements tags using
test('Name', { tag: tags }, async ({ page }) => {}) - Automatic Tag Selection: Body selector gets
fullPageTags, others getsectionTags
Organized Project Structure
./tests/ui/- Generated test files (single file per component)./utils/ui/- Utility functions organized by type:selectors.ts- Reusable selectors and constantshelpers.ts- Common helper functionstest-actions.ts- Generated test action functionspage-objects.ts- Page object model patternsvalidation.ts- Validation and error handlingenv-config.ts- NEW Environment configuration utilitiestest-tags.ts- NEW Tag management utilities
./data/ui/- Test data and configuration./pages/ui/- Page object classes and locators
Intelligent Code Generation
- Follows the embedded core test script template strictly
- Generates proper test action functions following Playwright best practices
- Preserves component-specific test_hide selectors
- Maintains separation between test files and utility/data files
Template Compliance
The server uses a mandatory core test script template that ensures consistency:
- Standard Playwright test structure
- Proper screenshot handling with
toMatchSnapshot - Element hiding for clean visual testing
- Scroll handling for element visibility
- Proper tag implementation
๐ Workflow
Phase 1: Configuration Validation
- Locate
playwright.config.tsfiles in the project - Verify
snapshotDiris set to"./__screenshots__" - Update configuration if necessary
Phase 2: Test File Generation
- Parse CSV data for test specifications
- Detect environment column and use appropriate template
- Create single test file per component in
./tests/ui/folder - Apply the core test script template with environment switching
- Replace template variables with CSV data
Phase 3: Project Structure Creation
- Create organized folder structure
- Generate utility files in appropriate locations
- Create data and page object files
- Generate environment configuration files
Phase 4: Code Refactoring
- Extract common utilities to grouped files
- Organize code for maintainability
- Follow project's existing coding style
- Ensure proper separation of concerns
- Implement proper tag system
๐ Setup & Usage
Prerequisites
- Node.js (v18 or higher)
- npm or yarn
- Playwright installed in your project
Quick Start
-
Install the package:
npm install ui-test-gen-mcp -
Configure your MCP client (e.g., Cursor, VS Code with MCP extension):
{ "mcpServers": { "ui-test-gen-mcp": { "command": "npx", "args": ["-y", "ui-test-gen-mcp"] } } } -
Alternative configuration (if using local installation):
{ "mcpServers": { "ui-test-gen-mcp": { "command": "node", "args": ["./node_modules/ui-test-gen-mcp/dist/main.js"] } } } -
Restart your MCP client to load the new server
Development Setup
If you're developing or want to run from source:
# Start development mode with auto-reload
npm run dev
# Build for production
npm run build
# Start the built server
npm start
๐ MCP Configuration Examples
For Cursor IDE
Add to your Cursor settings:
{
"mcpServers": {
"ui-test-gen-mcp": {
"command": "npx",
"args": ["-y", "ui-test-gen-mcp"]
}
}
}
For VS Code with MCP Extension
Add to your VS Code settings:
{
"mcp.servers": {
"ui-test-gen-mcp": {
"command": "npx",
"args": ["ui-test-gen-mcp"]
}
}
}
For Other MCP Clients
{
"mcpServers": {
"ui-test-gen-mcp": {
"command": "npx",
"args": ["-y", "ui-test-gen-mcp"]
}
}
}
๐งช Testing
Test the MCP connection:
# If installed globally
ui-test-gen-mcp
# If installed locally
npx ui-test-gen-mcp
# If running from source
node test-connection.js
๐ CSV Format Example
Basic Format
file_name,test_url,test_description,test_selector,test_hide,test_action
homepage,https://example.com,Homepage hero section,.hero-section,.ad-banner,click
product,https://example.com/product,Product image,.product-image,.cookie-banner,screenshot
NEW - With Environment Support
file_name,test_url,test_description,test_selector,test_hide,test_action,test_env
pdp,https://prep.example.com/product,PDP Full Page,body,.banner,.modal,prep
pdp,https://int.example.com/product,PDP Full Page,body,.banner,.modal,int
pdp,https://qa.example.com/product,PDP Full Page,body,.banner,.modal,qa
๐ก Usage Examples
Basic Usage
Once configured, you can use the MCP server to:
-
Generate tests from CSV data:
- Call
create_playwright_visual_testswith your CSV content - The server will automatically create test files and folder structure
- Call
-
List available tools:
- Call
list_toolsto see what's available
- Call
Example CSV Input
file_name,test_url,test_description,test_selector,test_hide,test_action,test_env
landing,https://myapp.com,Landing page header,.header-section,.notification-banner,screenshot,prep
dashboard,https://myapp.com/dashboard,Dashboard sidebar,.sidebar-nav,.ads-container,click,int
Generated Output
The server will create:
./tests/ui/landing.spec.ts- Single test file for landing page (handles all environments)./tests/ui/dashboard.spec.ts- Single test file for dashboard (handles all environments)./utils/ui/- Organized utility files including environment config./data/ui/- Test data files./pages/ui/- Page object classes
NEW - Environment Switching Example
// Generated test file with environment switching
test.describe('Landing - Visual testing', () => {
test('Landing page header', {
tag: sectionTags // Pre-calculated constant, no function call
}, async ({ page }) => {
const testData = landingTestData.find(t =>
t.test_description === 'Landing page header' &&
t.test_env === getCurrentEnv()
);
if (!testData) throw new Error('Test data not found');
await page.goto(testData.test_url);
// Hide elements specific to this component
await hideElements(page, testData.test_hide);
const locator = page.locator(testData.test_selector);
await locator.scrollIntoViewIfNeeded();
// Clean screenshot path structure
const fileName = generateFileName(testData.test_description);
expect(await locator.screenshot()).toMatchSnapshot(`${fileName}/${fileName}.png`);
});
});
โ ๏ธ Important Notes
Template Compliance
- The core test script template is mandatory and non-negotiable
- Never deviate from the template structure
- Always use exact import statements and test patterns
Environment Switching ๐
- Single Test File: One test file per component handles all environments
- User Control: Users manually configure environment selection
- No Automatic Switching:
switchEnvironment()calls are not automatically generated - Flexible Implementation: Users implement
getCurrentEnv()based on their configuration
Tag System ๐
- No Function Calls: Tags use pre-calculated constants (
fullPageTags,sectionTags) - Proper Syntax: Implements Playwright tag syntax correctly
- Automatic Selection: Body selector gets
fullPageTags, others getsectionTags
Component Safety
- Each CSV component maintains its own
test_hideselectors - No cross-component selector sharing
- Preserve component-specific configurations during refactoring
File Organization
- Test files must be created in
./tests/ui/folder - Utilities must be organized in appropriate grouped files
- Data files and page objects must be separate from
.spec.tsfiles
๐ฏ Benefits
- Rapid Test Creation: Generate comprehensive test suites from CSV data
- Consistent Structure: Enforced template compliance ensures consistency
- Professional Organization: Industry-standard folder structure
- Automatic Configuration: Playwright config validation and updates
- Maintainable Code: Clean, organized, and well-structured test files
- Project Integration: Follows existing project coding styles and conventions
- Easy Installation: Available as npm package for quick setup
- Environment Support: NEW - Single test file handles multiple environments
- Clean Screenshots: NEW - Simple, organized screenshot paths
- Proper Tags: NEW - No function calls, uses pre-calculated constants
๐ Troubleshooting
Common Issues
- MCP Connection Failed: Ensure the server is installed and configured correctly
- Template Errors: Verify CSV data follows required format
- Configuration Issues: Check that
playwright.config.tsexists and is editable - Folder Creation Errors: Ensure write permissions in the project directory
- Environment Issues: NEW - Verify
test_envcolumn is present in CSV for environment switching
Debug Steps
- Verify installation:
npm list ui-test-gen-mcp - Test MCP connection:
npx ui-test-gen-mcp - Check console logs for error messages
- Verify CSV data format and content
- Ensure project structure is properly set up
- Check for environment column in CSV data
๐ Additional Resources
- Model Context Protocol Documentation
- Playwright Testing Framework
- TypeScript Documentation
- npm Package Page
๐ค Contributing
Contributions are welcome! Please ensure:
- Code follows existing patterns and style
- Tests are updated for new features
- Documentation is kept current
๐ License
ISC License - see package.json for details
Note: This MCP server is designed for generating Playwright visual testing scripts with environment switching capabilities. Ensure you have Playwright properly configured in your project before using the generated tests.
Package: Available on npm as ui-test-gen-mcp
Recent Updates:
- โ Environment switching capabilities
- โ Improved screenshot path structure
- โ Enhanced tag system (no function calls)
- โ Single test file per component
- โ User-controlled environment configuration
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.