Skip to content

Commit e631dfd

Browse files
committed
feat(mcp): add JSON Schema for MCP/CLI configuration files
Auto-generate a JSON Schema (draft-07) from config.d.ts using the TypeScript compiler API. The schema covers all Config fields including recursively expanded LaunchOptions and BrowserContextOptions. - Add utils/generate_mcp_config_schema.js generator script - Output mcp-config.schema.json alongside config.d.ts - Register in build.js onChanges and flint for CI staleness checks - Add config-schema.spec.ts with structural assertion tests - Fix config.d.ts / configIni.ts drift: add saveTrace, remove dead saveVideo, add timeouts.expect to longhandTypes - Document $schema usage in getting-started-mcp.md and getting-started-cli.md
1 parent 2d6be2d commit e631dfd

9 files changed

Lines changed: 1481 additions & 11 deletions

File tree

docs/src/getting-started-cli.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,14 @@ playwright-cli --config path/to/config.json open example.com
275275
276276
The CLI also loads `.playwright/cli.config.json` automatically if present. The config file supports browser options, context options, network rules, timeouts, and more. Run `playwright-cli --help` for the full list of options.
277277
278+
A JSON Schema is available for IDE autocompletion. Once registered with [SchemaStore](https://www.schemastore.org/), the `.playwright/cli.config.json` file will be automatically associated in supported editors. For other file names, add `$schema` manually:
279+
280+
```json
281+
{
282+
"$schema": "https://raw.githubusercontent.com/microsoft/playwright/main/packages/playwright-core/src/tools/mcp/mcp-config.schema.json"
283+
}
284+
```
285+
278286
### Browser extension
279287
280288
Connect to your existing browser tabs instead of launching a new browser:

docs/src/getting-started-mcp.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,30 @@ Playwright MCP supports three profile modes:
179179

180180
### Configuration file
181181

182-
For advanced configuration, use a JSON config file:
182+
For advanced configuration, use a JSON or INI config file:
183183

184184
```bash
185185
npx @playwright/mcp@latest --config path/to/config.json
186186
```
187187

188-
The config file supports browser options, context options, network rules, timeouts, and more. See the [Playwright MCP repository](https://github.com/microsoft/playwright-mcp/blob/main/packages/playwright-mcp/config.d.ts) for the full schema.
188+
The config file supports browser options, context options, network rules, timeouts, and more. See the [Playwright MCP repository](https://github.com/microsoft/playwright-mcp/blob/main/packages/playwright-mcp/config.d.ts) for the full type definition.
189+
190+
#### JSON Schema for IDE autocompletion
191+
192+
A JSON Schema is available for configuration files. Add `$schema` to your config file for IDE autocompletion and validation:
193+
194+
```json
195+
{
196+
"$schema": "https://raw.githubusercontent.com/microsoft/playwright/main/packages/playwright-core/src/tools/mcp/mcp-config.schema.json",
197+
"browser": {
198+
"browserName": "chromium"
199+
}
200+
}
201+
```
202+
203+
If you are using `@playwright/cli`, the project-level config at `.playwright/cli.config.json` will be automatically associated with the schema once registered with [SchemaStore](https://www.schemastore.org/).
204+
205+
**Note:** The JSON Schema only validates JSON config files. INI format config files use the same options but are not validated by this schema.
189206

190207
### Standalone server
191208

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"lint": "npm run eslint && npm run tsc && npm run doc && npm run check-deps && node utils/generate_channels.js && node utils/generate_types/ && npm run lint-tests && npm run test-types && npm run lint-packages",
3636
"lint-packages": "node utils/workspace.js --ensure-consistent",
3737
"lint-tests": "node utils/lint_tests.js",
38-
"flint": "concurrently \"npm run eslint\" \"npm run tsc\" \"npm run doc\" \"npm run check-deps\" \"node utils/generate_channels.js\" \"npm run lint-tests\" \"npm run test-types\" \"npm run lint-packages\" \"node utils/doclint/linting-code-snippets/cli.js --js-only\"",
38+
"flint": "concurrently \"npm run eslint\" \"npm run tsc\" \"npm run doc\" \"npm run check-deps\" \"node utils/generate_channels.js\" \"node utils/generate_mcp_config_schema.js\" \"npm run lint-tests\" \"npm run test-types\" \"npm run lint-packages\" \"node utils/doclint/linting-code-snippets/cli.js --js-only\"",
3939
"clean": "node utils/build/clean.js",
4040
"build": "node utils/build/build.js",
4141
"watch": "node utils/build/build.js --watch --lint",

packages/playwright-core/src/tools/mcp/config.d.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
// JSON Schema is auto-generated from this file by utils/generate_mcp_config_schema.js.
18+
1719
import type * as playwright from '../../..';
1820

1921
export type ToolCapability =
@@ -52,10 +54,9 @@ export type Config = {
5254
userDataDir?: string;
5355

5456
/**
55-
* Launch options passed to
57+
* Launch options passed to browserType.launchPersistentContext().
58+
* This is useful for setting options like `channel`, `headless`, `executablePath`, etc.
5659
* @see https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context
57-
*
58-
* This is useful for settings options like `channel`, `headless`, `executablePath`, etc.
5960
*/
6061
launchOptions?: playwright.LaunchOptions;
6162

@@ -137,6 +138,11 @@ export type Config = {
137138
*/
138139
saveSession?: boolean;
139140

141+
/**
142+
* Whether to save the Playwright trace into the output directory.
143+
*/
144+
saveTrace?: boolean;
145+
140146
/**
141147
* Reuse the same browser context between all connected HTTP clients.
142148
*/
@@ -154,6 +160,11 @@ export type Config = {
154160
*/
155161
outputDir?: string;
156162

163+
/**
164+
* Whether to save snapshots, console messages, network logs and other session logs to a file or to the standard output. Defaults to "stdout".
165+
*/
166+
outputMode?: 'file' | 'stdout';
167+
157168
console?: {
158169
/**
159170
* The level of console messages to return. Each level includes the messages of more severe levels. Defaults to "info".
@@ -187,12 +198,12 @@ export type Config = {
187198
testIdAttribute?: string;
188199

189200
timeouts?: {
190-
/*
201+
/**
191202
* Configures default action timeout: https://playwright.dev/docs/api/class-page#page-set-default-timeout. Defaults to 5000ms.
192203
*/
193204
action?: number;
194205

195-
/*
206+
/**
196207
* Configures default navigation timeout: https://playwright.dev/docs/api/class-page#page-set-default-navigation-timeout. Defaults to 60000ms.
197208
*/
198209
navigation?: number;
@@ -204,7 +215,7 @@ export type Config = {
204215
};
205216

206217
/**
207-
* Whether to send image responses to the client. Can be "allow", "omit", or "auto". Defaults to "auto", which sends images if the client can display them.
218+
* Whether to send image responses to the client. Defaults to "allow".
208219
*/
209220
imageResponses?: 'allow' | 'omit';
210221

packages/playwright-core/src/tools/mcp/configIni.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function setNestedValue(obj: Record<string, any>, dotPath: string, value: any) {
9797
current[parts[parts.length - 1]] = value;
9898
}
9999

100-
// Regenerate this based on packages/playwright/src/tools/mcp/config.d.ts when config changes.
100+
// Keep in sync with config.d.ts. JSON Schema is auto-generated by utils/generate_mcp_config_schema.js.
101101

102102
type LonghandType = 'string' | 'number' | 'boolean' | 'string[]' | 'size';
103103

@@ -159,9 +159,9 @@ const longhandTypes: Record<string, LonghandType> = {
159159
'capabilities': 'string[]',
160160
'saveSession': 'boolean',
161161
'saveTrace': 'boolean',
162-
'saveVideo': 'size',
163162
'sharedBrowserContext': 'boolean',
164163
'outputDir': 'string',
164+
'outputMode': 'string',
165165
'imageResponses': 'string',
166166
'allowUnrestrictedFileAccess': 'boolean',
167167
'codegen': 'string',
@@ -182,6 +182,7 @@ const longhandTypes: Record<string, LonghandType> = {
182182
// timeouts
183183
'timeouts.action': 'number',
184184
'timeouts.navigation': 'number',
185+
'timeouts.expect': 'number',
185186

186187
// snapshot
187188
'snapshot.mode': 'string',

0 commit comments

Comments
 (0)