@playwright/mcp 0.0.18 → 0.0.19

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/lib/server.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Microsoft Corporation.
4
3
  *
@@ -14,31 +13,28 @@
14
13
  * See the License for the specific language governing permissions and
15
14
  * limitations under the License.
16
15
  */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.ServerList = void 0;
19
- exports.createServerWithTools = createServerWithTools;
20
- const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
21
- const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
22
- const zod_to_json_schema_1 = require("zod-to-json-schema");
23
- const context_1 = require("./context");
24
- function createServerWithTools(serverOptions, config) {
16
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
17
+ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
18
+ import { zodToJsonSchema } from 'zod-to-json-schema';
19
+ import { Context } from './context.js';
20
+ export function createServerWithTools(serverOptions, config) {
25
21
  const { name, version, tools } = serverOptions;
26
- const context = new context_1.Context(tools, config);
27
- const server = new index_js_1.Server({ name, version }, {
22
+ const context = new Context(tools, config);
23
+ const server = new Server({ name, version }, {
28
24
  capabilities: {
29
25
  tools: {},
30
26
  }
31
27
  });
32
- server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
28
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
33
29
  return {
34
30
  tools: tools.map(tool => ({
35
31
  name: tool.schema.name,
36
32
  description: tool.schema.description,
37
- inputSchema: (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema.inputSchema)
33
+ inputSchema: zodToJsonSchema(tool.schema.inputSchema)
38
34
  })),
39
35
  };
40
36
  });
41
- server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
37
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
42
38
  const errorResult = (...messages) => ({
43
39
  content: [{ type: 'text', text: messages.join('\n') }],
44
40
  isError: true,
@@ -65,7 +61,7 @@ function createServerWithTools(serverOptions, config) {
65
61
  };
66
62
  return server;
67
63
  }
68
- class ServerList {
64
+ export class ServerList {
69
65
  _servers = [];
70
66
  _serverFactory;
71
67
  constructor(serverFactory) {
@@ -86,4 +82,3 @@ class ServerList {
86
82
  await Promise.all(this._servers.map(server => server.close()));
87
83
  }
88
84
  }
89
- exports.ServerList = ServerList;
package/lib/tab.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Microsoft Corporation.
4
3
  *
@@ -14,10 +13,8 @@
14
13
  * See the License for the specific language governing permissions and
15
14
  * limitations under the License.
16
15
  */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.Tab = void 0;
19
- const pageSnapshot_1 = require("./pageSnapshot");
20
- class Tab {
16
+ import { PageSnapshot } from './pageSnapshot.js';
17
+ export class Tab {
21
18
  context;
22
19
  page;
23
20
  _console = [];
@@ -44,6 +41,9 @@ class Tab {
44
41
  }, this);
45
42
  });
46
43
  page.on('dialog', dialog => this.context.dialogShown(this, dialog));
44
+ page.on('download', download => {
45
+ void this.context.downloadStarted(this, download);
46
+ });
47
47
  page.setDefaultNavigationTimeout(60000);
48
48
  page.setDefaultTimeout(5000);
49
49
  }
@@ -75,7 +75,6 @@ class Tab {
75
75
  return this._requests;
76
76
  }
77
77
  async captureSnapshot() {
78
- this._snapshot = await pageSnapshot_1.PageSnapshot.create(this.page);
78
+ this._snapshot = await PageSnapshot.create(this.page);
79
79
  }
80
80
  }
81
- exports.Tab = Tab;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Microsoft Corporation.
4
3
  *
@@ -14,16 +13,15 @@
14
13
  * See the License for the specific language governing permissions and
15
14
  * limitations under the License.
16
15
  */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const zod_1 = require("zod");
19
- const tool_1 = require("./tool");
20
- const wait = captureSnapshot => (0, tool_1.defineTool)({
16
+ import { z } from 'zod';
17
+ import { defineTool } from './tool.js';
18
+ const wait = captureSnapshot => defineTool({
21
19
  capability: 'wait',
22
20
  schema: {
23
21
  name: 'browser_wait',
24
22
  description: 'Wait for a specified time in seconds',
25
- inputSchema: zod_1.z.object({
26
- time: zod_1.z.number().describe('The time to wait in seconds'),
23
+ inputSchema: z.object({
24
+ time: z.number().describe('The time to wait in seconds'),
27
25
  }),
28
26
  },
29
27
  handle: async (context, params) => {
@@ -35,12 +33,12 @@ const wait = captureSnapshot => (0, tool_1.defineTool)({
35
33
  };
36
34
  },
37
35
  });
38
- const close = (0, tool_1.defineTool)({
36
+ const close = defineTool({
39
37
  capability: 'core',
40
38
  schema: {
41
39
  name: 'browser_close',
42
40
  description: 'Close the page',
43
- inputSchema: zod_1.z.object({}),
41
+ inputSchema: z.object({}),
44
42
  },
45
43
  handle: async (context) => {
46
44
  await context.close();
@@ -51,14 +49,14 @@ const close = (0, tool_1.defineTool)({
51
49
  };
52
50
  },
53
51
  });
54
- const resize = captureSnapshot => (0, tool_1.defineTool)({
52
+ const resize = captureSnapshot => defineTool({
55
53
  capability: 'core',
56
54
  schema: {
57
55
  name: 'browser_resize',
58
56
  description: 'Resize the browser window',
59
- inputSchema: zod_1.z.object({
60
- width: zod_1.z.number().describe('Width of the browser window'),
61
- height: zod_1.z.number().describe('Height of the browser window'),
57
+ inputSchema: z.object({
58
+ width: z.number().describe('Width of the browser window'),
59
+ height: z.number().describe('Height of the browser window'),
62
60
  }),
63
61
  },
64
62
  handle: async (context, params) => {
@@ -78,7 +76,7 @@ const resize = captureSnapshot => (0, tool_1.defineTool)({
78
76
  };
79
77
  },
80
78
  });
81
- exports.default = (captureSnapshot) => [
79
+ export default (captureSnapshot) => [
82
80
  close,
83
81
  wait(captureSnapshot),
84
82
  resize(captureSnapshot)
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Microsoft Corporation.
4
3
  *
@@ -14,15 +13,14 @@
14
13
  * See the License for the specific language governing permissions and
15
14
  * limitations under the License.
16
15
  */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const zod_1 = require("zod");
19
- const tool_1 = require("./tool");
20
- const console = (0, tool_1.defineTool)({
16
+ import { z } from 'zod';
17
+ import { defineTool } from './tool.js';
18
+ const console = defineTool({
21
19
  capability: 'core',
22
20
  schema: {
23
21
  name: 'browser_console_messages',
24
22
  description: 'Returns all console messages',
25
- inputSchema: zod_1.z.object({}),
23
+ inputSchema: z.object({}),
26
24
  },
27
25
  handle: async (context) => {
28
26
  const messages = context.currentTabOrDie().console();
@@ -39,6 +37,6 @@ const console = (0, tool_1.defineTool)({
39
37
  };
40
38
  },
41
39
  });
42
- exports.default = [
40
+ export default [
43
41
  console,
44
42
  ];
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Microsoft Corporation.
4
3
  *
@@ -14,17 +13,16 @@
14
13
  * See the License for the specific language governing permissions and
15
14
  * limitations under the License.
16
15
  */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const zod_1 = require("zod");
19
- const tool_1 = require("./tool");
20
- const handleDialog = captureSnapshot => (0, tool_1.defineTool)({
16
+ import { z } from 'zod';
17
+ import { defineTool } from './tool.js';
18
+ const handleDialog = captureSnapshot => defineTool({
21
19
  capability: 'core',
22
20
  schema: {
23
21
  name: 'browser_handle_dialog',
24
22
  description: 'Handle a dialog',
25
- inputSchema: zod_1.z.object({
26
- accept: zod_1.z.boolean().describe('Whether to accept the dialog.'),
27
- promptText: zod_1.z.string().optional().describe('The text of the prompt in case of a prompt dialog.'),
23
+ inputSchema: z.object({
24
+ accept: z.boolean().describe('Whether to accept the dialog.'),
25
+ promptText: z.string().optional().describe('The text of the prompt in case of a prompt dialog.'),
28
26
  }),
29
27
  },
30
28
  handle: async (context, params) => {
@@ -47,6 +45,6 @@ const handleDialog = captureSnapshot => (0, tool_1.defineTool)({
47
45
  },
48
46
  clearsModalState: 'dialog',
49
47
  });
50
- exports.default = (captureSnapshot) => [
48
+ export default (captureSnapshot) => [
51
49
  handleDialog(captureSnapshot),
52
50
  ];
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Microsoft Corporation.
4
3
  *
@@ -14,16 +13,15 @@
14
13
  * See the License for the specific language governing permissions and
15
14
  * limitations under the License.
16
15
  */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const zod_1 = require("zod");
19
- const tool_1 = require("./tool");
20
- const uploadFile = captureSnapshot => (0, tool_1.defineTool)({
16
+ import { z } from 'zod';
17
+ import { defineTool } from './tool.js';
18
+ const uploadFile = captureSnapshot => defineTool({
21
19
  capability: 'files',
22
20
  schema: {
23
21
  name: 'browser_file_upload',
24
22
  description: 'Upload one or multiple files',
25
- inputSchema: zod_1.z.object({
26
- paths: zod_1.z.array(zod_1.z.string()).describe('The absolute paths to the files to upload. Can be a single file or multiple files.'),
23
+ inputSchema: z.object({
24
+ paths: z.array(z.string()).describe('The absolute paths to the files to upload. Can be a single file or multiple files.'),
27
25
  }),
28
26
  },
29
27
  handle: async (context, params) => {
@@ -46,6 +44,6 @@ const uploadFile = captureSnapshot => (0, tool_1.defineTool)({
46
44
  },
47
45
  clearsModalState: 'fileChooser',
48
46
  });
49
- exports.default = (captureSnapshot) => [
47
+ export default (captureSnapshot) => [
50
48
  uploadFile(captureSnapshot),
51
49
  ];
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Microsoft Corporation.
4
3
  *
@@ -14,25 +13,21 @@
14
13
  * See the License for the specific language governing permissions and
15
14
  * limitations under the License.
16
15
  */
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- const child_process_1 = require("child_process");
22
- const path_1 = __importDefault(require("path"));
23
- const zod_1 = require("zod");
24
- const tool_1 = require("./tool");
25
- const install = (0, tool_1.defineTool)({
16
+ import { fork } from 'child_process';
17
+ import path from 'path';
18
+ import { z } from 'zod';
19
+ import { defineTool } from './tool.js';
20
+ const install = defineTool({
26
21
  capability: 'install',
27
22
  schema: {
28
23
  name: 'browser_install',
29
24
  description: 'Install the browser specified in the config. Call this if you get an error about the browser not being installed.',
30
- inputSchema: zod_1.z.object({}),
25
+ inputSchema: z.object({}),
31
26
  },
32
27
  handle: async (context) => {
33
28
  const channel = context.config.browser?.launchOptions?.channel ?? context.config.browser?.launchOptions.browserName ?? 'chrome';
34
- const cli = path_1.default.join(require.resolve('playwright/package.json'), '..', 'cli.js');
35
- const child = (0, child_process_1.fork)(cli, ['install', channel], {
29
+ const cli = path.join(require.resolve('playwright/package.json'), '..', 'cli.js');
30
+ const child = fork(cli, ['install', channel], {
36
31
  stdio: 'pipe',
37
32
  });
38
33
  const output = [];
@@ -53,6 +48,6 @@ const install = (0, tool_1.defineTool)({
53
48
  };
54
49
  },
55
50
  });
56
- exports.default = [
51
+ export default [
57
52
  install,
58
53
  ];
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Microsoft Corporation.
4
3
  *
@@ -14,16 +13,15 @@
14
13
  * See the License for the specific language governing permissions and
15
14
  * limitations under the License.
16
15
  */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const zod_1 = require("zod");
19
- const tool_1 = require("./tool");
20
- const pressKey = captureSnapshot => (0, tool_1.defineTool)({
16
+ import { z } from 'zod';
17
+ import { defineTool } from './tool.js';
18
+ const pressKey = captureSnapshot => defineTool({
21
19
  capability: 'core',
22
20
  schema: {
23
21
  name: 'browser_press_key',
24
22
  description: 'Press a key on the keyboard',
25
- inputSchema: zod_1.z.object({
26
- key: zod_1.z.string().describe('Name of the key to press or a character to generate, such as `ArrowLeft` or `a`'),
23
+ inputSchema: z.object({
24
+ key: z.string().describe('Name of the key to press or a character to generate, such as `ArrowLeft` or `a`'),
27
25
  }),
28
26
  },
29
27
  handle: async (context, params) => {
@@ -41,6 +39,6 @@ const pressKey = captureSnapshot => (0, tool_1.defineTool)({
41
39
  };
42
40
  },
43
41
  });
44
- exports.default = (captureSnapshot) => [
42
+ export default (captureSnapshot) => [
45
43
  pressKey(captureSnapshot),
46
44
  ];
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Microsoft Corporation.
4
3
  *
@@ -14,16 +13,15 @@
14
13
  * See the License for the specific language governing permissions and
15
14
  * limitations under the License.
16
15
  */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const zod_1 = require("zod");
19
- const tool_1 = require("./tool");
20
- const navigate = captureSnapshot => (0, tool_1.defineTool)({
16
+ import { z } from 'zod';
17
+ import { defineTool } from './tool.js';
18
+ const navigate = captureSnapshot => defineTool({
21
19
  capability: 'core',
22
20
  schema: {
23
21
  name: 'browser_navigate',
24
22
  description: 'Navigate to a URL',
25
- inputSchema: zod_1.z.object({
26
- url: zod_1.z.string().describe('The URL to navigate to'),
23
+ inputSchema: z.object({
24
+ url: z.string().describe('The URL to navigate to'),
27
25
  }),
28
26
  },
29
27
  handle: async (context, params) => {
@@ -40,12 +38,12 @@ const navigate = captureSnapshot => (0, tool_1.defineTool)({
40
38
  };
41
39
  },
42
40
  });
43
- const goBack = captureSnapshot => (0, tool_1.defineTool)({
41
+ const goBack = captureSnapshot => defineTool({
44
42
  capability: 'history',
45
43
  schema: {
46
44
  name: 'browser_navigate_back',
47
45
  description: 'Go back to the previous page',
48
- inputSchema: zod_1.z.object({}),
46
+ inputSchema: z.object({}),
49
47
  },
50
48
  handle: async (context) => {
51
49
  const tab = await context.ensureTab();
@@ -61,12 +59,12 @@ const goBack = captureSnapshot => (0, tool_1.defineTool)({
61
59
  };
62
60
  },
63
61
  });
64
- const goForward = captureSnapshot => (0, tool_1.defineTool)({
62
+ const goForward = captureSnapshot => defineTool({
65
63
  capability: 'history',
66
64
  schema: {
67
65
  name: 'browser_navigate_forward',
68
66
  description: 'Go forward to the next page',
69
- inputSchema: zod_1.z.object({}),
67
+ inputSchema: z.object({}),
70
68
  },
71
69
  handle: async (context) => {
72
70
  const tab = context.currentTabOrDie();
@@ -82,7 +80,7 @@ const goForward = captureSnapshot => (0, tool_1.defineTool)({
82
80
  };
83
81
  },
84
82
  });
85
- exports.default = (captureSnapshot) => [
83
+ export default (captureSnapshot) => [
86
84
  navigate(captureSnapshot),
87
85
  goBack(captureSnapshot),
88
86
  goForward(captureSnapshot),
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Microsoft Corporation.
4
3
  *
@@ -14,15 +13,14 @@
14
13
  * See the License for the specific language governing permissions and
15
14
  * limitations under the License.
16
15
  */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- const zod_1 = require("zod");
19
- const tool_1 = require("./tool");
20
- const requests = (0, tool_1.defineTool)({
16
+ import { z } from 'zod';
17
+ import { defineTool } from './tool.js';
18
+ const requests = defineTool({
21
19
  capability: 'core',
22
20
  schema: {
23
21
  name: 'browser_network_requests',
24
22
  description: 'Returns all network requests since loading the page',
25
- inputSchema: zod_1.z.object({}),
23
+ inputSchema: z.object({}),
26
24
  },
27
25
  handle: async (context) => {
28
26
  const requests = context.currentTabOrDie().requests();
@@ -46,6 +44,6 @@ function renderRequest(request, response) {
46
44
  result.push(`=> [${response.status()}] ${response.statusText()}`);
47
45
  return result.join(' ');
48
46
  }
49
- exports.default = [
47
+ export default [
50
48
  requests,
51
49
  ];
package/lib/tools/pdf.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Copyright (c) Microsoft Corporation.
4
3
  *
@@ -14,54 +13,20 @@
14
13
  * See the License for the specific language governing permissions and
15
14
  * limitations under the License.
16
15
  */
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
31
- o["default"] = v;
32
- });
33
- var __importStar = (this && this.__importStar) || (function () {
34
- var ownKeys = function(o) {
35
- ownKeys = Object.getOwnPropertyNames || function (o) {
36
- var ar = [];
37
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
- return ar;
39
- };
40
- return ownKeys(o);
41
- };
42
- return function (mod) {
43
- if (mod && mod.__esModule) return mod;
44
- var result = {};
45
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
- __setModuleDefault(result, mod);
47
- return result;
48
- };
49
- })();
50
- Object.defineProperty(exports, "__esModule", { value: true });
51
- const zod_1 = require("zod");
52
- const tool_1 = require("./tool");
53
- const javascript = __importStar(require("../javascript"));
54
- const config_1 = require("../config");
55
- const pdf = (0, tool_1.defineTool)({
16
+ import { z } from 'zod';
17
+ import { defineTool } from './tool.js';
18
+ import * as javascript from '../javascript.js';
19
+ import { outputFile } from '../config.js';
20
+ const pdf = defineTool({
56
21
  capability: 'pdf',
57
22
  schema: {
58
23
  name: 'browser_pdf_save',
59
24
  description: 'Save page as PDF',
60
- inputSchema: zod_1.z.object({}),
25
+ inputSchema: z.object({}),
61
26
  },
62
27
  handle: async (context) => {
63
28
  const tab = context.currentTabOrDie();
64
- const fileName = await (0, config_1.outputFile)(context.config, `page-${new Date().toISOString()}'.pdf'`);
29
+ const fileName = await outputFile(context.config, `page-${new Date().toISOString()}.pdf`);
65
30
  const code = [
66
31
  `// Save page as ${fileName}`,
67
32
  `await page.pdf(${javascript.formatObject({ path: fileName })});`,
@@ -74,6 +39,6 @@ const pdf = (0, tool_1.defineTool)({
74
39
  };
75
40
  },
76
41
  });
77
- exports.default = [
42
+ export default [
78
43
  pdf,
79
44
  ];