@playwright-repl/mcp 0.13.0 → 0.14.0
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 +41 -1
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ It consists of two parts working together: **Dramaturg** (a Chrome extension tha
|
|
|
20
20
|
|
|
21
21
|
| | `@playwright-repl/mcp` | Playwright MCP | Playwriter |
|
|
22
22
|
|---|:---:|:---:|:---:|
|
|
23
|
-
| MCP tools exposed | **
|
|
23
|
+
| MCP tools exposed | **2** (`run_command` + `run_script`) | ~70 tools | **1** `execute` |
|
|
24
24
|
| Uses your real session | ✅ | ❌ | ✅ |
|
|
25
25
|
| Playwright runs inside browser | ✅ | ❌ | ❌ |
|
|
26
26
|
| `expect()` assertions | ✅ | ❌ | ❌ |
|
|
@@ -147,6 +147,46 @@ window.location.href
|
|
|
147
147
|
document.querySelectorAll('a').length
|
|
148
148
|
```
|
|
149
149
|
|
|
150
|
+
## Tool: `run_script`
|
|
151
|
+
|
|
152
|
+
Batch execution for multi-line scripts. Two language modes:
|
|
153
|
+
|
|
154
|
+
### Keyword script (`language="pw"`)
|
|
155
|
+
|
|
156
|
+
Splits by line, runs each command sequentially, returns ✓/✗ per line:
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
goto https://demo.playwright.dev/todomvc/
|
|
160
|
+
fill "What needs to be done?" "Buy groceries"
|
|
161
|
+
press Enter
|
|
162
|
+
verify-text "Buy groceries"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### JavaScript (`language="javascript"`)
|
|
166
|
+
|
|
167
|
+
Runs the entire block as one evaluation — use for Playwright API with assertions:
|
|
168
|
+
|
|
169
|
+
```js
|
|
170
|
+
await page.goto('https://demo.playwright.dev/todomvc/');
|
|
171
|
+
await page.getByPlaceholder('What needs to be done?').fill('Buy groceries');
|
|
172
|
+
await page.keyboard.press('Enter');
|
|
173
|
+
await expect(page.getByText('Buy groceries')).toBeVisible();
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Prompt: `generate-test`
|
|
177
|
+
|
|
178
|
+
A prompt template that guides the AI to generate a passing Playwright test from a described scenario.
|
|
179
|
+
|
|
180
|
+
**Args:**
|
|
181
|
+
- `steps` (required) — describe the test scenario, e.g. "log in with email/password, verify the dashboard loads". Also accepts pasted `.pw` scripts.
|
|
182
|
+
- `url` (optional) — URL to navigate to first.
|
|
183
|
+
|
|
184
|
+
**In Claude Desktop:** click "+" → select `generate-test` → fill in the form → send.
|
|
185
|
+
|
|
186
|
+
**In Claude Code:** `/mcp__playwright-repl__generate-test`
|
|
187
|
+
|
|
188
|
+
The AI navigates the page, takes snapshots, writes Playwright assertions, runs them via `run_script(language="javascript")`, and iterates until all pass.
|
|
189
|
+
|
|
150
190
|
## Tips for AI agents
|
|
151
191
|
|
|
152
192
|
- **Call `snapshot` to understand the page** — it returns the accessibility tree with element refs (`e1`, `e5`, …) that you can use with `click`, `fill`, etc. Useful before interacting with an unfamiliar page.
|
package/dist/index.js
CHANGED
|
@@ -67,6 +67,70 @@ server.registerTool('run_command', {
|
|
|
67
67
|
isError: result.isError,
|
|
68
68
|
};
|
|
69
69
|
});
|
|
70
|
+
const RUN_SCRIPT_DESCRIPTION = `\
|
|
71
|
+
Run a multi-line script, returning combined pass/fail results.
|
|
72
|
+
Useful for replaying a known script without per-step round trips.
|
|
73
|
+
Prefer run_command for AI-driven exploration where you need to observe and adapt after each step.
|
|
74
|
+
|
|
75
|
+
language='pw': each line is a .pw keyword command, run sequentially. Lines starting with # are skipped. Stops on first error.
|
|
76
|
+
language='javascript': the entire script is run as a single JavaScript/Playwright block.`;
|
|
77
|
+
server.registerTool('run_script', {
|
|
78
|
+
description: RUN_SCRIPT_DESCRIPTION,
|
|
79
|
+
inputSchema: {
|
|
80
|
+
script: z.string().describe('The script to execute'),
|
|
81
|
+
language: z.enum(['pw', 'javascript']).describe("'pw' for keyword commands (one per line), 'javascript' for a JS/Playwright block"),
|
|
82
|
+
},
|
|
83
|
+
}, async ({ script, language }) => {
|
|
84
|
+
if (!srv.connected) {
|
|
85
|
+
return {
|
|
86
|
+
content: [{ type: 'text', text: 'Browser not connected. Open Chrome with the playwright-repl extension — it connects automatically.' }],
|
|
87
|
+
isError: true,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const result = await srv.runScript(script, language);
|
|
91
|
+
return {
|
|
92
|
+
content: [{ type: 'text', text: result.text || 'Done' }],
|
|
93
|
+
isError: result.isError,
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
const GENERATE_TEST_PROMPT = (steps, url) => `\
|
|
97
|
+
Generate a passing Playwright test for the following scenario:
|
|
98
|
+
${steps}
|
|
99
|
+
|
|
100
|
+
Workflow:
|
|
101
|
+
1. ${url ? `Navigate to ${url} using run_command('goto ${url}').` : 'Navigate to the target URL using run_command.'}
|
|
102
|
+
2. Take a snapshot using run_command('snapshot') to understand the page structure.
|
|
103
|
+
3. Interact with the page as needed (click, fill, press) using run_command.
|
|
104
|
+
4. After each interaction, take another snapshot to verify the state before asserting.
|
|
105
|
+
5. Write assertions using \`expect\`.
|
|
106
|
+
|
|
107
|
+
Example pattern:
|
|
108
|
+
await page.goto('https://example.com');
|
|
109
|
+
await expect(page).toHaveTitle('Example', { exact: true });
|
|
110
|
+
await expect(page.getByRole('heading', { name: 'Welcome' })).toBeVisible();
|
|
111
|
+
await page.getByRole('link', { name: 'Get started', exact: true }).click();
|
|
112
|
+
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
|
|
113
|
+
|
|
114
|
+
Code constraints:
|
|
115
|
+
- Use only \`page\` and \`expect\` — available as globals, do NOT import them
|
|
116
|
+
- Plain \`await\` statements only — no \`import\`, no \`test()\` wrapper, no \`describe()\`
|
|
117
|
+
- Use \`exact: true\` when a locator text might match multiple elements
|
|
118
|
+
|
|
119
|
+
Once you have the code, run it with run_script(language="javascript").
|
|
120
|
+
If any assertion fails, read the error, fix the code, and run again until all pass.
|
|
121
|
+
Show the final passing code.`;
|
|
122
|
+
server.registerPrompt('generate-test', {
|
|
123
|
+
description: 'Generate a passing Playwright test from a described scenario',
|
|
124
|
+
argsSchema: {
|
|
125
|
+
steps: z.string().describe('Describe the test scenario, e.g. "log in with email/password, verify the dashboard loads"'),
|
|
126
|
+
url: z.string().optional().describe('URL to navigate to first (optional)'),
|
|
127
|
+
},
|
|
128
|
+
}, ({ steps, url }) => ({
|
|
129
|
+
messages: [{
|
|
130
|
+
role: 'user',
|
|
131
|
+
content: { type: 'text', text: GENERATE_TEST_PROMPT(steps, url) },
|
|
132
|
+
}],
|
|
133
|
+
}));
|
|
70
134
|
const transport = new StdioServerTransport();
|
|
71
135
|
await server.connect(transport);
|
|
72
136
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AACvC,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC,CAAC;IACvB,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CA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