Skip to main content
Glama
Playwright Smart MCP

Playwright Smart MCP

by jaystarz1

Playwright Smart MCP

A token-efficient Playwright MCP server that exposes 4 smart tools instead of 22, reducing context window usage by ~85%.

✨ New in v2.1

  • πŸ”§ Code Execution: New browser_execute_code tool for complex UI interactions

  • πŸ–₯️ Headed Mode: See the browser window, watch automation happen

  • πŸ’Ύ Session Persistence: Log in once, stay logged in across sessions

  • πŸ” Auto-Save: Cookies & login state saved automatically after every action

  • ⚑ Interactive Workflows: You log in, AI takes over

See FEATURES.md for full documentation on headed mode and session persistence.

Related MCP server: Cloudflare Playwright MCP

The Problem

The standard Playwright MCP server exposes 22 tools, each with full JSON schemas. This consumes ~5,000 tokens of your context window before you even do anything.

The Solution

This server consolidates all functionality into 4 high-level tools:

Tool

What It Does

Replaces

browser_screenshot

Navigate + capture screenshot

navigate, wait, screenshot

browser_extract

Navigate + get page content

navigate, snapshot, evaluate

browser_interact

Click, type, fill, scroll, etc.

15+ interaction tools

browser_execute_code

Execute JavaScript in browser

evaluate, complex DOM manipulation

Result: ~900 tokens instead of ~5,000 (82% reduction)

Installation

Option 1: Clone and Use Locally

git clone https://github.com/jaystarz1/playwright-smart-mcp.git
cd playwright-smart-mcp
npm install

Option 2: npx (coming soon)

npx playwright-smart-mcp

Configuration

Claude Code (Global - All Projects)

Add to ~/.claude/settings.json:

{
  "mcpServers": {
    "playwright-smart": {
      "type": "stdio",
      "command": "node",
      "args": ["/path/to/playwright-smart-mcp/server.js"]
    }
  }
}

Claude Code (Project-Specific)

Add to your project's .claude.json or via CLI:

claude mcp add playwright-smart node /path/to/playwright-smart-mcp/server.js

Claude Desktop

Add to your Claude Desktop config:

{
  "mcpServers": {
    "playwright-smart": {
      "command": "node",
      "args": ["/path/to/playwright-smart-mcp/server.js"]
    }
  }
}

Usage

browser_screenshot

Take a screenshot of any URL:

{
  "url": "https://example.com",
  "fullPage": true,
  "waitFor": ".main-content"
}

browser_extract

Get page content and links:

{
  "url": "https://example.com",
  "selector": ".article-body",
  "includeLinks": true
}

browser_interact

Execute a sequence of actions:

{
  "url": "https://example.com/login",
  "actions": [
    {"type": "fill", "selector": "#email", "value": "user@example.com"},
    {"type": "fill", "selector": "#password", "value": "secret"},
    {"type": "click", "selector": "button[type=submit]"},
    {"type": "wait", "selector": ".dashboard"}
  ],
  "returnScreenshot": true
}

Available action types:

  • click - Click an element

  • type - Type text (keystroke by keystroke)

  • fill - Fill a form field (faster than type)

  • select - Select dropdown option

  • wait - Wait for element or timeout

  • scroll - Scroll the page

  • press - Press a keyboard key (Enter, Tab, etc.)

browser_execute_code

Execute JavaScript in the browser context when standard interactions fail:

{
  "code": "document.querySelector('[placeholder*=\"Add people\"]').value = 'user@example.com'; return 'Email entered';"
}

Use cases:

  • Complex React/Vue components that don't respond to standard selectors

  • Dynamic UI elements that require custom event dispatching

  • DOM manipulation that's simpler with JavaScript than chained interactions

  • Extracting data in custom formats

Example: Sharing Google Drive folder

{
  "code": "const input = document.querySelector('[placeholder*=\"Add people\"]'); if (input) { input.value = 'user@example.com'; input.dispatchEvent(new Event('input', { bubbles: true })); return 'Email added'; } return 'Input not found';"
}

Example: Form Submission

Instead of 6+ tool calls with standard Playwright MCP:

browser_navigate β†’ form page
browser_type β†’ email field
browser_type β†’ password field
browser_click β†’ submit button
browser_wait_for β†’ success message
browser_screenshot β†’ capture result

Do it in one call:

{
  "tool": "browser_interact",
  "arguments": {
    "url": "https://example.com/signup",
    "actions": [
      {"type": "fill", "selector": "#email", "value": "user@example.com"},
      {"type": "fill", "selector": "#password", "value": "secret123"},
      {"type": "click", "selector": "button[type=submit]"},
      {"type": "wait", "selector": ".welcome-message"}
    ],
    "returnScreenshot": true
  }
}

Why This Approach?

Based on Anthropic's engineering blog post on code execution with MCP, which advocates for progressive disclosure of tool capabilities and code execution as an escape hatch.

"Models are great at navigating filesystems. Presenting tools as code on a filesystem allows models to read tool definitions on-demand, rather than reading them all up-front."

This server takes that principle and applies it to browser automation:

  • High-level tools (browser_interact) handle 95% of use cases

  • Code execution (browser_execute_code) handles the edge cases when selectors fail

  • Result: Scalpel approach vs sledgehammer - fewer tools, smarter usage

Token Comparison

Server

Tools

Est. Tokens

Use Case

Playwright MCP

22

~5,000

Full control needed

Playwright Smart

4

~900

Most automation tasks + edge cases

License

MIT

Contributing

PRs welcome! Ideas for improvement:

  • Add browser_pdf tool for PDF generation

  • Add browser_record for session recording

  • Support for multiple tabs/contexts

  • Pre-defined workflows (login, form submit, scrape)

Credits

Available Tools

4 tools
browser_execute_codeB

Execute JavaScript code in the current browser page context. Use this when standard interactions fail due to complex UI components.

Inputs: code (required).

browser_extractB

Navigate to a URL and extract page content. Returns text content and page structure.

Inputs: url (required), selector, includeLinks.

browser_interactC

Interact with a web page - navigate, click, type, fill forms, select options. Executes a sequence of actions.

Inputs: actions (required), url, returnContent, returnScreenshot.

browser_screenshotB

Navigate to a URL and take a screenshot. Returns the screenshot as base64.

Inputs: url (required), waitFor, fullPage.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 4 tools

    Disambiguation4/5

    Each tool targets a distinct function: capture (screenshot), read (extract), act (interact), and fall back to raw code (execute_code). The overlap between browser_interact and browser_execute_code is deliberate but could cause misselection since both can perform clicks/typing, with the latter described as a fallback. All tools start with navigation, so an agent must infer whether state persists across calls.

    Naming Consistency4/5

    All names use a consistent browser_ prefix and mostly verb or verb_noun forms (extract, interact, execute_code). browser_screenshot is a noun where the others are verbs, which is a minor deviation but still readable and predictable.

    Tool Count5/5

    Four tools is well-scoped for a browser automation server; each covers a distinct capability layer (visual, textual, interactive, programmatic) and none feels redundant or missing a sibling.

    Completeness3/5

    The surface lacks explicit tools for waiting/asserting, reading console or network logs, and inspecting the current page without re-navigating, which are common browser automation needs. browser_execute_code can work around some of these, but the lifecycle is somewhat thin.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Enables AI assistants to control a browser through a set of tools, allowing them to perform web automation tasks like navigation, typing, clicking, and taking screenshots.
      Apache 2.0
    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Enables AI assistants to control a browser through a set of tools, allowing them to perform web automation tasks like navigation, typing, clicking, and taking screenshots.
      Apache 2.0
    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Enables AI assistants to control a browser through a set of tools, allowing them to perform web automation tasks like navigation, typing, clicking, and taking screenshots.
      Apache 2.0
    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Enables AI assistants to control a browser through a set of tools, allowing them to perform web automation tasks like navigation, typing, clicking, and taking screenshots.
      Apache 2.0