mcp-accessibility-scanner 1.1.1 → 2.0.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.
Files changed (93) hide show
  1. package/lib/browserContextFactory.js +212 -0
  2. package/lib/browserContextFactory.js.map +1 -0
  3. package/lib/browserServerBackend.js +78 -0
  4. package/lib/browserServerBackend.js.map +1 -0
  5. package/lib/config.js +247 -0
  6. package/lib/config.js.map +1 -0
  7. package/lib/context.js +227 -0
  8. package/lib/context.js.map +1 -0
  9. package/lib/extension/cdpRelay.js +359 -0
  10. package/lib/extension/cdpRelay.js.map +1 -0
  11. package/lib/extension/extensionContextFactory.js +57 -0
  12. package/lib/extension/extensionContextFactory.js.map +1 -0
  13. package/lib/extension/protocol.js +19 -0
  14. package/lib/extension/protocol.js.map +1 -0
  15. package/lib/index.js +41 -0
  16. package/lib/index.js.map +1 -0
  17. package/lib/mcp/http.js +136 -0
  18. package/lib/mcp/http.js.map +1 -0
  19. package/lib/mcp/inProcessTransport.js +73 -0
  20. package/lib/mcp/inProcessTransport.js.map +1 -0
  21. package/lib/mcp/manualPromise.js +112 -0
  22. package/lib/mcp/manualPromise.js.map +1 -0
  23. package/lib/mcp/mdb.js +199 -0
  24. package/lib/mcp/mdb.js.map +1 -0
  25. package/lib/mcp/proxyBackend.js +105 -0
  26. package/lib/mcp/proxyBackend.js.map +1 -0
  27. package/lib/mcp/server.js +124 -0
  28. package/lib/mcp/server.js.map +1 -0
  29. package/lib/mcp/tool.js +33 -0
  30. package/lib/mcp/tool.js.map +1 -0
  31. package/lib/program.js +127 -0
  32. package/lib/program.js.map +1 -0
  33. package/lib/response.js +166 -0
  34. package/lib/response.js.map +1 -0
  35. package/lib/sessionLog.js +122 -0
  36. package/lib/sessionLog.js.map +1 -0
  37. package/lib/tab.js +250 -0
  38. package/lib/tab.js.map +1 -0
  39. package/lib/tools/common.js +56 -0
  40. package/lib/tools/common.js.map +1 -0
  41. package/lib/tools/console.js +34 -0
  42. package/lib/tools/console.js.map +1 -0
  43. package/lib/tools/dialogs.js +48 -0
  44. package/lib/tools/dialogs.js.map +1 -0
  45. package/lib/tools/evaluate.js +54 -0
  46. package/lib/tools/evaluate.js.map +1 -0
  47. package/lib/tools/files.js +45 -0
  48. package/lib/tools/files.js.map +1 -0
  49. package/lib/tools/form.js +58 -0
  50. package/lib/tools/form.js.map +1 -0
  51. package/lib/tools/install.js +54 -0
  52. package/lib/tools/install.js.map +1 -0
  53. package/lib/tools/keyboard.js +79 -0
  54. package/lib/tools/keyboard.js.map +1 -0
  55. package/lib/tools/mouse.js +100 -0
  56. package/lib/tools/mouse.js.map +1 -0
  57. package/lib/tools/navigate.js +55 -0
  58. package/lib/tools/navigate.js.map +1 -0
  59. package/lib/tools/network.js +42 -0
  60. package/lib/tools/network.js.map +1 -0
  61. package/lib/tools/pdf.js +41 -0
  62. package/lib/tools/pdf.js.map +1 -0
  63. package/lib/tools/screenshot.js +80 -0
  64. package/lib/tools/screenshot.js.map +1 -0
  65. package/lib/tools/snapshot.js +194 -0
  66. package/lib/tools/snapshot.js.map +1 -0
  67. package/lib/tools/tabs.js +60 -0
  68. package/lib/tools/tabs.js.map +1 -0
  69. package/lib/tools/tool.js +34 -0
  70. package/lib/tools/tool.js.map +1 -0
  71. package/lib/tools/utils.js +75 -0
  72. package/lib/tools/utils.js.map +1 -0
  73. package/lib/tools/verify.js +138 -0
  74. package/lib/tools/verify.js.map +1 -0
  75. package/lib/tools/wait.js +56 -0
  76. package/lib/tools/wait.js.map +1 -0
  77. package/lib/tools.js +55 -0
  78. package/lib/tools.js.map +1 -0
  79. package/lib/utils/codegen.js +50 -0
  80. package/lib/utils/codegen.js.map +1 -0
  81. package/lib/utils/fileUtils.js +37 -0
  82. package/lib/utils/fileUtils.js.map +1 -0
  83. package/lib/utils/guid.js +23 -0
  84. package/lib/utils/guid.js.map +1 -0
  85. package/lib/utils/log.js +22 -0
  86. package/lib/utils/log.js.map +1 -0
  87. package/lib/utils/package.js +21 -0
  88. package/lib/utils/package.js.map +1 -0
  89. package/lib/vscode/host.js +129 -0
  90. package/lib/vscode/host.js.map +1 -0
  91. package/lib/vscode/main.js +63 -0
  92. package/lib/vscode/main.js.map +1 -0
  93. package/package.json +19 -19
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { z } from 'zod';
17
+ import { defineTool } from './tool.js';
18
+ const wait = defineTool({
19
+ capability: 'core',
20
+ schema: {
21
+ name: 'browser_wait_for',
22
+ title: 'Wait for',
23
+ description: 'Wait for text to appear or disappear or a specified time to pass',
24
+ inputSchema: z.object({
25
+ time: z.number().optional().describe('The time to wait in seconds'),
26
+ text: z.string().optional().describe('The text to wait for'),
27
+ textGone: z.string().optional().describe('The text to wait for to disappear'),
28
+ }),
29
+ type: 'readOnly',
30
+ },
31
+ handle: async (context, params, response) => {
32
+ if (!params.text && !params.textGone && !params.time)
33
+ throw new Error('Either time, text or textGone must be provided');
34
+ if (params.time) {
35
+ response.addCode(`await new Promise(f => setTimeout(f, ${params.time} * 1000));`);
36
+ await new Promise(f => setTimeout(f, Math.min(30000, params.time * 1000)));
37
+ }
38
+ const tab = context.currentTabOrDie();
39
+ const locator = params.text ? tab.page.getByText(params.text).first() : undefined;
40
+ const goneLocator = params.textGone ? tab.page.getByText(params.textGone).first() : undefined;
41
+ if (goneLocator) {
42
+ response.addCode(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
43
+ await goneLocator.waitFor({ state: 'hidden' });
44
+ }
45
+ if (locator) {
46
+ response.addCode(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
47
+ await locator.waitFor({ state: 'visible' });
48
+ }
49
+ response.addResult(`Waited for ${params.text || params.textGone || params.time}`);
50
+ response.setIncludeSnapshot();
51
+ },
52
+ });
53
+ export default [
54
+ wait,
55
+ ];
56
+ //# sourceMappingURL=wait.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait.js","sourceRoot":"","sources":["../../src/tools/wait.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,MAAM,IAAI,GAAG,UAAU,CAAC;IACtB,UAAU,EAAE,MAAM;IAElB,MAAM,EAAE;QACN,IAAI,EAAE,kBAAkB;QACxB,KAAK,EAAE,UAAU;QACjB,WAAW,EAAE,kEAAkE;QAC/E,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;YACpB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;YACnE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,sBAAsB,CAAC;YAC5D,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,mCAAmC,CAAC;SAC9E,CAAC;QACF,IAAI,EAAE,UAAU;KACjB;IAED,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE;QAC1C,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,IAAI;YAClD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAEpE,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MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAClF,QAAQ,CAAC,kBAAkB,EAAE,CAAC;IAChC,CAAC;CACF,CAAC,CAAC;AAEH,eAAe;IACb,IAAI;CACL,CAAC"}
package/lib/tools.js ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import common from './tools/common.js';
17
+ import console from './tools/console.js';
18
+ import dialogs from './tools/dialogs.js';
19
+ import evaluate from './tools/evaluate.js';
20
+ import files from './tools/files.js';
21
+ import form from './tools/form.js';
22
+ import install from './tools/install.js';
23
+ import keyboard from './tools/keyboard.js';
24
+ import mouse from './tools/mouse.js';
25
+ import navigate from './tools/navigate.js';
26
+ import network from './tools/network.js';
27
+ import pdf from './tools/pdf.js';
28
+ import snapshot from './tools/snapshot.js';
29
+ import tabs from './tools/tabs.js';
30
+ import screenshot from './tools/screenshot.js';
31
+ import wait from './tools/wait.js';
32
+ import verify from './tools/verify.js';
33
+ export const allTools = [
34
+ ...common,
35
+ ...console,
36
+ ...dialogs,
37
+ ...evaluate,
38
+ ...files,
39
+ ...form,
40
+ ...install,
41
+ ...keyboard,
42
+ ...navigate,
43
+ ...network,
44
+ ...mouse,
45
+ ...pdf,
46
+ ...screenshot,
47
+ ...snapshot,
48
+ ...tabs,
49
+ ...wait,
50
+ ...verify,
51
+ ];
52
+ export function filteredTools(config) {
53
+ return allTools.filter(tool => tool.capability.startsWith('core') || config.capabilities?.includes(tool.capability));
54
+ }
55
+ //# source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IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;AACvH,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ // adapted from:
17
+ // - https://github.com/microsoft/playwright/blob/76ee48dc9d4034536e3ec5b2c7ce8be3b79418a8/packages/playwright-core/src/utils/isomorphic/stringUtils.ts
18
+ // - https://github.com/microsoft/playwright/blob/76ee48dc9d4034536e3ec5b2c7ce8be3b79418a8/packages/playwright-core/src/server/codegen/javascript.ts
19
+ // NOTE: this function should not be used to escape any selectors.
20
+ export function escapeWithQuotes(text, char = '\'') {
21
+ const stringified = JSON.stringify(text);
22
+ const escapedText = stringified.substring(1, stringified.length - 1).replace(/\\"/g, '"');
23
+ if (char === '\'')
24
+ return char + escapedText.replace(/[']/g, '\\\'') + char;
25
+ if (char === '"')
26
+ return char + escapedText.replace(/["]/g, '\\"') + char;
27
+ if (char === '`')
28
+ return char + escapedText.replace(/[`]/g, '\\`') + char;
29
+ throw new Error('Invalid escape char');
30
+ }
31
+ export function quote(text) {
32
+ return escapeWithQuotes(text, '\'');
33
+ }
34
+ export function formatObject(value, indent = ' ') {
35
+ if (typeof value === 'string')
36
+ return quote(value);
37
+ if (Array.isArray(value))
38
+ return `[${value.map(o => formatObject(o)).join(', ')}]`;
39
+ if (typeof value === 'object') {
40
+ const keys = Object.keys(value).filter(key => value[key] !== undefined).sort();
41
+ if (!keys.length)
42
+ return '{}';
43
+ const tokens = [];
44
+ for (const key of keys)
45
+ tokens.push(`${key}: ${formatObject(value[key])}`);
46
+ return `{\n${indent}${tokens.join(`,\n${indent}`)}\n}`;
47
+ }
48
+ return String(value);
49
+ }
50
+ //# sourceMappingURL=codegen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../src/utils/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,gBAAgB;AAChB,uJAAuJ;AACvJ,oJAAoJ;AAEpJ,kEAAkE;AAClE,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,OAAe,IAAI;IAChE,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,WAAW,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1F,IAAI,IAAI,KAAK,IAAI;QACf,OAAO,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAC3D,IAAI,IAAI,KAAK,GAAG;QACd,OAAO,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;IAC1D,IAAI,IAAI,KAAK,GAAG;QACd,OAAO,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;IAC1D,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,IAAY;IAChC,OAAO,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAU,EAAE,MAAM,GAAG,IAAI;IACpD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAC3B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC;IACtB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACtB,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IAC3D,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC;QAC/E,IAAI,CAAC,IAAI,CAAC,MAAM;YACd,OAAO,IAAI,CAAC;QACd,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,KAAK,MAAM,GAAG,IAAI,IAAI;YACpB,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;QACrD,OAAO,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,MAAM,EAAE,CAAC,KAAK,CAAC;IACzD,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import os from 'node:os';
17
+ import path from 'node:path';
18
+ export function cacheDir() {
19
+ let cacheDirectory;
20
+ if (process.platform === 'linux')
21
+ cacheDirectory = process.env.XDG_CACHE_HOME || path.join(os.homedir(), '.cache');
22
+ else if (process.platform === 'darwin')
23
+ cacheDirectory = path.join(os.homedir(), 'Library', 'Caches');
24
+ else if (process.platform === 'win32')
25
+ cacheDirectory = process.env.LOCALAPPDATA || path.join(os.homedir(), 'AppData', 'Local');
26
+ else
27
+ throw new Error('Unsupported platform: ' + process.platform);
28
+ return path.join(cacheDirectory, 'ms-playwright');
29
+ }
30
+ export function sanitizeForFilePath(s) {
31
+ const sanitize = (s) => s.replace(/[\x00-\x2C\x2E-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]+/g, '-');
32
+ const separator = s.lastIndexOf('.');
33
+ if (separator === -1)
34
+ return sanitize(s);
35
+ return sanitize(s.substring(0, separator)) + '.' + sanitize(s.substring(separator + 1));
36
+ }
37
+ //# sourceMappingURL=fileUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileUtils.js","sourceRoot":"","sources":["../../src/utils/fileUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,UAAU,QAAQ;IACtB,IAAI,cAAsB,CAAC;IAC3B,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAC9B,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;SAC9E,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ;QACpC,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;SAC3D,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QACnC,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;;QAEzF,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC/D,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,CAAS;IAC3C,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,mDAAmD,EAAE,GAAG,CAAC,CAAC;IACpG,MAAM,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,SAAS,KAAK,CAAC,CAAC;QAClB,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrB,OAAO,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,GAAG,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import crypto from 'crypto';
17
+ export function createGuid() {
18
+ return crypto.randomBytes(16).toString('hex');
19
+ }
20
+ export function createHash(data) {
21
+ return crypto.createHash('sha256').update(data).digest('hex').slice(0, 7);
22
+ }
23
+ //# sourceMappingURL=guid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guid.js","sourceRoot":"","sources":["../../src/utils/guid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,UAAU,UAAU;IACxB,OAAO,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import debug from 'debug';
17
+ const errorsDebug = debug('pw:mcp:errors');
18
+ export function logUnhandledError(error) {
19
+ errorsDebug(error);
20
+ }
21
+ export const testDebug = debug('pw:mcp:test');
22
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/utils/log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,WAAW,GAAG,KAAK,CAAC,eAAe,CAAC,CAAC;AAE3C,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,WAAW,CAAC,KAAK,CAAC,CAAC;AACrB,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import fs from 'fs';
17
+ import path from 'path';
18
+ import url from 'url';
19
+ const __filename = url.fileURLToPath(import.meta.url);
20
+ export const packageJSON = JSON.parse(fs.readFileSync(path.join(path.dirname(__filename), '..', '..', 'package.json'), 'utf8'));
21
+ //# sourceMappingURL=package.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.js","sourceRoot":"","sources":["../../src/utils/package.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,UAAU,GAAG,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { fileURLToPath } from 'url';
17
+ import path from 'path';
18
+ import { z } from 'zod';
19
+ import { zodToJsonSchema } from 'zod-to-json-schema';
20
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
21
+ import { ListRootsRequestSchema, PingRequestSchema } from '@modelcontextprotocol/sdk/types.js';
22
+ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
23
+ import * as mcpServer from '../mcp/server.js';
24
+ import { logUnhandledError } from '../utils/log.js';
25
+ import { packageJSON } from '../utils/package.js';
26
+ import { BrowserServerBackend } from '../browserServerBackend.js';
27
+ import { contextFactory } from '../browserContextFactory.js';
28
+ const contextSwitchOptions = z.object({
29
+ connectionString: z.string().optional().describe('The connection string to use to connect to the browser'),
30
+ lib: z.string().optional().describe('The library to use for the connection'),
31
+ });
32
+ class VSCodeProxyBackend {
33
+ _config;
34
+ _defaultTransportFactory;
35
+ name = 'Playwright MCP Client Switcher';
36
+ version = packageJSON.version;
37
+ _currentClient;
38
+ _contextSwitchTool;
39
+ _roots = [];
40
+ _clientVersion;
41
+ constructor(_config, _defaultTransportFactory) {
42
+ this._config = _config;
43
+ this._defaultTransportFactory = _defaultTransportFactory;
44
+ this._contextSwitchTool = this._defineContextSwitchTool();
45
+ }
46
+ async initialize(server, clientVersion, roots) {
47
+ this._clientVersion = clientVersion;
48
+ this._roots = roots;
49
+ const transport = await this._defaultTransportFactory();
50
+ await this._setCurrentClient(transport);
51
+ }
52
+ async listTools() {
53
+ const response = await this._currentClient.listTools();
54
+ return [
55
+ ...response.tools,
56
+ this._contextSwitchTool,
57
+ ];
58
+ }
59
+ async callTool(name, args) {
60
+ if (name === this._contextSwitchTool.name)
61
+ return this._callContextSwitchTool(args);
62
+ return await this._currentClient.callTool({
63
+ name,
64
+ arguments: args,
65
+ });
66
+ }
67
+ serverClosed(server) {
68
+ void this._currentClient?.close().catch(logUnhandledError);
69
+ }
70
+ async _callContextSwitchTool(params) {
71
+ if (!params.connectionString || !params.lib) {
72
+ const transport = await this._defaultTransportFactory();
73
+ await this._setCurrentClient(transport);
74
+ return {
75
+ content: [{ type: 'text', text: '### Result\nSuccessfully disconnected.\n' }],
76
+ };
77
+ }
78
+ await this._setCurrentClient(new StdioClientTransport({
79
+ command: process.execPath,
80
+ cwd: process.cwd(),
81
+ args: [
82
+ path.join(fileURLToPath(import.meta.url), '..', 'main.js'),
83
+ JSON.stringify(this._config),
84
+ params.connectionString,
85
+ params.lib,
86
+ ],
87
+ }));
88
+ return {
89
+ content: [{ type: 'text', text: '### Result\nSuccessfully connected.\n' }],
90
+ };
91
+ }
92
+ _defineContextSwitchTool() {
93
+ return {
94
+ name: 'browser_connect',
95
+ description: 'Do not call, this tool is used in the integration with the Playwright VS Code Extension and meant for programmatic usage only.',
96
+ inputSchema: zodToJsonSchema(contextSwitchOptions, { strictUnions: true }),
97
+ annotations: {
98
+ title: 'Connect to a browser running in VS Code.',
99
+ readOnlyHint: true,
100
+ openWorldHint: false,
101
+ },
102
+ };
103
+ }
104
+ async _setCurrentClient(transport) {
105
+ await this._currentClient?.close();
106
+ this._currentClient = undefined;
107
+ const client = new Client(this._clientVersion);
108
+ client.registerCapabilities({
109
+ roots: {
110
+ listRoots: true,
111
+ },
112
+ });
113
+ client.setRequestHandler(ListRootsRequestSchema, () => ({ roots: this._roots }));
114
+ client.setRequestHandler(PingRequestSchema, () => ({}));
115
+ await client.connect(transport);
116
+ this._currentClient = client;
117
+ }
118
+ }
119
+ export async function runVSCodeTools(config) {
120
+ const serverBackendFactory = {
121
+ name: 'Playwright w/ vscode',
122
+ nameInConfig: 'playwright-vscode',
123
+ version: packageJSON.version,
124
+ create: () => new VSCodeProxyBackend(config, () => mcpServer.wrapInProcess(new BrowserServerBackend(config, contextFactory(config))))
125
+ };
126
+ await mcpServer.start(serverBackendFactory, config.server);
127
+ return;
128
+ }
129
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/vscode/host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAC/F,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAK7D,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,wDAAwD,CAAC;IAC1G,GAAG,EAAE,CAAC,CAA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+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
17
+ import * as mcpServer from '../mcp/server.js';
18
+ import { BrowserServerBackend } from '../browserServerBackend.js';
19
+ class VSCodeBrowserContextFactory {
20
+ _config;
21
+ _playwright;
22
+ _connectionString;
23
+ name = 'vscode';
24
+ description = 'Connect to a browser running in the Playwright VS Code extension';
25
+ constructor(_config, _playwright, _connectionString) {
26
+ this._config = _config;
27
+ this._playwright = _playwright;
28
+ this._connectionString = _connectionString;
29
+ }
30
+ async createContext(clientInfo, abortSignal) {
31
+ let launchOptions = this._config.browser.launchOptions;
32
+ if (this._config.browser.userDataDir) {
33
+ launchOptions = {
34
+ ...launchOptions,
35
+ ...this._config.browser.contextOptions,
36
+ userDataDir: this._config.browser.userDataDir,
37
+ };
38
+ }
39
+ const connectionString = new URL(this._connectionString);
40
+ connectionString.searchParams.set('launch-options', JSON.stringify(launchOptions));
41
+ const browserType = this._playwright.chromium; // it could also be firefox or webkit, we just need some browser type to call `connect` on
42
+ const browser = await browserType.connect(connectionString.toString());
43
+ const context = browser.contexts()[0] ?? await browser.newContext(this._config.browser.contextOptions);
44
+ return {
45
+ browserContext: context,
46
+ close: async () => {
47
+ await browser.close();
48
+ }
49
+ };
50
+ }
51
+ }
52
+ async function main(config, connectionString, lib) {
53
+ const playwright = await import(lib).then(mod => mod.default ?? mod);
54
+ const factory = new VSCodeBrowserContextFactory(config, playwright, connectionString);
55
+ await mcpServer.connect({
56
+ name: 'Playwright MCP',
57
+ nameInConfig: 'playwright-vscode',
58
+ create: () => new BrowserServerBackend(config, factory),
59
+ version: 'unused'
60
+ }, new StdioServerTransport(), false);
61
+ }
62
+ await main(JSON.parse(process.argv[2]), process.argv[3], process.argv[4]);
63
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/vscode/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,KAAK,SAAS,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAKlE,MAAM,2BAA2B;IAIX;IAA6B;IAAkD;IAHnG,IAAI,GAAG,QAAQ,CAAC;IAChB,WAAW,GAAG,kEAAkE,CAAC;IAEjF,YAAoB,OAAmB,EAAU,WAAwC,EAAU,iBAAyB;QAAxG,YAAO,GAAP,OAAO,CAAY;QAAU,gBAAW,GAAX,WAAW,CAA6B;QAAU,sBAAiB,GAAjB,iBAAiB,CAAQ;IAAG,CAAC;IAEhI,KAAK,CAAC,aAAa,CAAC,UAAsB,EAAE,WAAwB;QAClE,IAAI,aAAa,GAAQ,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC;QAC5D,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YACrC,aAAa,GAAG;gBACd,GAAG,aAAa;gBAChB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc;gBACtC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW;aAC9C,CAAC;QACJ,CAAC;QACD,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACzD,gBAAgB,CAAC,YAAY,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,aAA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ClB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-accessibility-scanner",
3
- "version": "1.1.1",
3
+ "version": "2.0.0",
4
4
  "mcpName": "io.github.JustasMonkev/mcp-accessibility-scanner",
5
5
  "description": "A Model Context Protocol (MCP) server for performing automated accessibility scans of web pages using Playwright and Axe-core",
6
6
  "type": "module",
@@ -22,8 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "build": "tsc --project tsconfig.json",
25
- "lint": "npm run update-readme && eslint . && tsc --noEmit",
26
- "update-readme": "node utils/update-readme.js",
25
+ "lint": "npm run eslint . && tsc --noEmit",
27
26
  "watch": "tsc --watch",
28
27
  "run-server": "node lib/browserServer.js",
29
28
  "clean": "rm -rf lib",
@@ -31,32 +30,33 @@
31
30
  },
32
31
  "dependencies": {
33
32
  "@axe-core/playwright": "^4.10.2",
34
- "@modelcontextprotocol/sdk": "^1.16.0",
35
- "commander": "^14.0.0",
36
- "debug": "^4.4.1",
37
- "mime": "^4.0.7",
38
- "playwright": "^1.54.1",
39
- "playwright-core": "^1.54.1",
33
+ "@modelcontextprotocol/sdk": "^1.18.1",
34
+ "commander": "^14.0.1",
35
+ "debug": "^4.4.3",
36
+ "dotenv": "^17.2.2",
37
+ "mime": "^4.1.0",
38
+ "playwright": "^1.55.0",
39
+ "playwright-core": "^1.55.0",
40
40
  "ws": "^8.18.3",
41
41
  "zod-to-json-schema": "^3.24.6"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@eslint/eslintrc": "^3.3.1",
45
- "@eslint/js": "^9.31.0",
46
- "@playwright/test": "^1.54.1",
47
- "@stylistic/eslint-plugin": "^5.2.0",
48
- "@types/chrome": "^0.1.1",
45
+ "@eslint/js": "^9.36.0",
46
+ "@playwright/test": "^1.55.0",
47
+ "@stylistic/eslint-plugin": "^5.3.1",
48
+ "@types/chrome": "^0.1.12",
49
49
  "@types/debug": "^4.1.12",
50
- "@types/node": "^24.0.15",
50
+ "@types/node": "^24.5.2",
51
51
  "@types/ws": "^8.18.1",
52
- "@typescript-eslint/eslint-plugin": "^8.37.0",
53
- "@typescript-eslint/parser": "^8.37.0",
54
- "@typescript-eslint/utils": "^8.37.0",
55
- "eslint": "^9.31.0",
52
+ "@typescript-eslint/eslint-plugin": "^8.44.0",
53
+ "@typescript-eslint/parser": "^8.44.0",
54
+ "@typescript-eslint/utils": "^8.44.0",
55
+ "eslint": "^9.35.0",
56
56
  "eslint-plugin-import": "^2.32.0",
57
57
  "eslint-plugin-notice": "^1.0.0",
58
58
  "ts-node": "^10.9.2",
59
- "typescript": "^5.8.3"
59
+ "typescript": "^5.9.2"
60
60
  },
61
61
  "keywords": [
62
62
  "mcp",