@szymonrybczak/patchright-mcp-template 0.0.1-next

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ ## Cloudflare Playwright MCP Example
2
+
3
+ [![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/playwright-mcp/tree/main/cloudflare/example)
4
+
5
+ ### Overview
6
+
7
+ 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/cloudflare/playwright-mcp).
8
+
9
+ 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.
10
+
11
+ The server can be used with various AI platforms including Cloudflare AI Playground, Claude Desktop, and GitHub Copilot in VS Code.
12
+
13
+ ### Deploy
14
+
15
+ Follow these steps to set up and deploy the project:
16
+
17
+ 1. Install dependencies:
18
+ ```bash
19
+ npm ci
20
+ ```
21
+
22
+ 2. Deploy to Cloudflare Workers:
23
+
24
+ ```bash
25
+ npx wrangler deploy
26
+ ```
27
+
28
+ ### Use with Cloudflare AI Playground
29
+
30
+ ![alt text](https://github.com/cloudflare/playwright-mcp/raw/main/docs/imgs/playground-ai-screenshot.png)
31
+
32
+ [Cloudflare playground AI](https://playground.ai.cloudflare.com/) is a great way to test MCP servers using LLM models available in Workers AI.
33
+
34
+ - Navigate to https://playground.ai.cloudflare.com/
35
+ - Ensure model is set to `llama-3.3-70b-instruct-fp8-fast`
36
+ - In **MCP Servers**, set **URL** to `https://[my-mcp-url].workers.dev/sse`
37
+ - Click **Connect**
38
+ - Status should update to **Connected** and it should list 14 available tools
39
+
40
+ You can now start to interact with the model, and it will run necessary tools to accomplish what was requested.
41
+
42
+ > [!TIP]
43
+ > 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"
44
+
45
+ Example of a conversation:
46
+
47
+ | Role | Message |
48
+ |------|---------|
49
+ | **User** | Go to demo.playwright.dev/todomvc |
50
+ | **Assistant** | *runs browser_navigate tool*<br> 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. |
51
+ | **User** | Create some todo entry |
52
+ | **Assistant** | *runs browser_type tool*<br> A new todo entry "Buy groceries" has been created. The page snapshot shows the updated content of the page, including the new todo entry. |
53
+ | **User** | Nice. Now create a todo in parrot style |
54
+ | **Assistant** | *runs browser_type tool*<br> 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. |
55
+ | **User** | And create another todo in yoda style |
56
+ | **Assistant** | *runs browser_type tool*<br> 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. |
57
+ | **User** | Take a screenshot |
58
+ | **Assistant** | *runs browser_take_screenshot tool*<br> ![alt text](https://github.com/cloudflare/playwright-mcp/raw/main/docs/imgs/todomvc-screenshot-1.png) A screenshot of the current page has been taken. The screenshot is in PNG format and is 56KB in size. |
59
+ | **User** | Now click the checkbox of the parrot todo entry |
60
+ | **Assistant** | *runs browser_clickt tool*<br> 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. |
61
+ | **User** | Take a screenshot |
62
+ | **Assistant** | *runs browser_take_screenshot tool*<br> ![alt text](https://github.com/cloudflare/playwright-mcp/raw/main/docs/imgs/todomvc-screenshot-2.png) A screenshot of the current page has been taken. The screenshot is in PNG format and is 58KB in size. |
63
+ | **User** | Remove completed todo entries |
64
+ | **Assistant** | *runs browser_clickt tool*<br> 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. |
65
+ | **User** | Take a final screenshot |
66
+ | **Assistant** | *runs browser_take_screenshot tool*<br> ![alt text](https://github.com/cloudflare/playwright-mcp/raw/main/docs/imgs/todomvc-screenshot-3.png) A final screenshot of the current page has been taken. The screenshot is in PNG format and is 50KB in size. |
67
+
68
+ ### Use with Claude Desktop
69
+
70
+ 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:
71
+
72
+ 1. Open the configuration file for Claude Desktop.
73
+ 2. Add the following JSON snippet under the `mcpServers` section:
74
+
75
+ ```json
76
+ {
77
+ "mcpServers": {
78
+ "cloudflare-playwright-mcp": {
79
+ "command": "npx",
80
+ "args": [
81
+ "mcp-remote",
82
+ "https://[my-mcp-url].workers.dev/sse"
83
+ ]
84
+ }
85
+ }
86
+ }
87
+ ```
88
+
89
+ 3. Save the configuration file and **restart** Claude Desktop to apply the changes.
90
+
91
+ This setup ensures that Claude Desktop can communicate with the Cloudflare Playwright MCP server.
92
+
93
+ 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:
94
+
95
+ ![alt text](https://github.com/cloudflare/playwright-mcp/raw/main/docs/imgs/claudemcp.gif)
96
+
97
+ ### Configure in VSCode
98
+
99
+ You can install the Playwright MCP server using the [VS Code CLI](https://code.visualstudio.com/docs/configure/command-line):
100
+
101
+ ```bash
102
+ # For VS Code
103
+ code --add-mcp '{"name":"cloudflare-playwright","type":"sse","url":"https://[my-mcp-url].workers.dev/sse"}'
104
+ ```
105
+
106
+ ```bash
107
+ # For VS Code Insiders
108
+ code-insiders --add-mcp '{"name":"cloudflare-playwright","type":"sse","url":"https://[my-mcp-url].workers.dev/sse"}'
109
+ ```
110
+
111
+ After installation, the Playwright MCP server will be available for use with your GitHub Copilot agent in VS Code.
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@szymonrybczak/patchright-mcp-template",
3
+ "version": "0.0.1-next",
4
+ "description": "Cloudflare Playwright Tools for MCP - Template",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/cloudflare/playwright-mcp.git"
8
+ },
9
+ "homepage": "https://github.com/cloudflare/playwright-mcp",
10
+ "engines": {
11
+ "node": ">=18"
12
+ },
13
+ "license": "Apache-2.0",
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "deploy": "wrangler deploy"
17
+ },
18
+ "dependencies": {
19
+ "@szymonrybczak/playwright-mcp": "^0.0.4",
20
+ "chromium-bidi": "^12.0.1"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^22.14.1",
24
+ "typescript": "^5.8.2",
25
+ "wrangler": "^4.26.0"
26
+ }
27
+ }
package/src/index.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { env } from "cloudflare:workers";
2
+
3
+ import { createMcpAgent } from "@szymonrybczak/playwright-mcp";
4
+
5
+ export const PlaywrightMCP = createMcpAgent(env.BROWSER);
6
+
7
+ export default {
8
+ fetch(request: Request, env: Env, ctx: ExecutionContext) {
9
+ const { pathname } = new URL(request.url);
10
+
11
+ switch (pathname) {
12
+ case "/sse":
13
+ case "/sse/message":
14
+ return PlaywrightMCP.serveSSE("/sse").fetch(request, env, ctx);
15
+ case "/mcp":
16
+ return PlaywrightMCP.serve("/mcp").fetch(request, env, ctx);
17
+ default:
18
+ return new Response("Not Found", { status: 404 });
19
+ }
20
+ },
21
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "ESNext",
4
+ "moduleResolution": "Bundler",
5
+ "noEmit": true,
6
+ "skipLibCheck": true
7
+ },
8
+ "include": [
9
+ "worker-configuration.d.ts",
10
+ ]
11
+ }