botbrowser-mcp 0.1.7 → 0.1.9
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/dist/index.d.ts +2 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/tools/account.d.ts +5 -0
- package/dist/tools/account.js +84 -54
- package/dist/tools/account.js.map +1 -1
- package/dist/tools/instance.d.ts +6 -1
- package/dist/tools/instance.js +80 -50
- package/dist/tools/instance.js.map +1 -1
- package/dist/tools/playwright-mcp-proxy.d.ts +6 -2
- package/dist/tools/playwright-mcp-proxy.js +58 -6
- package/dist/tools/playwright-mcp-proxy.js.map +1 -1
- package/dist/tools/profile.d.ts +12 -0
- package/dist/tools/profile.js +76 -52
- package/dist/tools/profile.js.map +1 -1
- package/package.json +1 -1
- package/readme.md +49 -6
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -13,8 +13,8 @@ import { instanceTools, setManager as setInstanceManager } from './tools/instanc
|
|
|
13
13
|
import { PlaywrightMCPProxy } from './tools/playwright-mcp-proxy.js';
|
|
14
14
|
// 初始化数据库
|
|
15
15
|
initDatabase();
|
|
16
|
-
// 创建 Playwright
|
|
17
|
-
const manager = new PlaywrightManager();
|
|
16
|
+
// 创建 Playwright 管理器并导出(供 playwright-mcp-proxy 访问)
|
|
17
|
+
export const manager = new PlaywrightManager();
|
|
18
18
|
setInstanceManager(manager);
|
|
19
19
|
// 创建 Playwright MCP 代理并导出为全局变量(供 switch_browser_instance 使用)
|
|
20
20
|
export const playwrightMCPProxy = new PlaywrightMCPProxy(async () => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;GAEG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF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,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/tools/account.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare const accountTools: {
|
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
required: string[];
|
|
21
|
+
additionalProperties: boolean;
|
|
21
22
|
};
|
|
22
23
|
handler: (args: any) => Promise<{
|
|
23
24
|
content: {
|
|
@@ -36,6 +37,7 @@ export declare const accountTools: {
|
|
|
36
37
|
description: string;
|
|
37
38
|
};
|
|
38
39
|
};
|
|
40
|
+
additionalProperties: boolean;
|
|
39
41
|
};
|
|
40
42
|
handler: (args: any) => Promise<{
|
|
41
43
|
content: {
|
|
@@ -59,6 +61,7 @@ export declare const accountTools: {
|
|
|
59
61
|
};
|
|
60
62
|
};
|
|
61
63
|
required: string[];
|
|
64
|
+
additionalProperties: boolean;
|
|
62
65
|
};
|
|
63
66
|
handler: (args: any) => Promise<{
|
|
64
67
|
content: {
|
|
@@ -86,6 +89,7 @@ export declare const accountTools: {
|
|
|
86
89
|
};
|
|
87
90
|
};
|
|
88
91
|
required: string[];
|
|
92
|
+
additionalProperties: boolean;
|
|
89
93
|
};
|
|
90
94
|
handler: (args: any) => Promise<{
|
|
91
95
|
content: {
|
|
@@ -105,6 +109,7 @@ export declare const accountTools: {
|
|
|
105
109
|
};
|
|
106
110
|
};
|
|
107
111
|
required: string[];
|
|
112
|
+
additionalProperties: boolean;
|
|
108
113
|
};
|
|
109
114
|
handler: (args: any) => Promise<{
|
|
110
115
|
content: {
|
package/dist/tools/account.js
CHANGED
|
@@ -1,109 +1,139 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Account management tools
|
|
3
3
|
*/
|
|
4
4
|
import { AccountRepository } from '../db/repositories/account.js';
|
|
5
5
|
const accountRepo = new AccountRepository();
|
|
6
6
|
export const accountTools = {
|
|
7
7
|
add_account: {
|
|
8
|
-
description: '
|
|
8
|
+
description: 'Add an account to a browser profile with flexible metadata storage',
|
|
9
9
|
inputSchema: {
|
|
10
10
|
type: 'object',
|
|
11
11
|
properties: {
|
|
12
|
-
profile_alias: { type: 'string', description: '
|
|
13
|
-
username: { type: 'string', description: '
|
|
14
|
-
metadata: { type: 'string', description: '
|
|
12
|
+
profile_alias: { type: 'string', description: 'Browser profile alias' },
|
|
13
|
+
username: { type: 'string', description: 'Account username or identifier' },
|
|
14
|
+
metadata: { type: 'string', description: 'Account metadata (password, email, 2FA, etc.) in any format - key-value, JSON, or natural language' },
|
|
15
15
|
},
|
|
16
16
|
required: ['profile_alias', 'username'],
|
|
17
|
+
additionalProperties: false,
|
|
17
18
|
},
|
|
18
19
|
handler: async (args) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
try {
|
|
21
|
+
const id = accountRepo.create(args);
|
|
22
|
+
return {
|
|
23
|
+
content: [{
|
|
24
|
+
type: 'text',
|
|
25
|
+
text: `Account "${args.username}" added successfully with ID: ${id}`,
|
|
26
|
+
}],
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
throw new Error(`Failed to add account: ${error instanceof Error ? error.message : String(error)}`);
|
|
31
|
+
}
|
|
26
32
|
},
|
|
27
33
|
},
|
|
28
34
|
list_accounts: {
|
|
29
|
-
description: '
|
|
35
|
+
description: 'List all accounts or accounts for a specific profile',
|
|
30
36
|
inputSchema: {
|
|
31
37
|
type: 'object',
|
|
32
38
|
properties: {
|
|
33
|
-
profile_alias: { type: 'string', description: '
|
|
39
|
+
profile_alias: { type: 'string', description: 'Filter by browser profile alias (optional)' },
|
|
34
40
|
},
|
|
41
|
+
additionalProperties: false,
|
|
35
42
|
},
|
|
36
43
|
handler: async (args) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
try {
|
|
45
|
+
const accounts = args.profile_alias
|
|
46
|
+
? accountRepo.getByProfile(args.profile_alias)
|
|
47
|
+
: accountRepo.getAll();
|
|
48
|
+
return {
|
|
49
|
+
content: [{
|
|
50
|
+
type: 'text',
|
|
51
|
+
text: JSON.stringify(accounts, null, 2),
|
|
52
|
+
}],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw new Error(`Failed to list accounts: ${error instanceof Error ? error.message : String(error)}`);
|
|
57
|
+
}
|
|
46
58
|
},
|
|
47
59
|
},
|
|
48
60
|
find_account: {
|
|
49
|
-
description: '
|
|
61
|
+
description: 'Find a specific account by username within a profile',
|
|
50
62
|
inputSchema: {
|
|
51
63
|
type: 'object',
|
|
52
64
|
properties: {
|
|
53
|
-
profile_alias: { type: 'string', description: '
|
|
54
|
-
username: { type: 'string', description: '
|
|
65
|
+
profile_alias: { type: 'string', description: 'Browser profile alias' },
|
|
66
|
+
username: { type: 'string', description: 'Account username to search for' },
|
|
55
67
|
},
|
|
56
68
|
required: ['profile_alias', 'username'],
|
|
69
|
+
additionalProperties: false,
|
|
57
70
|
},
|
|
58
71
|
handler: async (args) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
try {
|
|
73
|
+
const account = accountRepo.findByUsername(args.profile_alias, args.username);
|
|
74
|
+
return {
|
|
75
|
+
content: [{
|
|
76
|
+
type: 'text',
|
|
77
|
+
text: account ? JSON.stringify(account, null, 2) : 'Account not found',
|
|
78
|
+
}],
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
throw new Error(`Failed to find account: ${error instanceof Error ? error.message : String(error)}`);
|
|
83
|
+
}
|
|
66
84
|
},
|
|
67
85
|
},
|
|
68
86
|
update_account: {
|
|
69
|
-
description: '
|
|
87
|
+
description: 'Update account information',
|
|
70
88
|
inputSchema: {
|
|
71
89
|
type: 'object',
|
|
72
90
|
properties: {
|
|
73
|
-
id: { type: 'number', description: '
|
|
74
|
-
username: { type: 'string', description: '
|
|
75
|
-
metadata: { type: 'string', description: '
|
|
91
|
+
id: { type: 'number', description: 'Account ID' },
|
|
92
|
+
username: { type: 'string', description: 'New username' },
|
|
93
|
+
metadata: { type: 'string', description: 'New metadata' },
|
|
76
94
|
},
|
|
77
95
|
required: ['id'],
|
|
96
|
+
additionalProperties: false,
|
|
78
97
|
},
|
|
79
98
|
handler: async (args) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
99
|
+
try {
|
|
100
|
+
const { id, ...updates } = args;
|
|
101
|
+
accountRepo.update(id, updates);
|
|
102
|
+
return {
|
|
103
|
+
content: [{
|
|
104
|
+
type: 'text',
|
|
105
|
+
text: `Account ${id} updated successfully`,
|
|
106
|
+
}],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
throw new Error(`Failed to update account: ${error instanceof Error ? error.message : String(error)}`);
|
|
111
|
+
}
|
|
88
112
|
},
|
|
89
113
|
},
|
|
90
114
|
delete_account: {
|
|
91
|
-
description: '
|
|
115
|
+
description: 'Delete an account',
|
|
92
116
|
inputSchema: {
|
|
93
117
|
type: 'object',
|
|
94
118
|
properties: {
|
|
95
|
-
id: { type: 'number', description: '
|
|
119
|
+
id: { type: 'number', description: 'Account ID to delete' },
|
|
96
120
|
},
|
|
97
121
|
required: ['id'],
|
|
122
|
+
additionalProperties: false,
|
|
98
123
|
},
|
|
99
124
|
handler: async (args) => {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
125
|
+
try {
|
|
126
|
+
accountRepo.delete(args.id);
|
|
127
|
+
return {
|
|
128
|
+
content: [{
|
|
129
|
+
type: 'text',
|
|
130
|
+
text: `Account ${args.id} deleted successfully`,
|
|
131
|
+
}],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
throw new Error(`Failed to delete account: ${error instanceof Error ? error.message : String(error)}`);
|
|
136
|
+
}
|
|
107
137
|
},
|
|
108
138
|
},
|
|
109
139
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/tools/account.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,MAAM,WAAW,GAAG,IAAI,iBAAiB,EAAE,CAAC;AAE5C,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,WAAW,EAAE;QACX,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/tools/account.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,MAAM,WAAW,GAAG,IAAI,iBAAiB,EAAE,CAAC;AAE5C,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,WAAW,EAAE;QACX,WAAW,EAAE,oEAAoE;QACjF,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,aAAa,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,uBAAuB,EAAE;gBACvE,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,gCAAgC,EAAE;gBAC3E,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW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M,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC5B,OAAO;oBACL,OAAO,EAAE,CAAC;4BACR,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,WAAW,IAAI,CAAC,EAAE,uBAAuB;yBAChD,CAAC;iBACH,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CAAC,6BAA6B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACzG,CAAC;QACH,CAAC;KACF;CACF,CAAC"}
|
package/dist/tools/instance.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Browser instance management tools
|
|
3
3
|
*/
|
|
4
4
|
import { PlaywrightManager } from '../playwright/manager.js';
|
|
5
5
|
export declare function setManager(m: PlaywrightManager): void;
|
|
@@ -24,6 +24,7 @@ export declare const instanceTools: {
|
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
required: string[];
|
|
27
|
+
additionalProperties: boolean;
|
|
27
28
|
};
|
|
28
29
|
handler: (args: any) => Promise<{
|
|
29
30
|
content: {
|
|
@@ -37,6 +38,7 @@ export declare const instanceTools: {
|
|
|
37
38
|
inputSchema: {
|
|
38
39
|
type: string;
|
|
39
40
|
properties: {};
|
|
41
|
+
additionalProperties: boolean;
|
|
40
42
|
};
|
|
41
43
|
handler: () => Promise<{
|
|
42
44
|
content: {
|
|
@@ -56,6 +58,7 @@ export declare const instanceTools: {
|
|
|
56
58
|
};
|
|
57
59
|
};
|
|
58
60
|
required: string[];
|
|
61
|
+
additionalProperties: boolean;
|
|
59
62
|
};
|
|
60
63
|
handler: (args: any) => Promise<{
|
|
61
64
|
content: {
|
|
@@ -75,6 +78,7 @@ export declare const instanceTools: {
|
|
|
75
78
|
};
|
|
76
79
|
};
|
|
77
80
|
required: string[];
|
|
81
|
+
additionalProperties: boolean;
|
|
78
82
|
};
|
|
79
83
|
handler: (args: any) => Promise<{
|
|
80
84
|
content: {
|
|
@@ -88,6 +92,7 @@ export declare const instanceTools: {
|
|
|
88
92
|
inputSchema: {
|
|
89
93
|
type: string;
|
|
90
94
|
properties: {};
|
|
95
|
+
additionalProperties: boolean;
|
|
91
96
|
};
|
|
92
97
|
handler: () => Promise<{
|
|
93
98
|
content: {
|
package/dist/tools/instance.js
CHANGED
|
@@ -4,104 +4,134 @@ export function setManager(m) {
|
|
|
4
4
|
}
|
|
5
5
|
export const instanceTools = {
|
|
6
6
|
launch_browser: {
|
|
7
|
-
description: '
|
|
7
|
+
description: 'Launch a new browser instance based on a profile configuration',
|
|
8
8
|
inputSchema: {
|
|
9
9
|
type: 'object',
|
|
10
10
|
properties: {
|
|
11
|
-
profile_alias: { type: 'string', description: '
|
|
12
|
-
account_id: { type: 'number', description: '
|
|
11
|
+
profile_alias: { type: 'string', description: 'Browser profile alias to use' },
|
|
12
|
+
account_id: { type: 'number', description: 'Optional account ID to associate with this instance' },
|
|
13
13
|
launch_options: {
|
|
14
14
|
type: 'object',
|
|
15
|
-
description: 'Playwright
|
|
15
|
+
description: 'Optional Playwright launch options (e.g., {"headless": false, "channel": "chrome"})',
|
|
16
16
|
additionalProperties: true,
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
required: ['profile_alias'],
|
|
20
|
+
additionalProperties: false,
|
|
20
21
|
},
|
|
21
22
|
handler: async (args) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
try {
|
|
24
|
+
const id = await manager.launchInstance(args.profile_alias, args.account_id, args.launch_options);
|
|
25
|
+
return {
|
|
26
|
+
content: [{
|
|
27
|
+
type: 'text',
|
|
28
|
+
text: `Browser instance ${id} launched successfully`,
|
|
29
|
+
}],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
throw new Error(`Failed to launch browser: ${error instanceof Error ? error.message : String(error)}`);
|
|
34
|
+
}
|
|
29
35
|
},
|
|
30
36
|
},
|
|
31
37
|
list_browser_instances: {
|
|
32
|
-
description: '
|
|
38
|
+
description: 'List all running browser instances with their status',
|
|
33
39
|
inputSchema: {
|
|
34
40
|
type: 'object',
|
|
35
41
|
properties: {},
|
|
42
|
+
additionalProperties: false,
|
|
36
43
|
},
|
|
37
44
|
handler: async () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
try {
|
|
46
|
+
const instances = manager.listInstances();
|
|
47
|
+
return {
|
|
48
|
+
content: [{
|
|
49
|
+
type: 'text',
|
|
50
|
+
text: JSON.stringify(instances, null, 2),
|
|
51
|
+
}],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
throw new Error(`Failed to list instances: ${error instanceof Error ? error.message : String(error)}`);
|
|
56
|
+
}
|
|
45
57
|
},
|
|
46
58
|
},
|
|
47
59
|
switch_browser_instance: {
|
|
48
|
-
description: '
|
|
60
|
+
description: 'Switch the active browser instance. All subsequent browser operations will run on the switched instance',
|
|
49
61
|
inputSchema: {
|
|
50
62
|
type: 'object',
|
|
51
63
|
properties: {
|
|
52
|
-
instance_id: { type: 'number', description: '
|
|
64
|
+
instance_id: { type: 'number', description: 'Instance ID to switch to' },
|
|
53
65
|
},
|
|
54
66
|
required: ['instance_id'],
|
|
67
|
+
additionalProperties: false,
|
|
55
68
|
},
|
|
56
69
|
handler: async (args) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
try {
|
|
71
|
+
await manager.switchActive(args.instance_id);
|
|
72
|
+
// CRITICAL: Reset Playwright MCP's context cache
|
|
73
|
+
// This forces it to fetch the new active context on the next tool call
|
|
74
|
+
const { playwrightMCPProxy } = await import('../index.js');
|
|
75
|
+
if (playwrightMCPProxy) {
|
|
76
|
+
await playwrightMCPProxy.resetContext();
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
content: [{
|
|
80
|
+
type: 'text',
|
|
81
|
+
text: `Switched to instance ${args.instance_id}`,
|
|
82
|
+
}],
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw new Error(`Failed to switch instance: ${error instanceof Error ? error.message : String(error)}`);
|
|
63
87
|
}
|
|
64
|
-
return {
|
|
65
|
-
content: [{
|
|
66
|
-
type: 'text',
|
|
67
|
-
text: `已切换到实例 ${args.instance_id}`,
|
|
68
|
-
}],
|
|
69
|
-
};
|
|
70
88
|
},
|
|
71
89
|
},
|
|
72
90
|
stop_browser_instance: {
|
|
73
|
-
description: '
|
|
91
|
+
description: 'Stop a running browser instance and save its state',
|
|
74
92
|
inputSchema: {
|
|
75
93
|
type: 'object',
|
|
76
94
|
properties: {
|
|
77
|
-
instance_id: { type: 'number', description: '
|
|
95
|
+
instance_id: { type: 'number', description: 'Instance ID to stop' },
|
|
78
96
|
},
|
|
79
97
|
required: ['instance_id'],
|
|
98
|
+
additionalProperties: false,
|
|
80
99
|
},
|
|
81
100
|
handler: async (args) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
101
|
+
try {
|
|
102
|
+
await manager.stopInstance(args.instance_id);
|
|
103
|
+
return {
|
|
104
|
+
content: [{
|
|
105
|
+
type: 'text',
|
|
106
|
+
text: `Instance ${args.instance_id} stopped successfully`,
|
|
107
|
+
}],
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
throw new Error(`Failed to stop instance: ${error instanceof Error ? error.message : String(error)}`);
|
|
112
|
+
}
|
|
89
113
|
},
|
|
90
114
|
},
|
|
91
115
|
cleanup_orphaned_instances: {
|
|
92
|
-
description: '
|
|
116
|
+
description: 'Clean up orphaned instance records (database entries for instances that are no longer running)',
|
|
93
117
|
inputSchema: {
|
|
94
118
|
type: 'object',
|
|
95
119
|
properties: {},
|
|
120
|
+
additionalProperties: false,
|
|
96
121
|
},
|
|
97
122
|
handler: async () => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
123
|
+
try {
|
|
124
|
+
const count = await manager.cleanupOrphaned();
|
|
125
|
+
return {
|
|
126
|
+
content: [{
|
|
127
|
+
type: 'text',
|
|
128
|
+
text: `Cleaned up ${count} orphaned instance record(s)`,
|
|
129
|
+
}],
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
throw new Error(`Failed to cleanup orphaned instances: ${error instanceof Error ? error.message : String(error)}`);
|
|
134
|
+
}
|
|
105
135
|
},
|
|
106
136
|
},
|
|
107
137
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instance.js","sourceRoot":"","sources":["../../src/tools/instance.ts"],"names":[],"mappings":"AAKA,IAAI,OAA0B,CAAC;AAE/B,MAAM,UAAU,UAAU,CAAC,CAAoB;IAC7C,OAAO,GAAG,CAAC,CAAC;AACd,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,cAAc,EAAE;QACd,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"instance.js","sourceRoot":"","sources":["../../src/tools/instance.ts"],"names":[],"mappings":"AAKA,IAAI,OAA0B,CAAC;AAE/B,MAAM,UAAU,UAAU,CAAC,CAAoB;IAC7C,OAAO,GAAG,CAAC,CAAC;AACd,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,cAAc,EAAE;QACd,WAAW,EAAE,gEAAgE;QAC7E,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,aAAa,EAAE,EAAE,I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,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACrH,CAAC;QACH,CAAC;KACF;CACF,CAAC"}
|
|
@@ -30,13 +30,17 @@ export declare class PlaywrightMCPProxy {
|
|
|
30
30
|
private loadTools;
|
|
31
31
|
/**
|
|
32
32
|
* Get all tool definitions for MCP protocol
|
|
33
|
+
*
|
|
34
|
+
* Adds optional instance_id parameter to all browser tools,
|
|
35
|
+
* allowing AI agents to directly specify which browser instance to operate on.
|
|
33
36
|
*/
|
|
34
37
|
getToolDefinitions(): Record<string, any>;
|
|
35
38
|
/**
|
|
36
39
|
* Call a Playwright MCP tool
|
|
37
40
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
41
|
+
* If instance_id is provided in args, temporarily switches to that instance,
|
|
42
|
+
* executes the tool, then restores the previous active instance.
|
|
43
|
+
* This allows AI agents to specify which browser to operate on directly.
|
|
40
44
|
*/
|
|
41
45
|
callTool(name: string, args: any): Promise<any>;
|
|
42
46
|
/**
|
|
@@ -130,13 +130,26 @@ export class PlaywrightMCPProxy {
|
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
132
132
|
* Get all tool definitions for MCP protocol
|
|
133
|
+
*
|
|
134
|
+
* Adds optional instance_id parameter to all browser tools,
|
|
135
|
+
* allowing AI agents to directly specify which browser instance to operate on.
|
|
133
136
|
*/
|
|
134
137
|
getToolDefinitions() {
|
|
135
138
|
const handlers = {};
|
|
136
139
|
for (const [name, tool] of this.tools) {
|
|
140
|
+
// Clone the original inputSchema and add instance_id parameter
|
|
141
|
+
const enhancedSchema = JSON.parse(JSON.stringify(tool.inputSchema || {}));
|
|
142
|
+
if (!enhancedSchema.properties) {
|
|
143
|
+
enhancedSchema.properties = {};
|
|
144
|
+
}
|
|
145
|
+
// Add instance_id parameter to all browser tools
|
|
146
|
+
enhancedSchema.properties.instance_id = {
|
|
147
|
+
type: 'number',
|
|
148
|
+
description: 'Optional browser instance ID to operate on. If not specified, uses the currently active instance. Use list_browser_instances to see available instances.'
|
|
149
|
+
};
|
|
137
150
|
handlers[name] = {
|
|
138
|
-
description: tool.description
|
|
139
|
-
inputSchema:
|
|
151
|
+
description: `${tool.description} (Supports multi-instance via instance_id parameter)`,
|
|
152
|
+
inputSchema: enhancedSchema,
|
|
140
153
|
handler: async (args) => {
|
|
141
154
|
return await this.callTool(name, args);
|
|
142
155
|
}
|
|
@@ -147,8 +160,9 @@ export class PlaywrightMCPProxy {
|
|
|
147
160
|
/**
|
|
148
161
|
* Call a Playwright MCP tool
|
|
149
162
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
163
|
+
* If instance_id is provided in args, temporarily switches to that instance,
|
|
164
|
+
* executes the tool, then restores the previous active instance.
|
|
165
|
+
* This allows AI agents to specify which browser to operate on directly.
|
|
152
166
|
*/
|
|
153
167
|
async callTool(name, args) {
|
|
154
168
|
if (!this.mcpServer) {
|
|
@@ -157,18 +171,41 @@ export class PlaywrightMCPProxy {
|
|
|
157
171
|
if (!this.tools.has(name)) {
|
|
158
172
|
throw new Error(`Unknown Playwright tool: ${name}`);
|
|
159
173
|
}
|
|
174
|
+
// Extract instance_id if provided
|
|
175
|
+
const { instance_id, ...toolArgs } = args || {};
|
|
176
|
+
let previousInstanceId = null;
|
|
177
|
+
let needsRestore = false;
|
|
160
178
|
try {
|
|
179
|
+
// If instance_id is specified, temporarily switch to that instance
|
|
180
|
+
if (instance_id !== undefined) {
|
|
181
|
+
const { PlaywrightManager } = await import('../playwright/manager.js');
|
|
182
|
+
const { manager } = await import('../index.js');
|
|
183
|
+
if (manager) {
|
|
184
|
+
// Save current active instance
|
|
185
|
+
const instances = manager.listInstances();
|
|
186
|
+
const currentActive = instances.find((i) => i.is_active);
|
|
187
|
+
if (currentActive) {
|
|
188
|
+
previousInstanceId = currentActive.id;
|
|
189
|
+
}
|
|
190
|
+
// Switch to specified instance
|
|
191
|
+
if (previousInstanceId !== instance_id) {
|
|
192
|
+
await manager.switchActive(instance_id);
|
|
193
|
+
await this.resetContext();
|
|
194
|
+
needsRestore = true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
161
198
|
// Get the tools/call handler
|
|
162
199
|
const handler = this.mcpServer['_requestHandlers'].get('tools/call');
|
|
163
200
|
if (!handler) {
|
|
164
201
|
throw new Error('tools/call handler not found in MCP server');
|
|
165
202
|
}
|
|
166
|
-
// Call the tool with our arguments
|
|
203
|
+
// Call the tool with our arguments (without instance_id)
|
|
167
204
|
const result = await handler({
|
|
168
205
|
method: 'tools/call',
|
|
169
206
|
params: {
|
|
170
207
|
name,
|
|
171
|
-
arguments:
|
|
208
|
+
arguments: toolArgs
|
|
172
209
|
}
|
|
173
210
|
}, {});
|
|
174
211
|
return result;
|
|
@@ -177,6 +214,21 @@ export class PlaywrightMCPProxy {
|
|
|
177
214
|
console.error(`Playwright tool '${name}' failed:`, error);
|
|
178
215
|
throw error;
|
|
179
216
|
}
|
|
217
|
+
finally {
|
|
218
|
+
// Restore previous active instance if we switched
|
|
219
|
+
if (needsRestore && previousInstanceId !== null) {
|
|
220
|
+
try {
|
|
221
|
+
const { manager } = await import('../index.js');
|
|
222
|
+
if (manager) {
|
|
223
|
+
await manager.switchActive(previousInstanceId);
|
|
224
|
+
await this.resetContext();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
console.error('Failed to restore previous instance:', error);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
180
232
|
}
|
|
181
233
|
/**
|
|
182
234
|
* Check if a tool exists
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playwright-mcp-proxy.js","sourceRoot":"","sources":["../../src/tools/playwright-mcp-proxy.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAO5C,uEAAuE;AACvE,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,C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B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC5C,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,0DAA0D;YAC1D,sEAAsE;YACtE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,GAAG,SAAS,CAAC;YACzD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,GAAG,EAAE,CAAC;YACjC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,GAAG,SAAS,CAAC;QAChD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,8CAA8C;QAChD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,qBAAqB;QACrB,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC1C,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACxC,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
|
package/dist/tools/profile.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare const profileTools: {
|
|
|
4
4
|
inputSchema: {
|
|
5
5
|
type: string;
|
|
6
6
|
properties: {};
|
|
7
|
+
additionalProperties: boolean;
|
|
7
8
|
};
|
|
8
9
|
handler: () => Promise<{
|
|
9
10
|
content: {
|
|
@@ -55,6 +56,7 @@ export declare const profileTools: {
|
|
|
55
56
|
};
|
|
56
57
|
};
|
|
57
58
|
required: string[];
|
|
59
|
+
additionalProperties: boolean;
|
|
58
60
|
};
|
|
59
61
|
handler: (args: any) => Promise<{
|
|
60
62
|
content: {
|
|
@@ -74,30 +76,39 @@ export declare const profileTools: {
|
|
|
74
76
|
};
|
|
75
77
|
executable_path: {
|
|
76
78
|
type: string;
|
|
79
|
+
description: string;
|
|
77
80
|
};
|
|
78
81
|
fingerprint_path: {
|
|
79
82
|
type: string;
|
|
83
|
+
description: string;
|
|
80
84
|
};
|
|
81
85
|
storage_state_path: {
|
|
82
86
|
type: string;
|
|
87
|
+
description: string;
|
|
83
88
|
};
|
|
84
89
|
description: {
|
|
85
90
|
type: string;
|
|
91
|
+
description: string;
|
|
86
92
|
};
|
|
87
93
|
proxy_server: {
|
|
88
94
|
type: string;
|
|
95
|
+
description: string;
|
|
89
96
|
};
|
|
90
97
|
proxy_username: {
|
|
91
98
|
type: string;
|
|
99
|
+
description: string;
|
|
92
100
|
};
|
|
93
101
|
proxy_password: {
|
|
94
102
|
type: string;
|
|
103
|
+
description: string;
|
|
95
104
|
};
|
|
96
105
|
proxy_bypass: {
|
|
97
106
|
type: string;
|
|
107
|
+
description: string;
|
|
98
108
|
};
|
|
99
109
|
};
|
|
100
110
|
required: string[];
|
|
111
|
+
additionalProperties: boolean;
|
|
101
112
|
};
|
|
102
113
|
handler: (args: any) => Promise<{
|
|
103
114
|
content: {
|
|
@@ -117,6 +128,7 @@ export declare const profileTools: {
|
|
|
117
128
|
};
|
|
118
129
|
};
|
|
119
130
|
required: string[];
|
|
131
|
+
additionalProperties: boolean;
|
|
120
132
|
};
|
|
121
133
|
handler: (args: any) => Promise<{
|
|
122
134
|
content: {
|
package/dist/tools/profile.js
CHANGED
|
@@ -5,93 +5,117 @@ import { ProfileRepository } from '../db/repositories/profile.js';
|
|
|
5
5
|
const profileRepo = new ProfileRepository();
|
|
6
6
|
export const profileTools = {
|
|
7
7
|
list_browser_profiles: {
|
|
8
|
-
description: '
|
|
8
|
+
description: 'List all browser profiles with their configurations',
|
|
9
9
|
inputSchema: {
|
|
10
10
|
type: 'object',
|
|
11
11
|
properties: {},
|
|
12
|
+
additionalProperties: false,
|
|
12
13
|
},
|
|
13
14
|
handler: async () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
try {
|
|
16
|
+
const profiles = profileRepo.getAll();
|
|
17
|
+
return {
|
|
18
|
+
content: [{
|
|
19
|
+
type: 'text',
|
|
20
|
+
text: JSON.stringify(profiles, null, 2),
|
|
21
|
+
}],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new Error(`Failed to list profiles: ${error instanceof Error ? error.message : String(error)}`);
|
|
26
|
+
}
|
|
21
27
|
},
|
|
22
28
|
},
|
|
23
29
|
create_browser_profile: {
|
|
24
|
-
description: '
|
|
30
|
+
description: 'Create a new browser profile with executable path and optional proxy settings',
|
|
25
31
|
inputSchema: {
|
|
26
32
|
type: 'object',
|
|
27
33
|
properties: {
|
|
28
|
-
alias: { type: 'string', description: '
|
|
29
|
-
executable_path: { type: 'string', description: 'Chrome
|
|
30
|
-
fingerprint_path: { type: 'string', description: '
|
|
31
|
-
storage_state_path: { type: 'string', description: '
|
|
32
|
-
description: { type: 'string', description: '
|
|
33
|
-
proxy_server: { type: 'string', description: '
|
|
34
|
-
proxy_username: { type: 'string', description: '
|
|
35
|
-
proxy_password: { type: 'string', description: '
|
|
36
|
-
proxy_bypass: { type: 'string', description: '
|
|
34
|
+
alias: { type: 'string', description: 'Unique profile identifier' },
|
|
35
|
+
executable_path: { type: 'string', description: 'Path to Chrome/Chromium executable' },
|
|
36
|
+
fingerprint_path: { type: 'string', description: 'Path to fingerprint configuration file (optional)' },
|
|
37
|
+
storage_state_path: { type: 'string', description: 'Path to save cookies/localStorage (optional)' },
|
|
38
|
+
description: { type: 'string', description: 'Profile description' },
|
|
39
|
+
proxy_server: { type: 'string', description: 'Proxy server URL (e.g., http://127.0.0.1:7890)' },
|
|
40
|
+
proxy_username: { type: 'string', description: 'Proxy authentication username' },
|
|
41
|
+
proxy_password: { type: 'string', description: 'Proxy authentication password' },
|
|
42
|
+
proxy_bypass: { type: 'string', description: 'Comma-separated domains to bypass proxy' },
|
|
37
43
|
},
|
|
38
44
|
required: ['alias', 'executable_path'],
|
|
45
|
+
additionalProperties: false,
|
|
39
46
|
},
|
|
40
47
|
handler: async (args) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
try {
|
|
49
|
+
profileRepo.create(args);
|
|
50
|
+
return {
|
|
51
|
+
content: [{
|
|
52
|
+
type: 'text',
|
|
53
|
+
text: `Profile "${args.alias}" created successfully`,
|
|
54
|
+
}],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw new Error(`Failed to create profile: ${error instanceof Error ? error.message : String(error)}`);
|
|
59
|
+
}
|
|
48
60
|
},
|
|
49
61
|
},
|
|
50
62
|
update_browser_profile: {
|
|
51
|
-
description: '
|
|
63
|
+
description: 'Update an existing browser profile configuration',
|
|
52
64
|
inputSchema: {
|
|
53
65
|
type: 'object',
|
|
54
66
|
properties: {
|
|
55
|
-
alias: { type: 'string', description: '
|
|
56
|
-
executable_path: { type: 'string' },
|
|
57
|
-
fingerprint_path: { type: 'string' },
|
|
58
|
-
storage_state_path: { type: 'string' },
|
|
59
|
-
description: { type: 'string' },
|
|
60
|
-
proxy_server: { type: 'string' },
|
|
61
|
-
proxy_username: { type: 'string' },
|
|
62
|
-
proxy_password: { type: 'string' },
|
|
63
|
-
proxy_bypass: { type: 'string' },
|
|
67
|
+
alias: { type: 'string', description: 'Profile alias to update' },
|
|
68
|
+
executable_path: { type: 'string', description: 'New executable path' },
|
|
69
|
+
fingerprint_path: { type: 'string', description: 'New fingerprint path' },
|
|
70
|
+
storage_state_path: { type: 'string', description: 'New storage state path' },
|
|
71
|
+
description: { type: 'string', description: 'New description' },
|
|
72
|
+
proxy_server: { type: 'string', description: 'New proxy server URL' },
|
|
73
|
+
proxy_username: { type: 'string', description: 'New proxy username' },
|
|
74
|
+
proxy_password: { type: 'string', description: 'New proxy password' },
|
|
75
|
+
proxy_bypass: { type: 'string', description: 'New proxy bypass list' },
|
|
64
76
|
},
|
|
65
77
|
required: ['alias'],
|
|
78
|
+
additionalProperties: false,
|
|
66
79
|
},
|
|
67
80
|
handler: async (args) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
81
|
+
try {
|
|
82
|
+
const { alias, ...updates } = args;
|
|
83
|
+
profileRepo.update(alias, updates);
|
|
84
|
+
return {
|
|
85
|
+
content: [{
|
|
86
|
+
type: 'text',
|
|
87
|
+
text: `Profile "${alias}" updated successfully`,
|
|
88
|
+
}],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
throw new Error(`Failed to update profile: ${error instanceof Error ? error.message : String(error)}`);
|
|
93
|
+
}
|
|
76
94
|
},
|
|
77
95
|
},
|
|
78
96
|
delete_browser_profile: {
|
|
79
|
-
description: '
|
|
97
|
+
description: 'Delete a browser profile and all associated accounts',
|
|
80
98
|
inputSchema: {
|
|
81
99
|
type: 'object',
|
|
82
100
|
properties: {
|
|
83
|
-
alias: { type: 'string', description: '
|
|
101
|
+
alias: { type: 'string', description: 'Profile alias to delete' },
|
|
84
102
|
},
|
|
85
103
|
required: ['alias'],
|
|
104
|
+
additionalProperties: false,
|
|
86
105
|
},
|
|
87
106
|
handler: async (args) => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
107
|
+
try {
|
|
108
|
+
profileRepo.delete(args.alias);
|
|
109
|
+
return {
|
|
110
|
+
content: [{
|
|
111
|
+
type: 'text',
|
|
112
|
+
text: `Profile "${args.alias}" deleted successfully`,
|
|
113
|
+
}],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
throw new Error(`Failed to delete profile: ${error instanceof Error ? error.message : String(error)}`);
|
|
118
|
+
}
|
|
95
119
|
},
|
|
96
120
|
},
|
|
97
121
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/tools/profile.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAkB,MAAM,+BAA+B,CAAC;AAElF,MAAM,WAAW,GAAG,IAAI,iBAAiB,EAAE,CAAC;AAE5C,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,qBAAqB,EAAE;QACrB,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/tools/profile.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAkB,MAAM,+BAA+B,CAAC;AAElF,MAAM,WAAW,GAAG,IAAI,iBAAiB,EAAE,CAAC;AAE5C,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,qBAAqB,EAAE;QACrB,WAAW,EAAE,qDAAqD;QAClE,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;YACd,oBAAoB,EAAE,KAAK;SAC5B;QACD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC;gBACtC,OAAO;oBACL,OAAO,EAAE,CAAC;4BACR,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE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K,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACzG,CAAC;QACH,CAAC;KACF;CACF,CAAC"}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -78,16 +78,40 @@ add_account(
|
|
|
78
78
|
|
|
79
79
|
# 3. 启动浏览器(自动成为活跃实例)
|
|
80
80
|
launch_browser(profile_alias: "twitter-bot", account_id: 1)
|
|
81
|
+
# 返回: Browser instance 1 launched successfully
|
|
81
82
|
|
|
82
|
-
# 4.
|
|
83
|
+
# 4. 方式1:使用活跃实例(传统方式)
|
|
83
84
|
browser_navigate(url: "https://twitter.com")
|
|
84
85
|
browser_click(element: "登录按钮")
|
|
85
86
|
|
|
86
87
|
# 5. 启动第二个实例
|
|
87
88
|
launch_browser(profile_alias: "twitter-bot", account_id: 2)
|
|
89
|
+
# 返回: Browser instance 2 launched successfully
|
|
88
90
|
|
|
89
|
-
# 6.
|
|
91
|
+
# 6. 方式2:直接指定实例ID(推荐!)
|
|
92
|
+
browser_navigate(url: "https://twitter.com", instance_id: 1) # 在实例1操作
|
|
93
|
+
browser_navigate(url: "https://facebook.com", instance_id: 2) # 在实例2操作
|
|
94
|
+
|
|
95
|
+
# 7. 方式3:切换活跃实例再操作
|
|
90
96
|
switch_browser_instance(instance_id: 1)
|
|
97
|
+
browser_click(element: "Tweet按钮") # 自动使用实例1
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 多实例操作的两种方式
|
|
101
|
+
|
|
102
|
+
**方式1: 显式指定 instance_id(推荐)**
|
|
103
|
+
```
|
|
104
|
+
# 所有浏览器工具都支持 instance_id 参数
|
|
105
|
+
browser_navigate(url: "https://example.com", instance_id: 1)
|
|
106
|
+
browser_click(element: "按钮", ref: "abc123", instance_id: 2)
|
|
107
|
+
browser_type(element: "输入框", ref: "xyz", text: "hello", instance_id: 1)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**方式2: 切换活跃实例**
|
|
111
|
+
```
|
|
112
|
+
switch_browser_instance(instance_id: 1)
|
|
113
|
+
browser_navigate(url: "https://example.com") # 使用实例1
|
|
114
|
+
browser_click(element: "按钮") # 使用实例1
|
|
91
115
|
```
|
|
92
116
|
|
|
93
117
|
## 可用工具 (36个)
|
|
@@ -113,6 +137,9 @@ switch_browser_instance(instance_id: 1)
|
|
|
113
137
|
- `cleanup_orphaned_instances` - 清理孤立记录
|
|
114
138
|
|
|
115
139
|
### 浏览器操作 (22个 - 来自 @playwright/mcp)
|
|
140
|
+
|
|
141
|
+
**所有浏览器工具都支持可选的 `instance_id` 参数,可直接指定要操作的浏览器实例**
|
|
142
|
+
|
|
116
143
|
- `browser_navigate` - 导航到 URL
|
|
117
144
|
- `browser_click` - 点击元素
|
|
118
145
|
- `browser_type` - 输入文本
|
|
@@ -192,11 +219,22 @@ switch_browser_instance(instance_id: 1)
|
|
|
192
219
|
- **动态上下文切换**: 使用 `PlaywrightMCPProxy` 包装 @playwright/mcp,通过 `resetContext()` 清除缓存
|
|
193
220
|
- **独立浏览器状态**: 每个实例维护独立的页面、会话和导航历史
|
|
194
221
|
- **完整配置支持**: 提供包含超时设置的完整 BrowserServerBackend 配置
|
|
222
|
+
- **直接实例指定**: 所有浏览器工具支持 `instance_id` 参数,无需切换即可操作指定实例
|
|
195
223
|
|
|
196
224
|
**工作原理:**
|
|
197
|
-
1.
|
|
198
|
-
2.
|
|
199
|
-
3.
|
|
225
|
+
1. AI Agent 调用浏览器工具时,可选提供 `instance_id` 参数
|
|
226
|
+
2. 如果提供了 `instance_id`,临时切换到该实例
|
|
227
|
+
3. 执行工具操作后,自动恢复到之前的活跃实例
|
|
228
|
+
4. 如果未提供 `instance_id`,使用当前活跃实例
|
|
229
|
+
|
|
230
|
+
**示例:**
|
|
231
|
+
```javascript
|
|
232
|
+
// 同时操作两个浏览器实例,无需显式切换
|
|
233
|
+
await browser_navigate({ url: "https://twitter.com", instance_id: 1 });
|
|
234
|
+
await browser_navigate({ url: "https://facebook.com", instance_id: 2 });
|
|
235
|
+
await browser_click({ element: "Tweet按钮", ref: "xyz", instance_id: 1 });
|
|
236
|
+
await browser_click({ element: "Post按钮", ref: "abc", instance_id: 2 });
|
|
237
|
+
```
|
|
200
238
|
|
|
201
239
|
### 元数据字段
|
|
202
240
|
|
|
@@ -234,7 +272,12 @@ SELECT * FROM browser_profiles;
|
|
|
234
272
|
A: 使用 `list_browser_instances` 查看,`is_active: 1` 的实例就是当前活跃实例。
|
|
235
273
|
|
|
236
274
|
**Q: 可以同时操作多个实例吗?**
|
|
237
|
-
A:
|
|
275
|
+
A: 可以!有两种方式:
|
|
276
|
+
1. 在每个工具调用时指定 `instance_id` 参数(推荐)
|
|
277
|
+
2. 使用 `switch_browser_instance` 切换活跃实例
|
|
278
|
+
|
|
279
|
+
**Q: 什么时候需要使用 instance_id 参数?**
|
|
280
|
+
A: 当你需要频繁在多个浏览器之间切换操作时,使用 `instance_id` 更方便,避免反复调用 `switch_browser_instance`。
|
|
238
281
|
|
|
239
282
|
**Q: Cookie 什么时候保存?**
|
|
240
283
|
A: 停止实例时(`stop_browser_instance`)会自动保存到 `storage_state_path`。
|