Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore(mcp): generate single mcp entry in the config (#37458)
Yury Semikhatskycb2d76ee8190
diff --git a/examples/todomvc/.claude/agents/playwright-test-generator.md b/examples/todomvc/.claude/agents/playwright-test-generator.mdindex 772dd180f8..a22b2d022f 100644--- a/examples/todomvc/.claude/agents/playwright-test-generator.md+++ b/examples/todomvc/.claude/agents/playwright-test-generator.md@@ -1,7 +1,7 @@---name: playwright-test-generatordescription: Use this agent when you need to create automated browser tests using Playwright. Examples: <example>Context: User wants to test a login flow on their web application. user: 'I need a test that logs into my app at localhost:3000 with username [email protected] and password 123456, then verifies the dashboard page loads' assistant: 'I'll use the playwright-test-generator agent to create and validate this login test for you' <commentary> The user needs a specific browser automation test created, which is exactly what the playwright-test-generator agent is designed for. </commentary></example><example>Context: User has built a new checkout flow and wants to ensure it works correctly. user: 'Can you create a test that adds items to cart, proceeds to checkout, fills in payment details, and confirms the order?' assistant: 'I'll use the playwright-test-generator agent to build a comprehensive checkout flow test' <commentary> This is a complex user journey that needs to be automated and tested, perfect for the playwright-test-generator agent. </commentary></example>-tools: Glob, Grep, Read, Write, mcp__playwright-0d2f__browser_click, mcp__playwright-0d2f__browser_drag, mcp__playwright-0d2f__browser_evaluate, mcp__playwright-0d2f__browser_file_upload, mcp__playwright-0d2f__browser_handle_dialog, mcp__playwright-0d2f__browser_hover, mcp__playwright-0d2f__browser_navigate, mcp__playwright-0d2f__browser_press_key, mcp__playwright-0d2f__browser_select_option, mcp__playwright-0d2f__browser_snapshot, mcp__playwright-0d2f__browser_type, mcp__playwright-0d2f__browser_verify_element_visible, mcp__playwright-0d2f__browser_verify_list_visible, mcp__playwright-0d2f__browser_verify_text_visible, mcp__playwright-0d2f__browser_verify_value, mcp__playwright-0d2f__browser_wait_for, mcp__playwright-0d2f__test_setup_page+tools: Glob, Grep, Read, Write, mcp__playwright-test__browser_click, mcp__playwright-test__browser_drag, mcp__playwright-test__browser_evaluate, mcp__playwright-test__browser_file_upload, mcp__playwright-test__browser_handle_dialog, mcp__playwright-test__browser_hover, mcp__playwright-test__browser_navigate, mcp__playwright-test__browser_press_key, mcp__playwright-test__browser_select_option, mcp__playwright-test__browser_snapshot, mcp__playwright-test__browser_type, mcp__playwright-test__browser_verify_element_visible, mcp__playwright-test__browser_verify_list_visible, mcp__playwright-test__browser_verify_text_visible, mcp__playwright-test__browser_verify_value, mcp__playwright-test__browser_wait_for, mcp__playwright-test__test_setup_pagemodel: sonnetcolor: blue---diff --git a/examples/todomvc/.claude/agents/playwright-test-planner.md b/examples/todomvc/.claude/agents/playwright-test-planner.mdindex 1f233162f5..0cd8fdaaff 100644--- a/examples/todomvc/.claude/agents/playwright-test-planner.md+++ b/examples/todomvc/.claude/agents/playwright-test-planner.md@@ -1,7 +1,7 @@---name: playwright-test-plannerdescription: Use this agent when you need to create comprehensive test plan for a web application or website. Examples: <example>Context: User wants to test a new e-commerce checkout flow. user: 'I need test scenarios for our new checkout process at https://mystore.com/checkout' assistant: 'I'll use the playwright-test-planner agent to navigate to your checkout page and create comprehensive test scenarios.' <commentary> The user needs test planning for a specific web page, so use the playwright-test-planner agent to explore and create test scenarios. </commentary></example><example>Context: User has deployed a new feature and wants thorough testing coverage. user: 'Can you help me test our new user dashboard at https://app.example.com/dashboard?' assistant: 'I'll launch the playwright-test-planner agent to explore your dashboard and develop detailed test scenarios.' <commentary> This requires web exploration and test scenario creation, perfect for the playwright-test-planner agent. </commentary></example>-tools: Glob, Grep, Read, Write, mcp__playwright-396e__browser_click, mcp__playwright-396e__browser_close, mcp__playwright-396e__browser_console_messages, mcp__playwright-396e__browser_drag, mcp__playwright-396e__browser_evaluate, mcp__playwright-396e__browser_file_upload, mcp__playwright-396e__browser_handle_dialog, mcp__playwright-396e__browser_hover, mcp__playwright-396e__browser_navigate, mcp__playwright-396e__browser_navigate_back, mcp__playwright-396e__browser_network_requests, mcp__playwright-396e__browser_press_key, mcp__playwright-396e__browser_select_option, mcp__playwright-396e__browser_snapshot, mcp__playwright-396e__browser_take_screenshot, mcp__playwright-396e__browser_type, mcp__playwright-396e__browser_wait_for, mcp__playwright-396e__test_setup_page+tools: Glob, Grep, Read, Write, mcp__playwright-test__browser_click, mcp__playwright-test__browser_close, mcp__playwright-test__browser_console_messages, mcp__playwright-test__browser_drag, mcp__playwright-test__browser_evaluate, mcp__playwright-test__browser_file_upload, mcp__playwright-test__browser_handle_dialog, mcp__playwright-test__browser_hover, mcp__playwright-test__browser_navigate, mcp__playwright-test__browser_navigate_back, mcp__playwright-test__browser_network_requests, mcp__playwright-test__browser_press_key, mcp__playwright-test__browser_select_option, mcp__playwright-test__browser_snapshot, mcp__playwright-test__browser_take_screenshot, mcp__playwright-test__browser_type, mcp__playwright-test__browser_wait_for, mcp__playwright-test__test_setup_pagemodel: sonnetcolor: green---@@ -10,7 +10,7 @@ You are an expert web test planner with extensive experience in quality assurancWhen given a target web page or application, you will:-1. **Navigate and Explore**:+1. **Navigate and Explore**:- Invoke the `test_setup_page` tool once to set up page before using any other tools- Explore the aria snapshot, use browser_* tools to navigate and discover interface.- Thoroughly explore the interface, identifying all interactive elements, forms, navigation paths, and functionalitydiff --git a/examples/todomvc/.mcp.json b/examples/todomvc/.mcp.jsonindex 3472f022fa..d9dfc1253b 100644--- a/examples/todomvc/.mcp.json+++ b/examples/todomvc/.mcp.json@@ -1,20 +1,6 @@{"mcpServers": {- "playwright-df91": {- "command": "npx",- "args": [- "playwright",- "run-test-mcp-server"- ]- },- "playwright-0d2f": {- "command": "npx",- "args": [- "playwright",- "run-test-mcp-server"- ]- },- "playwright-396e": {+ "playwright-test": {"command": "npx","args": ["playwright",diff --git a/examples/todomvc/prompt.claudecode.md b/examples/todomvc/prompt.claudecode.mdindex 99f51b7c47..3be701148c 100644--- a/examples/todomvc/prompt.claudecode.md+++ b/examples/todomvc/prompt.claudecode.md@@ -10,4 +10,4 @@ Test basic functionality of todo app.- For each scenario in `specs/test-plan.md`, use `playwright-test-generator`subagent to perform the scenario and generate the test source code into `tests/` folder.-- Use `playwright-test-fixer` subagent to fix the failing tests.+- Use `playwright-test-healer` subagent to fix the failing tests.diff --git a/packages/playwright/src/agents/generateAgents.ts b/packages/playwright/src/agents/generateAgents.tsindex 30dd5c9644..211aab6c57 100644--- a/packages/playwright/src/agents/generateAgents.ts+++ b/packages/playwright/src/agents/generateAgents.ts@@ -14,7 +14,6 @@* limitations under the License.*/-import crypto from 'crypto';import fs from 'fs';import path from 'path';import { yaml } from 'playwright-core/lib/utilsBundle';@@ -25,15 +24,8 @@ interface AgentHeader {model: string;color: string;tools: string[];- 'mcp-servers': Record<string, McpServerConfig>;}-interface McpServerConfig {- type: string;- command: string;- args: string[];- tools: string[];-}interface Agent {header: AgentHeader;@@ -111,21 +103,28 @@ const claudeToolMap = new Map<string, string[]>([['write', ['Write']],]);+// Common MCP server configurations+const commonMcpServers = {+ playwrightTest: {+ type: 'local',+ command: 'npx',+ args: ['playwright', 'run-test-mcp-server']+ }+};+function saveAsClaudeCode(agent: Agent): string {- function asClaudeTool(hash: string, tool: string): string {+ function asClaudeTool(tool: string): string {const [first, second] = tool.split('/');if (!second)return (claudeToolMap.get(first) || [first]).join(', ');- return `mcp__${first}-${hash}__${second}`;+ return `mcp__${first}__${second}`;}- const hash = shortHash(agent.header.name);-const lines: string[] = [];lines.push(`---`);lines.push(`name: ${agent.header.name}`);lines.push(`description: ${agent.header.description}. Examples: ${agent.examples.map(example => `<example>${example}</example>`).join('')}`);- lines.push(`tools: ${agent.header.tools.map(tool => asClaudeTool(hash, tool)).join(', ')}`);+ lines.push(`tools: ${agent.header.tools.map(tool => asClaudeTool(tool)).join(', ')}`);lines.push(`model: ${agent.header.model}`);lines.push(`color: ${agent.header.color}`);lines.push(`---`);@@ -143,13 +142,13 @@ const opencodeToolMap = new Map<string, string[]>([]);function saveAsOpencodeJson(agents: Agent[]): string {- function asOpencodeTool(tools: Record<string, boolean>, hash: string, tool: string): void {+ function asOpencodeTool(tools: Record<string, boolean>, tool: string): void {const [first, second] = tool.split('/');if (!second) {for (const tool of opencodeToolMap.get(first) || [first])tools[tool] = true;} else {- tools[`${first}-${hash}*${second}`] = true;+ tools[`${first}*${second}`] = true;}}@@ -161,7 +160,6 @@ function saveAsOpencodeJson(agents: Agent[]): string {};result['agent'] = {};for (const agent of agents) {- const hash = shortHash(agent.header.name);const tools: Record<string, boolean> = {};result['agent'][agent.header.name] = {description: agent.header.description,@@ -170,21 +168,17 @@ function saveAsOpencodeJson(agents: Agent[]): string {tools,};for (const tool of agent.header.tools)- asOpencodeTool(tools, hash, tool);-- for (const [name, mcp] of Object.entries(agent.header['mcp-servers'])) {- result['mcp'][name + '-' + hash] = {- type: mcp.type,- command: [mcp.command, ...mcp.args],- enabled: true,- };- }+ asOpencodeTool(tools, tool);}- return JSON.stringify(result, null, 2);-}-function shortHash(str: string): string {- return crypto.createHash('sha256').update(str).digest('hex').slice(0, 4);+ const server = commonMcpServers.playwrightTest;+ result['mcp']['playwright-test'] = {+ type: server.type,+ command: [server.command, ...server.args],+ enabled: true,+ };++ return JSON.stringify(result, null, 2);}async function loadAgents(): Promise<Agent[]> {@@ -205,18 +199,14 @@ export async function initClaudeCodeRepo() {for (const agent of agents)await writeFile(`.claude/agents/${agent.header.name}.md`, saveAsClaudeCode(agent));- const mcpServers: Record<string, { command: string; args: string[] }> = {};- for (const agent of agents) {- const hash = shortHash(agent.header.name);- for (const [name, mcp] of Object.entries(agent.header['mcp-servers'])) {- const entry = {- command: mcp.command,- args: mcp.args,- };- mcpServers[name + '-' + hash] = entry;+ await writeFile('.mcp.json', JSON.stringify({+ mcpServers: {+ 'playwright-test': {+ command: commonMcpServers.playwrightTest.command,+ args: commonMcpServers.playwrightTest.args,+ }}- }- await writeFile('.mcp.json', JSON.stringify({ mcpServers }, null, 2));+ }, null, 2));}const vscodeToolMap = new Map<string, string[]>([@@ -267,10 +257,10 @@ export async function initVSCodeRepo() {if (!mcpJson.servers)mcpJson.servers = {};- mcpJson.servers['playwright-test-mcp'] = {+ mcpJson.servers['playwright-test'] = {type: 'stdio',- command: 'npx',- args: ['playwright', 'run-test-mcp-server'],+ command: commonMcpServers.playwrightTest.command,+ args: commonMcpServers.playwrightTest.args,};await writeFile(mcpJsonPath, JSON.stringify(mcpJson, null, 2));}diff --git a/packages/playwright/src/agents/generator.md b/packages/playwright/src/agents/generator.mdindex c85e3c9ac6..f5abc27db5 100644--- a/packages/playwright/src/agents/generator.md+++ b/packages/playwright/src/agents/generator.md@@ -8,28 +8,23 @@ tools:- grep- read- write- - playwright/browser_click- - playwright/browser_drag- - playwright/browser_evaluate- - playwright/browser_file_upload- - playwright/browser_handle_dialog- - playwright/browser_hover- - playwright/browser_navigate- - playwright/browser_press_key- - playwright/browser_select_option- - playwright/browser_snapshot- - playwright/browser_type- - playwright/browser_verify_element_visible- - playwright/browser_verify_list_visible- - playwright/browser_verify_text_visible- - playwright/browser_verify_value- - playwright/browser_wait_for- - playwright/test_setup_page-mcp-servers:- playwright:- type: 'local'- command: 'npx'- args: ['playwright', 'run-test-mcp-server']+ - playwright-test/browser_click+ - playwright-test/browser_drag+ - playwright-test/browser_evaluate+ - playwright-test/browser_file_upload+ - playwright-test/browser_handle_dialog+ - playwright-test/browser_hover+ - playwright-test/browser_navigate+ - playwright-test/browser_press_key+ - playwright-test/browser_select_option+ - playwright-test/browser_snapshot+ - playwright-test/browser_type+ - playwright-test/browser_verify_element_visible+ - playwright-test/browser_verify_list_visible+ - playwright-test/browser_verify_text_visible+ - playwright-test/browser_verify_value+ - playwright-test/browser_wait_for+ - playwright-test/test_setup_page---You are a Playwright Test Generator, an expert in browser automation and end-to-end testing. Your specialty is creating robust, reliable Playwright tests that accurately simulate user interactions and validate application behavior.diff --git a/packages/playwright/src/agents/fixer.md b/packages/playwright/src/agents/healer.mdsimilarity index 80%rename from packages/playwright/src/agents/fixer.mdrename to packages/playwright/src/agents/healer.mdindex 4f159ea4b2..c2c826f68a 100644--- a/packages/playwright/src/agents/fixer.md+++ b/packages/playwright/src/agents/healer.md@@ -1,5 +1,5 @@----name: playwright-test-fixer+name: playwright-test-healerdescription: Use this agent when you need to debug and fix failing Playwright testscolor: redmodel: sonnet@@ -9,20 +9,15 @@ tools:- read- write- edit- - playwright/browser_evaluate- - playwright/browser_generate_locator- - playwright/browser_snapshot- - playwright/test_debug- - playwright/test_list- - playwright/test_run-mcp-servers:- playwright:- type: 'local'- command: 'npx'- args: ['playwright', 'run-test-mcp-server']+ - playwright-test/browser_evaluate+ - playwright-test/browser_generate_locator+ - playwright-test/browser_snapshot+ - playwright-test/test_debug+ - playwright-test/test_list+ - playwright-test/test_run----You are the Playwright Test Fixer, an expert test automation engineer specializing in debugging and+You are the Playwright Test Healer, an expert test automation engineer specializing in debugging andresolving Playwright test failures. Your mission is to systematically identify, diagnose, and fixbroken Playwright tests using a methodical approach.@@ -42,7 +37,7 @@ Your workflow:- Updating selectors to match current application state- Fixing assertions and expected values- Improving test reliability and maintainability- - For inherently dynamic data, utilize regular expressions to produce resilient locators+ - For inherently dynamic data, utilize regular expressions to produce resilient locators6. **Verification**: Restart the test after each fix to validate the changes7. **Iteration**: Repeat the investigation and fixing process until the test passes cleanly@@ -61,19 +56,19 @@ Key principles:<example>Context: A developer has a failing Playwright test that needs to be debugged and fixed.user: 'The login test is failing, can you fix it?'- assistant: 'I'll use the playwright-test-fixer agent to debug and fix the failing login test.'+ assistant: 'I'll use the playwright-test-healer agent to debug and fix the failing login test.'<commentary>The user has identified a specific failing test that needs debugging and fixing, which is exactly what the- playwright-test-fixer agent is designed for.+ playwright-test-healer agent is designed for.</commentary></example><example>Context: After running a test suite, several tests are reported as failing.user: 'Test user-registration.spec.ts is broken after the recent changes'- assistant: 'Let me use the playwright-test-fixer agent to investigate and fix the user-registration test.'+ assistant: 'Let me use the playwright-test-healer agent to investigate and fix the user-registration test.'<commentary>A specific test file is failing and needs debugging, which requires the systematic approach of the- playwright-test-fixer agent.+ playwright-test-healer agent.</commentary></example>diff --git a/packages/playwright/src/agents/planner.md b/packages/playwright/src/agents/planner.mdindex c6b94691f2..98ecb1cc8c 100644--- a/packages/playwright/src/agents/planner.md+++ b/packages/playwright/src/agents/planner.md@@ -8,36 +8,31 @@ tools:- grep- read- write- - playwright/browser_click- - playwright/browser_close- - playwright/browser_console_messages- - playwright/browser_drag- - playwright/browser_evaluate- - playwright/browser_file_upload- - playwright/browser_handle_dialog- - playwright/browser_hover- - playwright/browser_navigate- - playwright/browser_navigate_back- - playwright/browser_network_requests- - playwright/browser_press_key- - playwright/browser_select_option- - playwright/browser_snapshot- - playwright/browser_take_screenshot- - playwright/browser_type- - playwright/browser_wait_for- - playwright/test_setup_page-mcp-servers:- playwright:- type: 'local'- command: 'npx'- args: ['playwright', 'run-test-mcp-server']+ - playwright-test/browser_click+ - playwright-test/browser_close+ - playwright-test/browser_console_messages+ - playwright-test/browser_drag+ - playwright-test/browser_evaluate+ - playwright-test/browser_file_upload+ - playwright-test/browser_handle_dialog+ - playwright-test/browser_hover+ - playwright-test/browser_navigate+ - playwright-test/browser_navigate_back+ - playwright-test/browser_network_requests+ - playwright-test/browser_press_key+ - playwright-test/browser_select_option+ - playwright-test/browser_snapshot+ - playwright-test/browser_take_screenshot+ - playwright-test/browser_type+ - playwright-test/browser_wait_for+ - playwright-test/test_setup_page---You are an expert web test planner with extensive experience in quality assurance, user experience testing, and test scenario design. Your expertise includes functional testing, usability testing, edge case identification, and comprehensive test coverage planning.When given a target web page or application, you will:-1. **Navigate and Explore**:+1. **Navigate and Explore**:- Invoke the `test_setup_page` tool once to set up page before using any other tools- Explore the aria snapshot, use browser_* tools to navigate and discover interface.- Thoroughly explore the interface, identifying all interactive elements, forms, navigation paths, and functionality