Skip to main content
Glama
chenwei791129

Cloudflare Playwright MCP Worker

README.md
## Cloudflare Playwright MCP Worker

> Forked from [cloudflare/playwright-mcp](https://github.com/cloudflare/playwright-mcp) with added **API Key authentication** support via `X-API-Key` header.

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/chenwei791129/playwright-mcp-worker)

### Overview

This project demonstrates how to use [Playwright with Cloudflare Workers](https://github.com/cloudflare/playwright) as a Model Control Protocol (MCP) server using [Cloudflare Playwright MCP](https://github.com/chenwei791129/playwright-mcp-worker).

It 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.

The server can be used with various AI platforms including Claude Desktop, Claude Code, and GitHub Copilot in VS Code.

### Deploy

Follow these steps to set up and deploy the project:

1. Install dependencies:
```bash
npm ci
```

2. Deploy to Cloudflare Workers:

```bash
npx wrangler deploy
```

### Authentication (Optional)

You can protect your MCP server with an API key. Set the `API_KEY` secret using Wrangler:

```bash
npx wrangler secret put API_KEY
```

When `API_KEY` is set, all requests must include the `X-API-Key` header with the matching key. If `API_KEY` is not set, the server is open to all requests.

### Endpoints

This server exposes two transport types:

| Endpoint | Transport | Description |
|----------|-----------|-------------|
| `/sse` | Server-Sent Events (SSE) | Legacy streaming transport |
| `/mcp` | HTTP Streamable | Recommended modern transport |

### Use with Claude Desktop

As of now, [Claude Desktop](https://claude.ai/download) only supports local MCP servers. To use `playground-mcp` with Claude Desktop we make use of [mcp-remote](https://github.com/geelen/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:

**Using SSE transport:**

```json
{
  "mcpServers": {
    "cloudflare-playwright-mcp": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://[my-mcp-url].workers.dev/sse"
      ]
    }
  }
}
```

**Using HTTP Streamable transport:**

```json
{
  "mcpServers": {
    "cloudflare-playwright-mcp": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://[my-mcp-url].workers.dev/mcp"
      ]
    }
  }
}
```

**With API Key authentication**, add the `--header` flag:

```json
{
  "mcpServers": {
    "cloudflare-playwright-mcp": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://[my-mcp-url].workers.dev/mcp",
        "--header",
        "X-API-Key:${API_KEY}"
      ],
      "env": {
        "API_KEY": "<your-api-key>"
      }
    }
  }
}
```

3. 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](https://github.com/cloudflare/playwright-mcp/raw/main/docs/imgs/claudemcp.gif)

### Use with Claude Code

Add the MCP server using the `claude` CLI:

```bash
claude mcp add --scope user --transport http cloudflare-playwright https://[my-mcp-url].workers.dev/mcp
```

**With API Key authentication:**

```bash
claude mcp add --scope user --header "X-API-Key: ${API_KEY}" --transport http cloudflare-playwright https://[my-mcp-url].workers.dev/mcp
```

### Configure in VSCode

You can install the Playwright MCP server using the [VS Code CLI](https://code.visualstudio.com/docs/configure/command-line):

**Using SSE transport:**

```bash
# 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"}'
```

**Using HTTP Streamable transport:**

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

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

**With API Key authentication**, add the header to your `.vscode/mcp.json` or user settings:

```json
{
  "servers": {
    "cloudflare-playwright": {
      "type": "http",
      "url": "https://[my-mcp-url].workers.dev/mcp",
      "headers": {
        "X-API-Key": "<your-api-key>"
      }
    }
  }
}
```

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