MCPcopy Index your code
hub / github.com/cloudflare/playwright-mcp

github.com/cloudflare/playwright-mcp @v0.0.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.0.5 ↗ · + Follow
768 symbols 1,240 edges 74 files 42 documented · 5%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Cloudflare Playwright MCP

Deploy to Cloudflare

Overview

This project leverages Playwright for automated browser testing and integrates with Cloudflare Workers, Browser Rendering and @cloudflare/playwright for deployment.

Build and Deploy

Follow these steps to set up and deploy the project:

  1. Install dependencies:
npm ci
  1. Build:
cd cloudflare
npm run build
  1. Deploy to Cloudflare Workers:
cd cloudflare/example
npx wrangler deploy

Use with Cloudflare AI Playground

alt text

Cloudflare playground AI is a great way to test MCP servers using LLM models available in Workers AI.

  • Navigate to https://playground.ai.cloudflare.com/
  • Ensure model is set to llama-3.3-70b-instruct-fp8-fast
  • In MCP Servers, set URL to https://[my-mcp-url].workers.dev/sse
  • Click Connect
  • Status should update to Connected and it should list 14 available tools

You can now start to interact with the model, and it will run necessary tools to accomplish what was requested.

[!TIP] For best results, give simple instructions consisting of one single action, e. g., "Create a new todo entry", "Go to cloudflare site", "Take a screenshot"

Example of a conversation:

Role Message
User Go to demo.playwright.dev/todomvc
Assistant runs browser_navigate tool

The page has been navigated to https://demo.playwright.dev/todomvc/. The page title is "React • TodoMVC". The page snapshot shows the content of the page, including a heading, a textbox, and several links. | | User | Create some todo entry | | Assistant | runs browser_type tool

A new todo entry "Buy groceries" has been created. The page snapshot shows the updated content of the page, including the new todo entry. | | User | Nice. Now create a todo in parrot style | | Assistant | runs browser_type tool

A new todo entry "Polly wants a cracker" has been created in parrot style. The page snapshot shows the updated content of the page, including the new todo entry. | | User | And create another todo in yoda style | | Assistant | runs browser_type tool

A new todo entry "A walk, I must take" has been created in Yoda style. The page snapshot shows the updated content of the page, including the new todo entry. | | User | Take a screenshot | | Assistant | runs browser_take_screenshot tool

alt text A screenshot of the current page has been taken. The screenshot is in PNG format and is 56KB in size. | | User | Now click the checkbox of the parrot todo entry | | Assistant | runs browser_clickt tool

The checkbox of the parrot todo entry "Polly wants a cracker" has been clicked. The page snapshot shows the updated content of the page, with the checkbox now checked. | | User | Take a screenshot | | Assistant | runs browser_take_screenshot tool

alt text A screenshot of the current page has been taken. The screenshot is in PNG format and is 58KB in size. | | User | Remove completed todo entries | | Assistant | runs browser_clickt tool

The "Clear completed" button has been clicked. The page snapshot shows the updated content of the page, with the completed todo entry "Polly wants a cracker" removed. | | User | Take a final screenshot | | Assistant | runs browser_take_screenshot tool

alt text A final screenshot of the current page has been taken. The screenshot is in PNG format and is 50KB in size. |

Use with Claude Desktop

As of now, Claude Desktop only supports local MCP servers. To use playground-mcp with Claude Desktop we make use of mcp-remote, a tool that proxies remote MCP servers and exposes them locally. Use the following configuration:

  1. Open the configuration file for Claude Desktop.
  2. Add the following JSON snippet under the mcpServers section:
{
  "mcpServers": {
    "cloudflare-playwright-mcp": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://[my-mcp-url].workers.dev/sse"
      ]
    }
  }
}
  1. Save the configuration file and restart Claude Desktop to apply the changes.

This setup ensures that Claude Desktop can communicate with the Cloudflare Playwright MCP server.

Here's an example of a session opening the TODO demo app, adding "buy lemons" and doing a screenshot, taking advantage of playwright-mcp tools and Browser Rendering:

alt text

Configure in VSCode

You can install the Playwright MCP server using the VS Code CLI:

# For VS Code
code --add-mcp '{"name":"cloudflare-playwright","type":"sse","url":"https://[my-mcp-url].workers.dev/sse"}'
# For VS Code Insiders
code-insiders --add-mcp '{"name":"cloudflare-playwright","type":"sse","url":"https://[my-mcp-url].workers.dev/sse"}'

After installation, the Playwright MCP server will be available for use with your GitHub Copilot agent in VS Code.

Tool Modes

The tools are available in two modes:

  1. Snapshot Mode (default): Uses accessibility snapshots for better performance and reliability
  2. Vision Mode: Uses screenshots for visual-based interactions

Vision Mode works best with the computer use models that are able to interact with elements using X Y coordinate space, based on the provided screenshot.

Interactions

  • browser_snapshot
  • Title: Page snapshot
  • Description: Capture accessibility snapshot of the current page, this is better than screenshot
  • Parameters: None
  • Read-only: true

  • browser_click

  • Title: Click
  • Description: Perform click on a web page
  • Parameters:
    • element (string): Human-readable element description used to obtain permission to interact with the element
    • ref (string): Exact target element reference from the page snapshot
    • doubleClick (boolean, optional): Whether to perform a double click instead of a single click
  • Read-only: false

  • browser_drag

  • Title: Drag mouse
  • Description: Perform drag and drop between two elements
  • Parameters:
    • startElement (string): Human-readable source element description used to obtain the permission to interact with the element
    • startRef (string): Exact source element reference from the page snapshot
    • endElement (string): Human-readable target element description used to obtain the permission to interact with the element
    • endRef (string): Exact target element reference from the page snapshot
  • Read-only: false

  • browser_hover

  • Title: Hover mouse
  • Description: Hover over element on page
  • Parameters:
    • element (string): Human-readable element description used to obtain permission to interact with the element
    • ref (string): Exact target element reference from the page snapshot
  • Read-only: true

  • browser_type

  • Title: Type text
  • Description: Type text into editable element
  • Parameters:
    • element (string): Human-readable element description used to obtain permission to interact with the element
    • ref (string): Exact target element reference from the page snapshot
    • text (string): Text to type into the element
    • submit (boolean, optional): Whether to submit entered text (press Enter after)
    • slowly (boolean, optional): Whether to type one character at a time. Useful for triggering key handlers in the page. By default entire text is filled in at once.
  • Read-only: false

  • browser_select_option

  • Title: Select option
  • Description: Select an option in a dropdown
  • Parameters:
    • element (string): Human-readable element description used to obtain permission to interact with the element
    • ref (string): Exact target element reference from the page snapshot
    • values (array): Array of values to select in the dropdown. This can be a single value or multiple values.
  • Read-only: false

  • browser_press_key

  • Title: Press a key
  • Description: Press a key on the keyboard
  • Parameters:
    • key (string): Name of the key to press or a character to generate, such as ArrowLeft or a
  • Read-only: false

  • browser_wait_for

  • Title: Wait for
  • Description: Wait for text to appear or disappear or a specified time to pass
  • Parameters:
    • time (number, optional): The time to wait in seconds
    • text (string, optional): The text to wait for
    • textGone (string, optional): The text to wait for to disappear
  • Read-only: true

  • browser_file_upload

  • Title: Upload files
  • Description: Upload one or multiple files
  • Parameters:
    • paths (array): The absolute paths to the files to upload. Can be a single file or multiple files.
  • Read-only: false

  • browser_handle_dialog

  • Title: Handle a dialog
  • Description: Handle a dialog
  • Parameters:
    • accept (boolean): Whether to accept the dialog.
    • promptText (string, optional): The text of the prompt in case of a prompt dialog.
  • Read-only: false

Navigation

  • browser_navigate
  • Title: Navigate to a URL
  • Description: Navigate to a URL
  • Parameters:
    • url (string): The URL to navigate to
  • Read-only: false

  • browser_navigate_back

  • Title: Go back
  • Description: Go back to the previous page
  • Parameters: None
  • Read-only: true

  • browser_navigate_forward

  • Title: Go forward
  • Description: Go forward to the next page
  • Parameters: None
  • Read-only: true

Resources

  • browser_take_screenshot
  • Title: Take a screenshot
  • Description: Take a screenshot of the current page. You can't perform actions based on the screenshot, use browser_snapshot for actions.
  • Parameters:
    • raw (boolean, optional): Whether to return without compression (in PNG format). Default is false, which returns a JPEG image.
    • filename (string, optional): File name to save the screenshot to. Defaults to page-{timestamp}.{png|jpeg} if not specified.
    • element (string, optional): Human-readable element description used to obtain permission to screenshot the element. If not provided, the screenshot will be taken of viewport. If element is provided, ref must be provided too.
    • ref (string, optional): Exact target element reference from the page snapshot. If not provided, the screenshot will be taken of viewport. If ref is provided, element must be provided too.
  • Read-only: true

  • browser_pdf_save

  • Title: Save as PDF
  • Description: Save page as PDF
  • Parameters:
    • filename (string, optional): File name to save the pdf to. Defaults to page-{timestamp}.pdf if not specified.
  • Read-only: true

  • browser_network_requests

  • Title: List network requests
  • Description: Returns all network requests since loading the page
  • Parameters: None
  • Read-only: true

  • browser_console_messages

  • Title: Get console messages
  • Description: Returns all console messages
  • Parameters: None
  • Read-only: true

Utilities

  • browser_install
  • Title: Install the browser specified in the config
  • Description: Install the browser specified in the config. Call this if you get an error about the browser not being installed.
  • Parameters: None
  • Read-only: false

  • browser_close

  • Title: Close browser
  • Description: Close the page
  • Parameters: None
  • Read-only: true

  • browser_resize

  • Title: Resize browser window
  • Description: Resize the browser window
  • Parameters:
    • width (number): Width of the browser window
    • height (number): Height of the browser window
  • Read-only: true

Tabs

  • browser_tab_list
  • Title: List tabs
  • Description: List browser tabs
  • Parameters: None
  • Read-only: true

<!-- NOTE: This has been gener

Extension points exported contracts — how you extend this code

BrowserContextFactory (Interface)
(no doc) [6 implementers]
src/browserContextFactory.ts
ServiceWorkerGlobalScope (Interface)
* This ServiceWorker API interface represents the global execution context of a service worker. * Available only in sec
cloudflare/example/worker-configuration.d.ts
Performance (Interface)
* The Workers runtime supports a subset of the Performance API, used to measure timing and performance, * as well as tim
cloudflare/example/worker-configuration.d.ts
Response (Interface)
* This Fetch API interface represents the response to a request. * * [MDN Reference](https://developer.mozilla.org/doc
cloudflare/example/worker-configuration.d.ts
Request (Interface)
* This Fetch API interface represents a resource request. * * [MDN Reference](https://developer.mozilla.org/docs/Web/A
cloudflare/example/worker-configuration.d.ts
ReadableStream (Interface)
* This Streams API interface represents a readable stream of byte data. The Fetch API offers a concrete instance of a Re
cloudflare/example/worker-configuration.d.ts

Core symbols most depended-on inside this repo

setContent
called by 33
tests/testserver/index.ts
defineTool
called by 30
src/tools/tool.ts
close
called by 30
cloudflare/example/worker-configuration.d.ts
end
called by 23
cloudflare/example/worker-configuration.d.ts
currentTabOrDie
called by 19
src/context.ts
connect
called by 15
cloudflare/example/worker-configuration.d.ts
toString
called by 13
cloudflare/example/worker-configuration.d.ts
pickDefined
called by 12
src/config.ts

Shape

Method 311
Interface 264
Class 119
Function 74

Languages

TypeScript100%

Modules by API surface

cloudflare/example/worker-configuration.d.ts534 symbols
src/browserContextFactory.ts41 symbols
src/context.ts27 symbols
src/manualPromise.ts19 symbols
src/httpServer.ts17 symbols
tests/testserver/index.ts14 symbols
src/browserServer.ts14 symbols
src/tab.ts13 symbols
src/tools/utils.ts11 symbols
src/pageSnapshot.ts7 symbols
src/config.ts7 symbols
src/transport.ts6 symbols

For agents

$ claude mcp add playwright-mcp \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact