Concept #91Mediumextended-ai-concepts

What is Playwright MCP?

#gen-ai#mcp

Answer

What is Playwright MCP?

Playwright MCP is an MCP server that gives AI models (like Claude) the ability to control a real web browser using Microsoft's Playwright automation library. It enables AI agents to browse websites, fill forms, click buttons, and extract content.

What It Enables

With Playwright MCP, Claude can:

  • Navigate to URLs
  • Click buttons and links
  • Fill in form fields
  • Take screenshots
  • Extract text from web pages
  • Run JavaScript in the browser
  • Automate end-to-end testing

Setup

bash
npm install -g @modelcontextprotocol/server-playwright
json
// ~/.claude.json
{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-playwright"]
    }
  }
}

Available Tools (exposed to Claude)

ToolDescription
text
playwright_navigate
Go to a URL
text
playwright_click
Click an element by selector
text
playwright_fill
Type text into an input field
text
playwright_screenshot
Capture current page as image
text
playwright_get_text
Extract text content from page
text
playwright_evaluate
Run JavaScript in browser
text
playwright_select
Select an option from dropdown

Example: Claude Using Playwright MCP

text
User: "Go to example.com and tell me what the main heading says"

Claude:
  1. Calls playwright_navigate({url: "https://example.com"})
  2. Calls playwright_get_text({selector: "h1"})
  3. Returns: "The heading says 'Example Domain'"
text
User: "Search for 'AI engineering' on DuckDuckGo and summarize the first 3 results"

Claude:
  1. playwright_navigate({url: "https://duckduckgo.com"})
  2. playwright_fill({selector: "input[name='q']", value: "AI engineering"})
  3. playwright_click({selector: "button[type='submit']"})
  4. playwright_get_text({selector: ".results"})
  5. Summarizes the extracted text

Use Cases

Use CaseDescription
Web scrapingExtract data from websites that block direct requests
E2E testingClaude writes and runs browser tests
Form automationFill and submit web forms
ResearchBrowse and summarize multiple pages
UI verificationCheck that pages render correctly
Web workflowsAutomate repetitive browser tasks

Security Note

Playwright MCP gives Claude full browser control — only enable it for trusted workflows. Configure with allowed domains if needed:

json
{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-playwright",
               "--allowed-origins", "https://yoursite.com"]
    }
  }
}

Playwright MCP vs Direct Playwright

Direct Playwright CodePlaywright MCP
ControlYou write automation codeClaude writes + executes
FlexibilityFull programming controlNatural language instructions
SpeedFaster for known tasksFaster for ad-hoc tasks
Best forKnown, repeatable workflowsExploratory, conversational automation