@andrew-chen-wang/camoufox-mcp 0.0.1
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/config.d.ts +41 -0
- package/index.d.ts +22 -0
- package/index.js +1 -0
- package/lib/browserContextFactory.js +178 -0
- package/lib/config.js +204 -0
- package/lib/connection.js +84 -0
- package/lib/context.js +361 -0
- package/lib/fileUtils.js +32 -0
- package/lib/index.js +66 -0
- package/lib/javascript.js +49 -0
- package/lib/manualPromise.js +111 -0
- package/lib/mcpHttpServer.js +90 -0
- package/lib/package.js +20 -0
- package/lib/pageSnapshot.js +44 -0
- package/lib/resources/resource.js +16 -0
- package/lib/server.js +48 -0
- package/lib/tab.js +107 -0
- package/lib/tools/common.js +68 -0
- package/lib/tools/console.js +77 -0
- package/lib/tools/devtools.js +189 -0
- package/lib/tools/dialogs.js +52 -0
- package/lib/tools/files.js +51 -0
- package/lib/tools/forms.js +67 -0
- package/lib/tools/install.js +57 -0
- package/lib/tools/keyboard.js +158 -0
- package/lib/tools/mouse.js +119 -0
- package/lib/tools/navigate.js +117 -0
- package/lib/tools/network.js +197 -0
- package/lib/tools/pdf.js +49 -0
- package/lib/tools/screenshot.js +80 -0
- package/lib/tools/snapshot.js +307 -0
- package/lib/tools/storage.js +344 -0
- package/lib/tools/tabs.js +172 -0
- package/lib/tools/testing.js +60 -0
- package/lib/tools/tool.js +18 -0
- package/lib/tools/utils.js +87 -0
- package/lib/tools/vision.js +189 -0
- package/lib/tools/wait.js +59 -0
- package/lib/tools.js +73 -0
- package/package.json +48 -0
|
@@ -0,0 +1,189 @@
|
|
|
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
|
+
import * as javascript from '../javascript.js';
|
|
19
|
+
const elementSchema = z.object({
|
|
20
|
+
element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
|
|
21
|
+
});
|
|
22
|
+
const screenshot = defineTool({
|
|
23
|
+
capability: 'core',
|
|
24
|
+
schema: {
|
|
25
|
+
name: 'browser_screen_capture',
|
|
26
|
+
title: 'Take a screenshot',
|
|
27
|
+
description: 'Take a screenshot of the current page',
|
|
28
|
+
inputSchema: z.object({}),
|
|
29
|
+
type: 'readOnly',
|
|
30
|
+
},
|
|
31
|
+
handle: async (context) => {
|
|
32
|
+
const tab = await context.ensureTab();
|
|
33
|
+
const options = { type: 'jpeg', quality: 50, scale: 'css' };
|
|
34
|
+
const code = [
|
|
35
|
+
`// Take a screenshot of the current page`,
|
|
36
|
+
`await page.screenshot(${javascript.formatObject(options)});`,
|
|
37
|
+
];
|
|
38
|
+
const action = () => tab.page.screenshot(options).then(buffer => {
|
|
39
|
+
return {
|
|
40
|
+
content: [{ type: 'image', data: buffer.toString('base64'), mimeType: 'image/jpeg' }],
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
code,
|
|
45
|
+
action,
|
|
46
|
+
captureSnapshot: false,
|
|
47
|
+
waitForNetwork: false
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
const moveMouse = defineTool({
|
|
52
|
+
capability: 'core',
|
|
53
|
+
schema: {
|
|
54
|
+
name: 'browser_screen_move_mouse',
|
|
55
|
+
title: 'Move mouse',
|
|
56
|
+
description: 'Move mouse to a given position',
|
|
57
|
+
inputSchema: elementSchema.extend({
|
|
58
|
+
x: z.number().describe('X coordinate'),
|
|
59
|
+
y: z.number().describe('Y coordinate'),
|
|
60
|
+
}),
|
|
61
|
+
type: 'readOnly',
|
|
62
|
+
},
|
|
63
|
+
handle: async (context, params) => {
|
|
64
|
+
const tab = context.currentTabOrDie();
|
|
65
|
+
const code = [
|
|
66
|
+
`// Move mouse to (${params.x}, ${params.y})`,
|
|
67
|
+
`await page.mouse.move(${params.x}, ${params.y});`,
|
|
68
|
+
];
|
|
69
|
+
const action = () => tab.page.mouse.move(params.x, params.y);
|
|
70
|
+
return {
|
|
71
|
+
code,
|
|
72
|
+
action,
|
|
73
|
+
captureSnapshot: false,
|
|
74
|
+
waitForNetwork: false
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
const click = defineTool({
|
|
79
|
+
capability: 'core',
|
|
80
|
+
schema: {
|
|
81
|
+
name: 'browser_screen_click',
|
|
82
|
+
title: 'Click',
|
|
83
|
+
description: 'Click left mouse button',
|
|
84
|
+
inputSchema: elementSchema.extend({
|
|
85
|
+
x: z.number().describe('X coordinate'),
|
|
86
|
+
y: z.number().describe('Y coordinate'),
|
|
87
|
+
}),
|
|
88
|
+
type: 'destructive',
|
|
89
|
+
},
|
|
90
|
+
handle: async (context, params) => {
|
|
91
|
+
const tab = context.currentTabOrDie();
|
|
92
|
+
const code = [
|
|
93
|
+
`// Click mouse at coordinates (${params.x}, ${params.y})`,
|
|
94
|
+
`await page.mouse.move(${params.x}, ${params.y});`,
|
|
95
|
+
`await page.mouse.down();`,
|
|
96
|
+
`await page.mouse.up();`,
|
|
97
|
+
];
|
|
98
|
+
const action = async () => {
|
|
99
|
+
await tab.page.mouse.move(params.x, params.y);
|
|
100
|
+
await tab.page.mouse.down();
|
|
101
|
+
await tab.page.mouse.up();
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
code,
|
|
105
|
+
action,
|
|
106
|
+
captureSnapshot: false,
|
|
107
|
+
waitForNetwork: true,
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
const drag = defineTool({
|
|
112
|
+
capability: 'core',
|
|
113
|
+
schema: {
|
|
114
|
+
name: 'browser_screen_drag',
|
|
115
|
+
title: 'Drag mouse',
|
|
116
|
+
description: 'Drag left mouse button',
|
|
117
|
+
inputSchema: elementSchema.extend({
|
|
118
|
+
startX: z.number().describe('Start X coordinate'),
|
|
119
|
+
startY: z.number().describe('Start Y coordinate'),
|
|
120
|
+
endX: z.number().describe('End X coordinate'),
|
|
121
|
+
endY: z.number().describe('End Y coordinate'),
|
|
122
|
+
}),
|
|
123
|
+
type: 'destructive',
|
|
124
|
+
},
|
|
125
|
+
handle: async (context, params) => {
|
|
126
|
+
const tab = context.currentTabOrDie();
|
|
127
|
+
const code = [
|
|
128
|
+
`// Drag mouse from (${params.startX}, ${params.startY}) to (${params.endX}, ${params.endY})`,
|
|
129
|
+
`await page.mouse.move(${params.startX}, ${params.startY});`,
|
|
130
|
+
`await page.mouse.down();`,
|
|
131
|
+
`await page.mouse.move(${params.endX}, ${params.endY});`,
|
|
132
|
+
`await page.mouse.up();`,
|
|
133
|
+
];
|
|
134
|
+
const action = async () => {
|
|
135
|
+
await tab.page.mouse.move(params.startX, params.startY);
|
|
136
|
+
await tab.page.mouse.down();
|
|
137
|
+
await tab.page.mouse.move(params.endX, params.endY);
|
|
138
|
+
await tab.page.mouse.up();
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
code,
|
|
142
|
+
action,
|
|
143
|
+
captureSnapshot: false,
|
|
144
|
+
waitForNetwork: true,
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
const type = defineTool({
|
|
149
|
+
capability: 'core',
|
|
150
|
+
schema: {
|
|
151
|
+
name: 'browser_screen_type',
|
|
152
|
+
title: 'Type text',
|
|
153
|
+
description: 'Type text',
|
|
154
|
+
inputSchema: z.object({
|
|
155
|
+
text: z.string().describe('Text to type into the element'),
|
|
156
|
+
submit: z.boolean().optional().describe('Whether to submit entered text (press Enter after)'),
|
|
157
|
+
}),
|
|
158
|
+
type: 'destructive',
|
|
159
|
+
},
|
|
160
|
+
handle: async (context, params) => {
|
|
161
|
+
const tab = context.currentTabOrDie();
|
|
162
|
+
const code = [
|
|
163
|
+
`// Type ${params.text}`,
|
|
164
|
+
`await page.keyboard.type('${params.text}');`,
|
|
165
|
+
];
|
|
166
|
+
const action = async () => {
|
|
167
|
+
await tab.page.keyboard.type(params.text);
|
|
168
|
+
if (params.submit)
|
|
169
|
+
await tab.page.keyboard.press('Enter');
|
|
170
|
+
};
|
|
171
|
+
if (params.submit) {
|
|
172
|
+
code.push(`// Submit text`);
|
|
173
|
+
code.push(`await page.keyboard.press('Enter');`);
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
code,
|
|
177
|
+
action,
|
|
178
|
+
captureSnapshot: false,
|
|
179
|
+
waitForNetwork: true,
|
|
180
|
+
};
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
export default [
|
|
184
|
+
screenshot,
|
|
185
|
+
moveMouse,
|
|
186
|
+
click,
|
|
187
|
+
drag,
|
|
188
|
+
type,
|
|
189
|
+
];
|
|
@@ -0,0 +1,59 @@
|
|
|
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 = captureSnapshot => defineTool({
|
|
19
|
+
capability: 'wait',
|
|
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) => {
|
|
32
|
+
if (!params.text && !params.textGone && !params.time)
|
|
33
|
+
throw new Error('Either time, text or textGone must be provided');
|
|
34
|
+
const code = [];
|
|
35
|
+
if (params.time) {
|
|
36
|
+
code.push(`await new Promise(f => setTimeout(f, ${params.time} * 1000));`);
|
|
37
|
+
await new Promise(f => setTimeout(f, Math.min(10000, params.time * 1000)));
|
|
38
|
+
}
|
|
39
|
+
const tab = context.currentTabOrDie();
|
|
40
|
+
const locator = params.text ? tab.page.getByText(params.text).first() : undefined;
|
|
41
|
+
const goneLocator = params.textGone ? tab.page.getByText(params.textGone).first() : undefined;
|
|
42
|
+
if (goneLocator) {
|
|
43
|
+
code.push(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`);
|
|
44
|
+
await goneLocator.waitFor({ state: 'hidden' });
|
|
45
|
+
}
|
|
46
|
+
if (locator) {
|
|
47
|
+
code.push(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`);
|
|
48
|
+
await locator.waitFor({ state: 'visible' });
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
code,
|
|
52
|
+
captureSnapshot,
|
|
53
|
+
waitForNetwork: false,
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
export default (captureSnapshot) => [
|
|
58
|
+
wait(captureSnapshot),
|
|
59
|
+
];
|
package/lib/tools.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
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 devtools from './tools/devtools.js';
|
|
19
|
+
import dialogs from './tools/dialogs.js';
|
|
20
|
+
import files from './tools/files.js';
|
|
21
|
+
import forms from './tools/forms.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 storage from './tools/storage.js';
|
|
30
|
+
import tabs from './tools/tabs.js';
|
|
31
|
+
import screenshot from './tools/screenshot.js';
|
|
32
|
+
import testing from './tools/testing.js';
|
|
33
|
+
import vision from './tools/vision.js';
|
|
34
|
+
import wait from './tools/wait.js';
|
|
35
|
+
export const snapshotTools = [
|
|
36
|
+
...common(true),
|
|
37
|
+
...console,
|
|
38
|
+
...dialogs(true),
|
|
39
|
+
...files(true),
|
|
40
|
+
...forms,
|
|
41
|
+
...install,
|
|
42
|
+
...keyboard(true),
|
|
43
|
+
...mouse(true),
|
|
44
|
+
...navigate(true),
|
|
45
|
+
...network,
|
|
46
|
+
...pdf,
|
|
47
|
+
...screenshot,
|
|
48
|
+
...snapshot,
|
|
49
|
+
...storage,
|
|
50
|
+
...tabs(true),
|
|
51
|
+
...testing,
|
|
52
|
+
...devtools,
|
|
53
|
+
...wait(true),
|
|
54
|
+
];
|
|
55
|
+
export const visionTools = [
|
|
56
|
+
...common(false),
|
|
57
|
+
...console,
|
|
58
|
+
...dialogs(false),
|
|
59
|
+
...files(false),
|
|
60
|
+
...forms,
|
|
61
|
+
...install,
|
|
62
|
+
...keyboard(false),
|
|
63
|
+
...mouse(false),
|
|
64
|
+
...navigate(false),
|
|
65
|
+
...network,
|
|
66
|
+
...pdf,
|
|
67
|
+
...storage,
|
|
68
|
+
...tabs(false),
|
|
69
|
+
...testing,
|
|
70
|
+
...devtools,
|
|
71
|
+
...vision,
|
|
72
|
+
...wait(false),
|
|
73
|
+
];
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@andrew-chen-wang/camoufox-mcp",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Camoufox-backed MCP browser automation server",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Andrew-Chen-Wang/camoufox-mcp.git"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=18"
|
|
12
|
+
},
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"clean": "rm -rf lib",
|
|
17
|
+
"test": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
"./package.json": "./package.json",
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./index.d.ts",
|
|
23
|
+
"default": "./index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"lib",
|
|
28
|
+
"index.js",
|
|
29
|
+
"index.d.ts",
|
|
30
|
+
"config.d.ts",
|
|
31
|
+
"package.json"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
35
|
+
"camoufox-js": "^0.9.3",
|
|
36
|
+
"debug": "^4.4.1",
|
|
37
|
+
"mime": "^4.1.0",
|
|
38
|
+
"playwright-core": "^1.53.0",
|
|
39
|
+
"ws": "^8.18.1",
|
|
40
|
+
"zod": "^3.25.76",
|
|
41
|
+
"zod-to-json-schema": "^3.24.6"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/debug": "^4.1.12",
|
|
45
|
+
"@types/node": "^22.15.30",
|
|
46
|
+
"typescript": "^5.8.3"
|
|
47
|
+
}
|
|
48
|
+
}
|