fastbrowser_cli 1.0.14 → 1.0.16
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/.playwright-mcp/.gitignore +3 -0
- package/README.md +29 -3
- package/dist/fastbrowser_cli/fastbrowser_cli.js +52 -35
- package/dist/fastbrowser_cli/fastbrowser_cli.js.map +1 -1
- package/dist/fastbrowser_cli/libs/http-client.js +3 -7
- package/dist/fastbrowser_cli/libs/http-client.js.map +1 -1
- package/dist/fastbrowser_cli/libs/server-manager.d.ts.map +1 -1
- package/dist/fastbrowser_cli/libs/server-manager.js +30 -28
- package/dist/fastbrowser_cli/libs/server-manager.js.map +1 -1
- package/dist/fastbrowser_httpd/fastbrowser_httpd.js +22 -18
- package/dist/fastbrowser_httpd/fastbrowser_httpd.js.map +1 -1
- package/dist/fastbrowser_httpd/libs/routes.d.ts +2 -2
- package/dist/fastbrowser_httpd/libs/routes.d.ts.map +1 -1
- package/dist/fastbrowser_httpd/libs/routes.js +4 -8
- package/dist/fastbrowser_httpd/libs/routes.js.map +1 -1
- package/dist/fastbrowser_httpd/libs/tool-schemas.js +39 -42
- package/dist/fastbrowser_httpd/libs/tool-schemas.js.map +1 -1
- package/dist/fastbrowser_mcp/fastbrowser_mcp.d.ts.map +1 -1
- package/dist/fastbrowser_mcp/fastbrowser_mcp.js +270 -187
- package/dist/fastbrowser_mcp/fastbrowser_mcp.js.map +1 -1
- package/dist/fastbrowser_mcp/fastbrowser_types.d.ts +5 -0
- package/dist/fastbrowser_mcp/fastbrowser_types.d.ts.map +1 -0
- package/dist/fastbrowser_mcp/fastbrowser_types.js +2 -0
- package/dist/fastbrowser_mcp/fastbrowser_types.js.map +1 -0
- package/dist/{fastweb_mcp/libs/mcp_client.d.ts → fastbrowser_mcp/libs/mcp_client_TOREMOVE.d.ts} +6 -2
- package/dist/fastbrowser_mcp/libs/mcp_client_TOREMOVE.d.ts.map +1 -0
- package/dist/{src/libs/mcp_client.js → fastbrowser_mcp/libs/mcp_client_TOREMOVE.js} +15 -12
- package/dist/fastbrowser_mcp/libs/mcp_client_TOREMOVE.js.map +1 -0
- package/dist/{src/libs/mcp_client.d.ts → fastbrowser_mcp/libs/mcp_my_client.d.ts} +6 -2
- package/dist/fastbrowser_mcp/libs/mcp_my_client.d.ts.map +1 -0
- package/dist/{fastweb_mcp/libs/mcp_client.js → fastbrowser_mcp/libs/mcp_my_client.js} +15 -12
- package/dist/fastbrowser_mcp/libs/mcp_my_client.js.map +1 -0
- package/dist/fastbrowser_mcp/libs/mcp_proxy.d.ts +2 -2
- package/dist/fastbrowser_mcp/libs/mcp_proxy.d.ts.map +1 -1
- package/dist/fastbrowser_mcp/libs/mcp_proxy.js +9 -16
- package/dist/fastbrowser_mcp/libs/mcp_proxy.js.map +1 -1
- package/dist/fastbrowser_mcp/libs/mcp_target_helper.d.ts +35 -0
- package/dist/fastbrowser_mcp/libs/mcp_target_helper.d.ts.map +1 -0
- package/dist/fastbrowser_mcp/libs/mcp_target_helper.js +161 -0
- package/dist/fastbrowser_mcp/libs/mcp_target_helper.js.map +1 -0
- package/dist/fastbrowser_mcp/libs/playwright_a11y_helper.d.ts +28 -0
- package/dist/fastbrowser_mcp/libs/playwright_a11y_helper.d.ts.map +1 -0
- package/dist/fastbrowser_mcp/libs/playwright_a11y_helper.js +210 -0
- package/dist/fastbrowser_mcp/libs/playwright_a11y_helper.js.map +1 -0
- package/dist/fastbrowser_mcp/libs/response_formatter.d.ts +10 -0
- package/dist/fastbrowser_mcp/libs/response_formatter.d.ts.map +1 -0
- package/dist/fastbrowser_mcp/libs/response_formatter.js +155 -0
- package/dist/fastbrowser_mcp/libs/response_formatter.js.map +1 -0
- package/dist/fastbrowser_mcp/libs/schemas.js +14 -17
- package/dist/fastbrowser_mcp/libs/schemas.js.map +1 -1
- package/examples/mcp_client_playwright.ts +34 -0
- package/examples/welcometothejungle/wttj-job.ts +180 -0
- package/examples/welcometothejungle/wttj-search.ts +105 -0
- package/outputs/.gitignore +3 -0
- package/package.json +12 -8
- package/src/fastbrowser_cli/fastbrowser_cli.ts +34 -11
- package/src/fastbrowser_cli/libs/server-manager.ts +12 -3
- package/src/fastbrowser_httpd/fastbrowser_httpd.ts +16 -5
- package/src/fastbrowser_httpd/libs/routes.ts +2 -2
- package/src/fastbrowser_mcp/fastbrowser_mcp.ts +324 -150
- package/src/fastbrowser_mcp/fastbrowser_types.ts +4 -0
- package/src/fastbrowser_mcp/libs/{mcp_client.ts → mcp_client_TOREMOVE.ts} +13 -1
- package/src/fastbrowser_mcp/libs/mcp_my_client.ts +128 -0
- package/src/fastbrowser_mcp/libs/mcp_proxy.ts +2 -2
- package/src/fastbrowser_mcp/libs/mcp_target_helper.ts +164 -0
- package/src/fastbrowser_mcp/libs/playwright_a11y_helper.ts +249 -0
- package/src/fastbrowser_mcp/libs/response_formatter.ts +162 -0
- package/src/fastbrowser_mcp/libs/schemas.ts +2 -2
- package/tsconfig.build.json +13 -0
- package/tsconfig.json +10 -22
- package/dist/contrib/fastweb-cli/fastweb-cli.d.ts +0 -3
- package/dist/contrib/fastweb-cli/fastweb-cli.d.ts.map +0 -1
- package/dist/contrib/fastweb-cli/fastweb-cli.js +0 -151
- package/dist/contrib/fastweb-cli/fastweb-cli.js.map +0 -1
- package/dist/contrib/fastweb-cli/http-client.d.ts +0 -7
- package/dist/contrib/fastweb-cli/http-client.d.ts.map +0 -1
- package/dist/contrib/fastweb-cli/http-client.js +0 -51
- package/dist/contrib/fastweb-cli/http-client.js.map +0 -1
- package/dist/contrib/fastweb-http-server/fastweb-http-server.d.ts +0 -3
- package/dist/contrib/fastweb-http-server/fastweb-http-server.d.ts.map +0 -1
- package/dist/contrib/fastweb-http-server/fastweb-http-server.js +0 -82
- package/dist/contrib/fastweb-http-server/fastweb-http-server.js.map +0 -1
- package/dist/contrib/fastweb-http-server/routes.d.ts +0 -6
- package/dist/contrib/fastweb-http-server/routes.d.ts.map +0 -1
- package/dist/contrib/fastweb-http-server/routes.js +0 -41
- package/dist/contrib/fastweb-http-server/routes.js.map +0 -1
- package/dist/contrib/fastweb-http-server/tool-schemas.d.ts +0 -63
- package/dist/contrib/fastweb-http-server/tool-schemas.d.ts.map +0 -1
- package/dist/contrib/fastweb-http-server/tool-schemas.js +0 -61
- package/dist/contrib/fastweb-http-server/tool-schemas.js.map +0 -1
- package/dist/fastbrowser_mcp/libs/mcp_client.d.ts +0 -120
- package/dist/fastbrowser_mcp/libs/mcp_client.d.ts.map +0 -1
- package/dist/fastbrowser_mcp/libs/mcp_client.js +0 -83
- package/dist/fastbrowser_mcp/libs/mcp_client.js.map +0 -1
- package/dist/fastweb_cli/fastweb_cli.d.ts +0 -3
- package/dist/fastweb_cli/fastweb_cli.d.ts.map +0 -1
- package/dist/fastweb_cli/fastweb_cli.js +0 -254
- package/dist/fastweb_cli/fastweb_cli.js.map +0 -1
- package/dist/fastweb_cli/http-client.d.ts +0 -7
- package/dist/fastweb_cli/http-client.d.ts.map +0 -1
- package/dist/fastweb_cli/http-client.js +0 -51
- package/dist/fastweb_cli/http-client.js.map +0 -1
- package/dist/fastweb_cli/libs/http-client.d.ts +0 -7
- package/dist/fastweb_cli/libs/http-client.d.ts.map +0 -1
- package/dist/fastweb_cli/libs/http-client.js +0 -51
- package/dist/fastweb_cli/libs/http-client.js.map +0 -1
- package/dist/fastweb_cli/libs/server-manager.d.ts +0 -12
- package/dist/fastweb_cli/libs/server-manager.d.ts.map +0 -1
- package/dist/fastweb_cli/libs/server-manager.js +0 -194
- package/dist/fastweb_cli/libs/server-manager.js.map +0 -1
- package/dist/fastweb_http_server/fastweb_http_server.d.ts +0 -3
- package/dist/fastweb_http_server/fastweb_http_server.d.ts.map +0 -1
- package/dist/fastweb_http_server/fastweb_http_server.js +0 -82
- package/dist/fastweb_http_server/fastweb_http_server.js.map +0 -1
- package/dist/fastweb_http_server/libs/routes.d.ts +0 -6
- package/dist/fastweb_http_server/libs/routes.d.ts.map +0 -1
- package/dist/fastweb_http_server/libs/routes.js +0 -41
- package/dist/fastweb_http_server/libs/routes.js.map +0 -1
- package/dist/fastweb_http_server/libs/tool-schemas.d.ts +0 -72
- package/dist/fastweb_http_server/libs/tool-schemas.d.ts.map +0 -1
- package/dist/fastweb_http_server/libs/tool-schemas.js +0 -65
- package/dist/fastweb_http_server/libs/tool-schemas.js.map +0 -1
- package/dist/fastweb_http_server/routes.d.ts +0 -6
- package/dist/fastweb_http_server/routes.d.ts.map +0 -1
- package/dist/fastweb_http_server/routes.js +0 -41
- package/dist/fastweb_http_server/routes.js.map +0 -1
- package/dist/fastweb_http_server/tool-schemas.d.ts +0 -63
- package/dist/fastweb_http_server/tool-schemas.d.ts.map +0 -1
- package/dist/fastweb_http_server/tool-schemas.js +0 -61
- package/dist/fastweb_http_server/tool-schemas.js.map +0 -1
- package/dist/fastweb_mcp/fastweb_mcp.d.ts +0 -4
- package/dist/fastweb_mcp/fastweb_mcp.d.ts.map +0 -1
- package/dist/fastweb_mcp/fastweb_mcp.js +0 -417
- package/dist/fastweb_mcp/fastweb_mcp.js.map +0 -1
- package/dist/fastweb_mcp/libs/mcp_client.d.ts.map +0 -1
- package/dist/fastweb_mcp/libs/mcp_client.js.map +0 -1
- package/dist/fastweb_mcp/libs/mcp_proxy.d.ts +0 -10
- package/dist/fastweb_mcp/libs/mcp_proxy.d.ts.map +0 -1
- package/dist/fastweb_mcp/libs/mcp_proxy.js +0 -45
- package/dist/fastweb_mcp/libs/mcp_proxy.js.map +0 -1
- package/dist/fastweb_mcp/libs/schemas.d.ts +0 -28
- package/dist/fastweb_mcp/libs/schemas.d.ts.map +0 -1
- package/dist/fastweb_mcp/libs/schemas.js +0 -38
- package/dist/fastweb_mcp/libs/schemas.js.map +0 -1
- package/dist/src/fastweb_mcp.d.ts +0 -17
- package/dist/src/fastweb_mcp.d.ts.map +0 -1
- package/dist/src/fastweb_mcp.js +0 -342
- package/dist/src/fastweb_mcp.js.map +0 -1
- package/dist/src/libs/mcp_client.d.ts.map +0 -1
- package/dist/src/libs/mcp_client.js.map +0 -1
- package/dist/src/libs/mcp_proxy.d.ts +0 -10
- package/dist/src/libs/mcp_proxy.d.ts.map +0 -1
- package/dist/src/libs/mcp_proxy.js +0 -45
- package/dist/src/libs/mcp_proxy.js.map +0 -1
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
3
|
+
// Convert Playwright's get-text-snapshot format to chrome-devtools-mcp's
|
|
4
|
+
// take_snapshot body format, so that the rest of the pipeline (A11yParse +
|
|
5
|
+
// selector engine) can be reused unchanged.
|
|
6
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
7
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
8
|
+
export class PlaywrightA11yConverter {
|
|
9
|
+
/**
|
|
10
|
+
* Convert Playwright's `get-text-snapshot` output to the body of chrome-devtools-mcp's `take_snapshot`.
|
|
11
|
+
*
|
|
12
|
+
* Playwright emits a YAML-like tree with `[ref=eN]` markers, e.g.
|
|
13
|
+
* ```
|
|
14
|
+
* - link "Welcome" [ref=e7] [cursor=pointer]:
|
|
15
|
+
* - /url: /fr
|
|
16
|
+
* - img "Welcome" [ref=e8]
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* chrome-devtools-mcp emits one node per line with `uid=...`, e.g.
|
|
20
|
+
* ```
|
|
21
|
+
* uid=e7 link "Welcome" url="/fr"
|
|
22
|
+
* uid=e8 image "Welcome"
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* The output omits the `## Latest page snapshot` metadata line, so it can be passed directly
|
|
26
|
+
* to `A11yParse.A11yTree.parse()`.
|
|
27
|
+
*/
|
|
28
|
+
static convertToChromeDevtools(playwrightText) {
|
|
29
|
+
const lines = playwrightText.split('\n');
|
|
30
|
+
const stack = [];
|
|
31
|
+
const allNodes = [];
|
|
32
|
+
let synthCounter = 0;
|
|
33
|
+
const synth = () => `s${++synthCounter}`;
|
|
34
|
+
for (const rawLine of lines) {
|
|
35
|
+
if (rawLine.trim().length === 0)
|
|
36
|
+
continue;
|
|
37
|
+
const indentMatch = /^( *)/.exec(rawLine);
|
|
38
|
+
const leadingSpaces = indentMatch !== null ? indentMatch[1].length : 0;
|
|
39
|
+
const indent = Math.floor(leadingSpaces / 2);
|
|
40
|
+
const trimmed = rawLine.slice(leadingSpaces);
|
|
41
|
+
if (!trimmed.startsWith('- '))
|
|
42
|
+
continue;
|
|
43
|
+
const body = trimmed.slice(2);
|
|
44
|
+
while (stack.length > 0 && stack[stack.length - 1].indent >= indent) {
|
|
45
|
+
stack.pop();
|
|
46
|
+
}
|
|
47
|
+
const parent = stack[stack.length - 1];
|
|
48
|
+
const parsed = PlaywrightA11yConverter._parseLine(body);
|
|
49
|
+
if (parsed.kind === 'parent_attr') {
|
|
50
|
+
if (parent !== undefined) {
|
|
51
|
+
parent.attrs.push([parsed.key, parsed.value]);
|
|
52
|
+
}
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (parsed.kind === 'static_text') {
|
|
56
|
+
const node = {
|
|
57
|
+
indent,
|
|
58
|
+
uid: synth(),
|
|
59
|
+
role: 'StaticText',
|
|
60
|
+
name: parsed.text,
|
|
61
|
+
attrs: [],
|
|
62
|
+
flags: [],
|
|
63
|
+
};
|
|
64
|
+
allNodes.push(node);
|
|
65
|
+
stack.push(node);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const uid = parsed.uid !== undefined ? parsed.uid : synth();
|
|
69
|
+
const attrs = [...parsed.attrs];
|
|
70
|
+
if (parsed.value !== undefined) {
|
|
71
|
+
attrs.push(['value', parsed.value]);
|
|
72
|
+
}
|
|
73
|
+
const node = {
|
|
74
|
+
indent,
|
|
75
|
+
uid,
|
|
76
|
+
role: parsed.role,
|
|
77
|
+
name: parsed.name,
|
|
78
|
+
attrs,
|
|
79
|
+
flags: parsed.flags,
|
|
80
|
+
};
|
|
81
|
+
allNodes.push(node);
|
|
82
|
+
stack.push(node);
|
|
83
|
+
}
|
|
84
|
+
return allNodes.map((node) => PlaywrightA11yConverter._stringifyNode(node)).join('\n');
|
|
85
|
+
}
|
|
86
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
87
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
88
|
+
// Internal helpers
|
|
89
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
90
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
91
|
+
static _parseLine(body) {
|
|
92
|
+
if (body.startsWith('/url:')) {
|
|
93
|
+
return { kind: 'parent_attr', key: 'url', value: body.slice('/url:'.length).trim() };
|
|
94
|
+
}
|
|
95
|
+
if (body.startsWith('/placeholder:')) {
|
|
96
|
+
return { kind: 'parent_attr', key: 'placeholder', value: body.slice('/placeholder:'.length).trim() };
|
|
97
|
+
}
|
|
98
|
+
if (body.startsWith('text:')) {
|
|
99
|
+
const text = PlaywrightA11yConverter._unquoteIfQuoted(body.slice('text:'.length).trim());
|
|
100
|
+
return { kind: 'static_text', text };
|
|
101
|
+
}
|
|
102
|
+
let i = 0;
|
|
103
|
+
const roleMatch = /^(\w+)/.exec(body);
|
|
104
|
+
if (roleMatch === null) {
|
|
105
|
+
return { kind: 'node', role: 'unknown', attrs: [], flags: [] };
|
|
106
|
+
}
|
|
107
|
+
const role = roleMatch[1];
|
|
108
|
+
i = role.length;
|
|
109
|
+
const skipSpaces = () => {
|
|
110
|
+
while (i < body.length && body[i] === ' ')
|
|
111
|
+
i++;
|
|
112
|
+
};
|
|
113
|
+
skipSpaces();
|
|
114
|
+
let name;
|
|
115
|
+
if (body[i] === '"') {
|
|
116
|
+
const parsed = PlaywrightA11yConverter._readQuotedString(body, i);
|
|
117
|
+
name = parsed.value;
|
|
118
|
+
i = parsed.next;
|
|
119
|
+
}
|
|
120
|
+
const brackets = [];
|
|
121
|
+
skipSpaces();
|
|
122
|
+
while (body[i] === '[') {
|
|
123
|
+
const closeIdx = body.indexOf(']', i);
|
|
124
|
+
if (closeIdx === -1)
|
|
125
|
+
break;
|
|
126
|
+
const content = body.slice(i + 1, closeIdx);
|
|
127
|
+
const eqIdx = content.indexOf('=');
|
|
128
|
+
if (eqIdx >= 0) {
|
|
129
|
+
brackets.push({
|
|
130
|
+
kind: 'attr',
|
|
131
|
+
key: content.slice(0, eqIdx),
|
|
132
|
+
value: content.slice(eqIdx + 1),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
brackets.push({ kind: 'flag', name: content });
|
|
137
|
+
}
|
|
138
|
+
i = closeIdx + 1;
|
|
139
|
+
skipSpaces();
|
|
140
|
+
}
|
|
141
|
+
let value;
|
|
142
|
+
if (body[i] === ':') {
|
|
143
|
+
i++;
|
|
144
|
+
const rest = body.slice(i).trim();
|
|
145
|
+
if (rest.length > 0) {
|
|
146
|
+
value = PlaywrightA11yConverter._unquoteIfQuoted(rest);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
let uid;
|
|
150
|
+
const attrs = [];
|
|
151
|
+
const flags = [];
|
|
152
|
+
for (const b of brackets) {
|
|
153
|
+
if (b.kind === 'attr') {
|
|
154
|
+
if (b.key === 'ref') {
|
|
155
|
+
uid = b.value;
|
|
156
|
+
}
|
|
157
|
+
else if (b.key === 'cursor') {
|
|
158
|
+
// CSS cursor — not a meaningful a11y attribute
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
attrs.push([b.key, b.value]);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
flags.push(b.name);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return { kind: 'node', role, name, uid, attrs, flags, value };
|
|
169
|
+
}
|
|
170
|
+
static _readQuotedString(input, start) {
|
|
171
|
+
let i = start + 1;
|
|
172
|
+
let result = '';
|
|
173
|
+
while (i < input.length) {
|
|
174
|
+
const ch = input[i];
|
|
175
|
+
if (ch === '\\' && i + 1 < input.length) {
|
|
176
|
+
result += input[i + 1];
|
|
177
|
+
i += 2;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (ch === '"') {
|
|
181
|
+
return { value: result, next: i + 1 };
|
|
182
|
+
}
|
|
183
|
+
result += ch;
|
|
184
|
+
i++;
|
|
185
|
+
}
|
|
186
|
+
return { value: result, next: i };
|
|
187
|
+
}
|
|
188
|
+
static _unquoteIfQuoted(s) {
|
|
189
|
+
if (s.length >= 2 && s.startsWith('"') && s.endsWith('"')) {
|
|
190
|
+
const inner = s.slice(1, -1);
|
|
191
|
+
return inner.replace(/\\(.)/g, '$1');
|
|
192
|
+
}
|
|
193
|
+
return s;
|
|
194
|
+
}
|
|
195
|
+
static _stringifyNode(node) {
|
|
196
|
+
const pad = ' '.repeat(node.indent);
|
|
197
|
+
const name = node.name !== undefined ? ` "${PlaywrightA11yConverter._escapeQuotes(node.name)}"` : '';
|
|
198
|
+
const parts = [];
|
|
199
|
+
for (const flag of node.flags)
|
|
200
|
+
parts.push(flag);
|
|
201
|
+
for (const [k, v] of node.attrs)
|
|
202
|
+
parts.push(`${k}="${PlaywrightA11yConverter._escapeQuotes(v)}"`);
|
|
203
|
+
const tail = parts.length > 0 ? ' ' + parts.join(' ') : '';
|
|
204
|
+
return `${pad}uid=${node.uid} ${node.role}${name}${tail}`;
|
|
205
|
+
}
|
|
206
|
+
static _escapeQuotes(s) {
|
|
207
|
+
return s.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=playwright_a11y_helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playwright_a11y_helper.js","sourceRoot":"","sources":["../../../src/fastbrowser_mcp/libs/playwright_a11y_helper.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,+EAA+E;AAC/E,yEAAyE;AACzE,2EAA2E;AAC3E,4CAA4C;AAC5C,+EAA+E;AAC/E,+EAA+E;AA4B/E,MAAM,OAAO,uBAAuB;IACnC;;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AC;IACV,CAAC;IAEO,MAAM,CAAC,cAAc,CAAC,IAAiB;QAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,uBAAuB,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACrG,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,uBAAuB,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QAClG,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3D,OAAO,GAAG,GAAG,OAAO,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;IAC3D,CAAC;IAEO,MAAM,CAAC,aAAa,CAAC,CAAS;QACrC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;CACD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CallToolResult } from "@modelcontextprotocol/sdk/types";
|
|
2
|
+
import { FastBrowserMcpTarget } from "../fastbrowser_types.js";
|
|
3
|
+
export declare class ResponseFormatter {
|
|
4
|
+
static formatListPages(mcpTarget: FastBrowserMcpTarget, callToolResult: CallToolResult): Promise<string>;
|
|
5
|
+
static formatNavigatePage(mcpTarget: FastBrowserMcpTarget, callToolResult: CallToolResult): Promise<string>;
|
|
6
|
+
static formatTakeSnapshot(mcpTarget: FastBrowserMcpTarget, callToolResult: CallToolResult): Promise<string>;
|
|
7
|
+
static formatPressKeys(mcpTarget: FastBrowserMcpTarget, keysToSend: string[]): Promise<string>;
|
|
8
|
+
static formatClick(mcpTarget: FastBrowserMcpTarget, callToolResult: CallToolResult): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=response_formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response_formatter.d.ts","sourceRoot":"","sources":["../../../src/fastbrowser_mcp/libs/response_formatter.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAGjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAG/D,qBAAa,iBAAiB;WAChB,eAAe,CAAC,SAAS,EAAE,oBAAoB,EAAE,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;WA+CjG,kBAAkB,CAAC,SAAS,EAAE,oBAAoB,EAAE,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;WA6CpG,kBAAkB,CAAC,SAAS,EAAE,oBAAoB,EAAE,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;WAqBpG,eAAe,CAAC,SAAS,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;WAKvF,WAAW,CAAC,SAAS,EAAE,oBAAoB,EAAE,cAAc,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;CAgC1G"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// node imports
|
|
2
|
+
import * as Assert from "assert";
|
|
3
|
+
import { PlaywrightA11yConverter } from "./playwright_a11y_helper.js";
|
|
4
|
+
export class ResponseFormatter {
|
|
5
|
+
static async formatListPages(mcpTarget, callToolResult) {
|
|
6
|
+
const resultContent = callToolResult.content[0];
|
|
7
|
+
if (resultContent.type !== "text")
|
|
8
|
+
throw new Error("Unexpected content type");
|
|
9
|
+
const resultText = resultContent.text;
|
|
10
|
+
if (mcpTarget === 'chrome_devtools') {
|
|
11
|
+
// EXAMPLE:
|
|
12
|
+
// ## Pages
|
|
13
|
+
// 1: about:blank
|
|
14
|
+
// 2: https://example.com/ [selected]
|
|
15
|
+
return resultText;
|
|
16
|
+
}
|
|
17
|
+
else if (mcpTarget === 'playwright') {
|
|
18
|
+
// EXAMPLE:
|
|
19
|
+
// ### Result
|
|
20
|
+
// - 0: (current) [Offres d'emploi (CDI, CDD), apprentissages et stages | Welcome to the Jungle](https://www.welcometothejungle.com/fr/jobs?refinementList%5Boffices.country_code%5D%5B%5D=FR&query=machine%20learning&page=1)
|
|
21
|
+
// ### Events
|
|
22
|
+
// - New console entries: .playwright-mcp/console-2026-04-25T10-43-58-002Z.log#L1-L62
|
|
23
|
+
// Convert 'playwright' format to 'chrome_devtools' format for consistency in the CLI output
|
|
24
|
+
const lines = resultText.split('\n');
|
|
25
|
+
// remove the 'Events' section and its lines, if it exists
|
|
26
|
+
const eventsIndex = lines.findIndex(line => line.startsWith('### Events'));
|
|
27
|
+
const linesWithoutEvents = eventsIndex !== -1 ? lines.slice(0, eventsIndex) : lines;
|
|
28
|
+
const pageLines = linesWithoutEvents.filter(line => line.trim().startsWith('- '));
|
|
29
|
+
const formattedLines = pageLines.map(line => {
|
|
30
|
+
// Extract the page index and title/url from the line
|
|
31
|
+
const match = line.trim().match(/- (\d+): (.+)/);
|
|
32
|
+
if (match) {
|
|
33
|
+
const index = match[1];
|
|
34
|
+
const titleAndUrl = match[2];
|
|
35
|
+
// Check if this is the current page (marked with "(current)")
|
|
36
|
+
const isCurrent = titleAndUrl.includes('(current)');
|
|
37
|
+
const titleAndUrlClean = titleAndUrl.replace('(current)', '').trim();
|
|
38
|
+
const urlMatch = titleAndUrlClean.match(/\((https?:\/\/.+)\)/);
|
|
39
|
+
const url = urlMatch ? urlMatch[1] : '';
|
|
40
|
+
return `${index}: ${url}${isCurrent ? ' [selected]' : ''}`;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return line; // If the line doesn't match the expected format, return it unchanged
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const outputStr = `## Pages\n${formattedLines.join('\n')}`;
|
|
47
|
+
return outputStr;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error(`Unsupported MCP target: ${mcpTarget}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
static async formatNavigatePage(mcpTarget, callToolResult) {
|
|
54
|
+
const resultContent = callToolResult.content[0];
|
|
55
|
+
if (resultContent.type !== "text")
|
|
56
|
+
throw new Error("Unexpected content type");
|
|
57
|
+
const resultText = resultContent.text;
|
|
58
|
+
// Target format example:
|
|
59
|
+
// Successfully navigated to https://example.com
|
|
60
|
+
if (mcpTarget === 'chrome_devtools') {
|
|
61
|
+
// EXAMPLE:
|
|
62
|
+
// Successfully navigated to https://example.com
|
|
63
|
+
// ## Pages
|
|
64
|
+
// 1: https://example.com/ [selected]
|
|
65
|
+
// Convert 'chrome_devtools' format to the target format for consistency in the CLI output
|
|
66
|
+
const lines = resultText.split('\n');
|
|
67
|
+
// keep only the first line that contains the navigation result
|
|
68
|
+
Assert.ok(lines.length > 0, "Expected at least one line in the navigate page result");
|
|
69
|
+
const navigateLine = lines[0].trim();
|
|
70
|
+
const outputStr = navigateLine ? navigateLine.trim() : resultText; // Return the navigate line if found, otherwise return the original text
|
|
71
|
+
return outputStr;
|
|
72
|
+
}
|
|
73
|
+
else if (mcpTarget === 'playwright') {
|
|
74
|
+
// EXAMPLE:
|
|
75
|
+
// ### Ran Playwright code
|
|
76
|
+
// ```js
|
|
77
|
+
// await page.goto('https:/example.com');
|
|
78
|
+
// ```
|
|
79
|
+
// ### Page
|
|
80
|
+
// - Page URL: https://example.com/
|
|
81
|
+
// - Page Title: Example Domain
|
|
82
|
+
// ### Snapshot
|
|
83
|
+
// - [Snapshot](.playwright-mcp/page-2026-04-25T11-24-36-780Z.yml)
|
|
84
|
+
// Convert 'playwright' format to a simpler format for consistency in the CLI output
|
|
85
|
+
const lines = resultText.split('\n');
|
|
86
|
+
const pageUrlLine = lines.find(line => line.trim().startsWith('- Page URL:'));
|
|
87
|
+
const pageUrl = pageUrlLine ? pageUrlLine.replace('- Page URL:', '').trim() : '';
|
|
88
|
+
Assert.ok(pageUrl, "Expected to find a line with the page URL in the navigate page result");
|
|
89
|
+
const outputStr = `Successfully navigated to ${pageUrl}`;
|
|
90
|
+
return outputStr;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
throw new Error(`Unsupported MCP target: ${mcpTarget}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
static async formatTakeSnapshot(mcpTarget, callToolResult) {
|
|
97
|
+
// extract the snapshot text from the tool response, which has different formats for chrome_devtools and playwright MCP targets
|
|
98
|
+
if (mcpTarget === 'chrome_devtools') {
|
|
99
|
+
// take a snapshot to get the latest accessibility tree
|
|
100
|
+
const responseText = callToolResult.content[0];
|
|
101
|
+
if (responseText.type !== "text")
|
|
102
|
+
throw new Error("Unexpected content type");
|
|
103
|
+
// get the snapshot text and remove the first line (snapshot metadata)
|
|
104
|
+
let snapshotText = responseText.text;
|
|
105
|
+
snapshotText = snapshotText.split('\n').slice(1).join('\n');
|
|
106
|
+
return snapshotText;
|
|
107
|
+
}
|
|
108
|
+
else if (mcpTarget === 'playwright') {
|
|
109
|
+
const responseText = callToolResult.content[0];
|
|
110
|
+
if (responseText.type !== "text")
|
|
111
|
+
throw new Error("Unexpected content type");
|
|
112
|
+
const snapshotText = PlaywrightA11yConverter.convertToChromeDevtools(responseText.text);
|
|
113
|
+
return snapshotText;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
throw new Error(`Unsupported MCP target: ${mcpTarget}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
static async formatPressKeys(mcpTarget, keysToSend) {
|
|
120
|
+
const outputStr = `Pressed keys: ${keysToSend.join(', ')}`;
|
|
121
|
+
return outputStr;
|
|
122
|
+
}
|
|
123
|
+
static async formatClick(mcpTarget, callToolResult) {
|
|
124
|
+
const resultContent = callToolResult.content[0];
|
|
125
|
+
if (resultContent.type !== "text")
|
|
126
|
+
throw new Error("Unexpected content type");
|
|
127
|
+
const resultText = resultContent.text;
|
|
128
|
+
// Target format example:
|
|
129
|
+
// Successfully clicked on the element
|
|
130
|
+
if (mcpTarget === 'chrome_devtools') {
|
|
131
|
+
// EXAMPLE:
|
|
132
|
+
// Successfully clicked on the element
|
|
133
|
+
return resultText;
|
|
134
|
+
}
|
|
135
|
+
else if (mcpTarget === 'playwright') {
|
|
136
|
+
// EXAMPLE:
|
|
137
|
+
// ### Ran Playwright code`
|
|
138
|
+
// ```js
|
|
139
|
+
// await page.getByRole('link', { name: 'Learn more' }).click();
|
|
140
|
+
// ```
|
|
141
|
+
// ### Page
|
|
142
|
+
// - Page URL: https://www.iana.org/help/example-domains
|
|
143
|
+
// - Page Title: Example Domains
|
|
144
|
+
// ### Snapshot
|
|
145
|
+
// - [Snapshot](.playwrigh`t-mcp/page-2026-04-25T11-56-08-184Z.yml)
|
|
146
|
+
// Convert 'playwright' format to a simpler format for consistency in the CLI output
|
|
147
|
+
const outputStr = `Successfully clicked on the element`;
|
|
148
|
+
return outputStr;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
throw new Error(`Unsupported MCP target: ${mcpTarget}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=response_formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response_formatter.js","sourceRoot":"","sources":["../../../src/fastbrowser_mcp/libs/response_formatter.ts"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AAC,EAAE,CAAA;QAC1D,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,SAA+B,EAAE,cAA8B;QACvF,MAAM,aAAa,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;QAC/C,IAAI,aAAa,CAAC,IAAI,KAAK,MAAM;YAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC9E,MAAM,UAAU,GAAW,aAAa,CAAC,IAAI,CAAA;QAE7C,yBAAyB;QACzB,sCAAsC;QAEtC,IAAI,SAAS,KAAK,iBAAiB,EAAE,CAAC;YACrC,WAAW;YACX,sCAAsC;YAEtC,OAAO,UAAU,CAAA;QAClB,CAAC;aAAM,IAAI,SAAS,KAAK,YAAY,EAAE,CAAC;YACvC,WAAW;YACX,2BAA2B;YAC3B,QAAQ;YACR,gEAAgE;YAChE,MAAM;YACN,WAAW;YACX,wDAAwD;YACxD,gCAAgC;YAChC,eAAe;YACf,mEAAmE;YAEnE,oFAAoF;YACpF,MAAM,SAAS,GAAG,qCAAqC,CAAA;YACvD,OAAO,SAAS,CAAC;QAClB,CAAC;aAAM,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,2BAA2B,SAAS,EAAE,CAAC,CAAC;QACzD,CAAC;IACF,CAAC;CACD"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QuerySelectorsFirstInputSchema = exports.QuerySelectorFirstInputSchema = exports.QuerySelectorsInputSchema = exports.QuerySelectorInputSchema = void 0;
|
|
4
1
|
// npm imports
|
|
5
|
-
|
|
2
|
+
import { z } from 'zod';
|
|
6
3
|
///////////////////////////////////////////////////////////////////////////////
|
|
7
4
|
///////////////////////////////////////////////////////////////////////////////
|
|
8
5
|
// Authoritative query selector schemas — shared between the MCP server
|
|
@@ -10,29 +7,29 @@ const zod_1 = require("zod");
|
|
|
10
7
|
// importing the schemas does not execute the CLI's top-level `main()`.
|
|
11
8
|
///////////////////////////////////////////////////////////////////////////////
|
|
12
9
|
///////////////////////////////////////////////////////////////////////////////
|
|
13
|
-
|
|
14
|
-
selector:
|
|
10
|
+
export const QuerySelectorInputSchema = z.object({
|
|
11
|
+
selector: z.string()
|
|
15
12
|
.describe("CSS-like selector to query the accessibility tree"),
|
|
16
|
-
limit:
|
|
13
|
+
limit: z.number()
|
|
17
14
|
.describe("Maximum number of nodes to return (excluding ancestors). Set to 0 for no limit.")
|
|
18
15
|
.default(0),
|
|
19
|
-
withAncestors:
|
|
16
|
+
withAncestors: z.boolean()
|
|
20
17
|
.describe("Whether to include ancestor nodes in the result")
|
|
21
|
-
.default(
|
|
18
|
+
.default(false),
|
|
22
19
|
});
|
|
23
|
-
|
|
24
|
-
selectors:
|
|
20
|
+
export const QuerySelectorsInputSchema = z.object({
|
|
21
|
+
selectors: z.array(QuerySelectorInputSchema)
|
|
25
22
|
.describe("List of selectors to query the accessibility tree"),
|
|
26
23
|
});
|
|
27
|
-
|
|
28
|
-
selector:
|
|
24
|
+
export const QuerySelectorFirstInputSchema = z.object({
|
|
25
|
+
selector: z.string()
|
|
29
26
|
.describe("CSS-like selector to query the accessibility tree"),
|
|
30
|
-
withAncestors:
|
|
27
|
+
withAncestors: z.boolean()
|
|
31
28
|
.describe("Whether to include ancestor nodes in the result")
|
|
32
|
-
.default(
|
|
29
|
+
.default(false),
|
|
33
30
|
});
|
|
34
|
-
|
|
35
|
-
selectors:
|
|
31
|
+
export const QuerySelectorsFirstInputSchema = z.object({
|
|
32
|
+
selectors: z.array(QuerySelectorFirstInputSchema)
|
|
36
33
|
.describe("List of selectors; for each, the first matching node is returned"),
|
|
37
34
|
});
|
|
38
35
|
//# sourceMappingURL=schemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../src/fastbrowser_mcp/libs/schemas.ts"],"names":[],"mappings":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,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
+
|
|
4
|
+
async function main() {
|
|
5
|
+
// Note: the PLAYWRIGHT_MCP_EXTENSION_TOKEN environment variable is required to authenticate with the Playwright MCP extension.
|
|
6
|
+
const client = new Client({
|
|
7
|
+
name: 'foobar',
|
|
8
|
+
version: '0.1.0',
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const transport = new StdioClientTransport({
|
|
12
|
+
command: 'npx',
|
|
13
|
+
args: ["@playwright/mcp", "--extension"],
|
|
14
|
+
env: {
|
|
15
|
+
PLAYWRIGHT_MCP_EXTENSION_TOKEN: 'd-dwfALmOesZLoS7i-ia8Wf7TWrHtlRMHuVCqAUuiKU'
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
console.log("Connecting to MCP server...");
|
|
19
|
+
await client.connect(transport);
|
|
20
|
+
console.log("Connected!");
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const listToolsResult = await client.listTools()
|
|
24
|
+
console.log("Available tools:", listToolsResult.tools.map(tool => tool.name));
|
|
25
|
+
|
|
26
|
+
// const toolResult = await client.callTool({
|
|
27
|
+
// name: '',
|
|
28
|
+
// arguments: args
|
|
29
|
+
// })
|
|
30
|
+
|
|
31
|
+
await client.close();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
void main();
|