@darbotlabs/darbot-browser-mcp 0.1.1 → 1.3.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.
- package/LICENSE +1 -1
- package/README.md +249 -158
- package/cli.js +1 -1
- package/config.d.ts +77 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/ai/context.js +150 -0
- package/lib/ai/guardrails.js +382 -0
- package/lib/ai/integration.js +397 -0
- package/lib/ai/intent.js +237 -0
- package/lib/ai/manualPromise.js +111 -0
- package/lib/ai/memory.js +273 -0
- package/lib/ai/ml-scorer.js +265 -0
- package/lib/ai/orchestrator-tools.js +292 -0
- package/lib/ai/orchestrator.js +473 -0
- package/lib/ai/planner.js +300 -0
- package/lib/ai/reporter.js +493 -0
- package/lib/ai/workflow.js +407 -0
- package/lib/auth/apiKeyAuth.js +46 -0
- package/lib/auth/entraAuth.js +110 -0
- package/lib/auth/entraJwtVerifier.js +117 -0
- package/lib/auth/index.js +210 -0
- package/lib/auth/managedIdentityAuth.js +175 -0
- package/lib/auth/mcpOAuthProvider.js +186 -0
- package/lib/auth/tunnelAuth.js +120 -0
- package/lib/browserContextFactory.js +1 -1
- package/lib/browserServer.js +1 -1
- package/lib/cdpRelay.js +2 -2
- package/lib/common.js +68 -0
- package/lib/config.js +62 -3
- package/lib/connection.js +1 -1
- package/lib/context.js +1 -1
- package/lib/fileUtils.js +1 -1
- package/lib/guardrails.js +382 -0
- package/lib/health.js +178 -0
- package/lib/httpServer.js +1 -1
- package/lib/index.js +1 -1
- package/lib/javascript.js +1 -1
- package/lib/manualPromise.js +1 -1
- package/lib/memory.js +273 -0
- package/lib/openapi.js +373 -0
- package/lib/orchestrator.js +473 -0
- package/lib/package.js +1 -1
- package/lib/pageSnapshot.js +17 -2
- package/lib/planner.js +302 -0
- package/lib/program.js +17 -5
- package/lib/reporter.js +493 -0
- package/lib/resources/resource.js +1 -1
- package/lib/server.js +5 -3
- package/lib/tab.js +1 -1
- package/lib/tools/ai-native.js +298 -0
- package/lib/tools/autonomous.js +147 -0
- package/lib/tools/clock.js +183 -0
- package/lib/tools/common.js +1 -1
- package/lib/tools/console.js +1 -1
- package/lib/tools/diagnostics.js +132 -0
- package/lib/tools/dialogs.js +1 -1
- package/lib/tools/emulation.js +155 -0
- package/lib/tools/files.js +1 -1
- package/lib/tools/install.js +1 -1
- package/lib/tools/keyboard.js +1 -1
- package/lib/tools/navigate.js +1 -1
- package/lib/tools/network.js +1 -1
- package/lib/tools/pageSnapshot.js +58 -0
- package/lib/tools/pdf.js +1 -1
- package/lib/tools/profiles.js +76 -25
- package/lib/tools/screenshot.js +1 -1
- package/lib/tools/scroll.js +93 -0
- package/lib/tools/snapshot.js +1 -1
- package/lib/tools/storage.js +328 -0
- package/lib/tools/tab.js +16 -0
- package/lib/tools/tabs.js +1 -1
- package/lib/tools/testing.js +1 -1
- package/lib/tools/tool.js +1 -1
- package/lib/tools/utils.js +1 -1
- package/lib/tools/vision.js +1 -1
- package/lib/tools/wait.js +1 -1
- package/lib/tools.js +22 -1
- package/lib/transport.js +251 -31
- package/package.json +54 -21
package/lib/openapi.js
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) DarbotLabs.
|
|
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 { zodToJsonSchema } from 'zod-to-json-schema';
|
|
17
|
+
import { packageJSON } from './package.js';
|
|
18
|
+
/**
|
|
19
|
+
* Generates OpenAPI specifications for MCP tools
|
|
20
|
+
* Enables discovery and integration with Copilot Studio
|
|
21
|
+
*/
|
|
22
|
+
export class OpenAPIGenerator {
|
|
23
|
+
tools;
|
|
24
|
+
baseUrl;
|
|
25
|
+
constructor(tools, baseUrl = '') {
|
|
26
|
+
this.tools = tools;
|
|
27
|
+
this.baseUrl = baseUrl;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Generates complete OpenAPI specification
|
|
31
|
+
*/
|
|
32
|
+
generateSpec() {
|
|
33
|
+
const paths = this.generatePaths();
|
|
34
|
+
const schemas = this.generateSchemas();
|
|
35
|
+
const tags = this.generateTags();
|
|
36
|
+
return {
|
|
37
|
+
openapi: '3.0.3',
|
|
38
|
+
info: {
|
|
39
|
+
title: 'Darbot Browser MCP API',
|
|
40
|
+
description: 'Autonomous browser automation tools for Microsoft Copilot Studio integration. Provides 52 AI-driven browser capabilities including navigation, interaction, testing, and work profile management.',
|
|
41
|
+
version: packageJSON.version,
|
|
42
|
+
contact: {
|
|
43
|
+
name: 'Darbot Labs',
|
|
44
|
+
url: 'https://github.com/darbotlabs/darbot-browser-mcp',
|
|
45
|
+
email: 'support@darbotlabs.com'
|
|
46
|
+
},
|
|
47
|
+
license: {
|
|
48
|
+
name: 'Apache 2.0',
|
|
49
|
+
url: 'https://www.apache.org/licenses/LICENSE-2.0'
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
servers: [
|
|
53
|
+
{
|
|
54
|
+
url: this.baseUrl || '{protocol}://{host}:{port}',
|
|
55
|
+
description: 'Darbot Browser MCP Server'
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
paths,
|
|
59
|
+
components: {
|
|
60
|
+
schemas,
|
|
61
|
+
securitySchemes: {
|
|
62
|
+
EntraID: {
|
|
63
|
+
type: 'http',
|
|
64
|
+
scheme: 'bearer',
|
|
65
|
+
bearerFormat: 'JWT',
|
|
66
|
+
description: 'Microsoft Entra ID (Azure AD) authentication'
|
|
67
|
+
},
|
|
68
|
+
ApiKey: {
|
|
69
|
+
type: 'apiKey',
|
|
70
|
+
in: 'header',
|
|
71
|
+
name: 'X-API-Key',
|
|
72
|
+
description: 'API Key authentication for service-to-service calls'
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
security: [
|
|
77
|
+
{ EntraID: [] },
|
|
78
|
+
{ ApiKey: [] }
|
|
79
|
+
],
|
|
80
|
+
tags
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* HTTP handler for OpenAPI specification endpoint
|
|
85
|
+
*/
|
|
86
|
+
handleOpenAPISpec(req, res) {
|
|
87
|
+
try {
|
|
88
|
+
const spec = this.generateSpec();
|
|
89
|
+
res.statusCode = 200;
|
|
90
|
+
res.setHeader('Content-Type', 'application/json');
|
|
91
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
92
|
+
res.setHeader('Cache-Control', 'public, max-age=3600');
|
|
93
|
+
res.end(JSON.stringify(spec, null, 2));
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
res.statusCode = 500;
|
|
97
|
+
res.setHeader('Content-Type', 'application/json');
|
|
98
|
+
res.end(JSON.stringify({
|
|
99
|
+
error: 'Failed to generate OpenAPI specification',
|
|
100
|
+
message: error instanceof Error ? error.message : 'Unknown error'
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
generatePaths() {
|
|
105
|
+
const paths = {};
|
|
106
|
+
// Add health endpoints
|
|
107
|
+
paths['/health'] = {
|
|
108
|
+
get: {
|
|
109
|
+
summary: 'Health Check',
|
|
110
|
+
description: 'Returns the health status of the service',
|
|
111
|
+
tags: ['Health'],
|
|
112
|
+
responses: {
|
|
113
|
+
'200': {
|
|
114
|
+
description: 'Service is healthy',
|
|
115
|
+
content: {
|
|
116
|
+
'application/json': {
|
|
117
|
+
schema: {
|
|
118
|
+
$ref: '#/components/schemas/HealthStatus'
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
'503': {
|
|
124
|
+
description: 'Service is unhealthy',
|
|
125
|
+
content: {
|
|
126
|
+
'application/json': {
|
|
127
|
+
schema: {
|
|
128
|
+
$ref: '#/components/schemas/HealthStatus'
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
paths['/ready'] = {
|
|
137
|
+
get: {
|
|
138
|
+
summary: 'Readiness Check',
|
|
139
|
+
description: 'Returns readiness status for load balancer',
|
|
140
|
+
tags: ['Health'],
|
|
141
|
+
responses: {
|
|
142
|
+
'200': {
|
|
143
|
+
description: 'Service is ready',
|
|
144
|
+
content: {
|
|
145
|
+
'text/plain': {
|
|
146
|
+
schema: { type: 'string', example: 'OK' }
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
// Add MCP endpoints
|
|
154
|
+
paths['/mcp/tools'] = {
|
|
155
|
+
get: {
|
|
156
|
+
summary: 'List Available Tools',
|
|
157
|
+
description: 'Returns a list of all available browser automation tools',
|
|
158
|
+
tags: ['MCP'],
|
|
159
|
+
responses: {
|
|
160
|
+
'200': {
|
|
161
|
+
description: 'List of tools',
|
|
162
|
+
content: {
|
|
163
|
+
'application/json': {
|
|
164
|
+
schema: {
|
|
165
|
+
type: 'object',
|
|
166
|
+
properties: {
|
|
167
|
+
tools: {
|
|
168
|
+
type: 'array',
|
|
169
|
+
items: {
|
|
170
|
+
$ref: '#/components/schemas/Tool'
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
// Add tool-specific endpoints
|
|
182
|
+
for (const tool of this.tools) {
|
|
183
|
+
const toolPath = `/api/v1/tools/${tool.schema.name}`;
|
|
184
|
+
paths[toolPath] = {
|
|
185
|
+
post: {
|
|
186
|
+
summary: tool.schema.title || tool.schema.name,
|
|
187
|
+
description: tool.schema.description,
|
|
188
|
+
tags: [this.getToolCategory(tool)],
|
|
189
|
+
operationId: `execute_${tool.schema.name}`,
|
|
190
|
+
requestBody: {
|
|
191
|
+
required: true,
|
|
192
|
+
content: {
|
|
193
|
+
'application/json': {
|
|
194
|
+
schema: zodToJsonSchema(tool.schema.inputSchema, {
|
|
195
|
+
name: `${tool.schema.name}Input`,
|
|
196
|
+
$refStrategy: 'none'
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
responses: {
|
|
202
|
+
'200': {
|
|
203
|
+
description: 'Tool executed successfully',
|
|
204
|
+
content: {
|
|
205
|
+
'application/json': {
|
|
206
|
+
schema: {
|
|
207
|
+
type: 'object',
|
|
208
|
+
properties: {
|
|
209
|
+
success: { type: 'boolean' },
|
|
210
|
+
result: { type: 'object' },
|
|
211
|
+
metadata: { type: 'object' }
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
'400': {
|
|
218
|
+
description: 'Invalid request parameters',
|
|
219
|
+
content: {
|
|
220
|
+
'application/json': {
|
|
221
|
+
schema: {
|
|
222
|
+
$ref: '#/components/schemas/Error'
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
'401': {
|
|
228
|
+
description: 'Authentication required'
|
|
229
|
+
},
|
|
230
|
+
'500': {
|
|
231
|
+
description: 'Internal server error',
|
|
232
|
+
content: {
|
|
233
|
+
'application/json': {
|
|
234
|
+
schema: {
|
|
235
|
+
$ref: '#/components/schemas/Error'
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
return paths;
|
|
245
|
+
}
|
|
246
|
+
generateSchemas() {
|
|
247
|
+
const schemas = {};
|
|
248
|
+
// Common schemas
|
|
249
|
+
schemas.Error = {
|
|
250
|
+
type: 'object',
|
|
251
|
+
properties: {
|
|
252
|
+
error: { type: 'string' },
|
|
253
|
+
message: { type: 'string' },
|
|
254
|
+
details: { type: 'object' }
|
|
255
|
+
},
|
|
256
|
+
required: ['error', 'message']
|
|
257
|
+
};
|
|
258
|
+
schemas.HealthStatus = {
|
|
259
|
+
type: 'object',
|
|
260
|
+
properties: {
|
|
261
|
+
status: {
|
|
262
|
+
type: 'string',
|
|
263
|
+
enum: ['healthy', 'degraded', 'unhealthy']
|
|
264
|
+
},
|
|
265
|
+
timestamp: { type: 'string', format: 'date-time' },
|
|
266
|
+
version: { type: 'string' },
|
|
267
|
+
checks: {
|
|
268
|
+
type: 'array',
|
|
269
|
+
items: {
|
|
270
|
+
type: 'object',
|
|
271
|
+
properties: {
|
|
272
|
+
name: { type: 'string' },
|
|
273
|
+
status: {
|
|
274
|
+
type: 'string',
|
|
275
|
+
enum: ['pass', 'warn', 'fail']
|
|
276
|
+
},
|
|
277
|
+
duration: { type: 'number' },
|
|
278
|
+
details: { type: 'object' }
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
schemas.Tool = {
|
|
285
|
+
type: 'object',
|
|
286
|
+
properties: {
|
|
287
|
+
name: { type: 'string' },
|
|
288
|
+
description: { type: 'string' },
|
|
289
|
+
inputSchema: { type: 'object' },
|
|
290
|
+
annotations: {
|
|
291
|
+
type: 'object',
|
|
292
|
+
properties: {
|
|
293
|
+
title: { type: 'string' },
|
|
294
|
+
readOnlyHint: { type: 'boolean' },
|
|
295
|
+
destructiveHint: { type: 'boolean' }
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
// Add tool-specific schemas
|
|
301
|
+
for (const tool of this.tools) {
|
|
302
|
+
const schemaName = `${tool.schema.name}Input`;
|
|
303
|
+
schemas[schemaName] = zodToJsonSchema(tool.schema.inputSchema, {
|
|
304
|
+
name: schemaName,
|
|
305
|
+
$refStrategy: 'none'
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
return schemas;
|
|
309
|
+
}
|
|
310
|
+
generateTags() {
|
|
311
|
+
const categories = new Set();
|
|
312
|
+
for (const tool of this.tools)
|
|
313
|
+
categories.add(this.getToolCategory(tool));
|
|
314
|
+
const tags = [
|
|
315
|
+
{ name: 'Health', description: 'Health check and monitoring endpoints' },
|
|
316
|
+
{ name: 'MCP', description: 'Model Context Protocol endpoints' }
|
|
317
|
+
];
|
|
318
|
+
for (const category of categories) {
|
|
319
|
+
tags.push({
|
|
320
|
+
name: category,
|
|
321
|
+
description: this.getCategoryDescription(category)
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
return tags;
|
|
325
|
+
}
|
|
326
|
+
getToolCategory(tool) {
|
|
327
|
+
// Categorize tools based on their names
|
|
328
|
+
const name = tool.schema.name.toLowerCase();
|
|
329
|
+
if (name.includes('navigate') || name.includes('goto') || name.includes('url'))
|
|
330
|
+
return 'Navigation';
|
|
331
|
+
if (name.includes('click') || name.includes('type') || name.includes('drag') || name.includes('hover'))
|
|
332
|
+
return 'Interaction';
|
|
333
|
+
if (name.includes('screenshot') || name.includes('snapshot') || name.includes('pdf'))
|
|
334
|
+
return 'Capture';
|
|
335
|
+
if (name.includes('tab') || name.includes('window'))
|
|
336
|
+
return 'Tabs';
|
|
337
|
+
if (name.includes('profile') || name.includes('session'))
|
|
338
|
+
return 'Profiles';
|
|
339
|
+
if (name.includes('wait') || name.includes('expect'))
|
|
340
|
+
return 'Wait';
|
|
341
|
+
if (name.includes('test') || name.includes('assert'))
|
|
342
|
+
return 'Testing';
|
|
343
|
+
if (name.includes('network') || name.includes('request'))
|
|
344
|
+
return 'Network';
|
|
345
|
+
if (name.includes('console') || name.includes('log'))
|
|
346
|
+
return 'Console';
|
|
347
|
+
if (name.includes('file') || name.includes('upload') || name.includes('download'))
|
|
348
|
+
return 'Files';
|
|
349
|
+
return 'General';
|
|
350
|
+
}
|
|
351
|
+
getCategoryDescription(category) {
|
|
352
|
+
const descriptions = {
|
|
353
|
+
'Navigation': 'Page navigation and URL manipulation tools',
|
|
354
|
+
'Interaction': 'Page interaction tools (clicks, typing, drag & drop)',
|
|
355
|
+
'Capture': 'Screenshot, snapshot, and PDF generation tools',
|
|
356
|
+
'Tabs': 'Browser tab and window management tools',
|
|
357
|
+
'Profiles': 'Work profile and session management tools',
|
|
358
|
+
'Wait': 'Waiting and synchronization tools',
|
|
359
|
+
'Testing': 'Testing and assertion tools',
|
|
360
|
+
'Network': 'Network monitoring and request tools',
|
|
361
|
+
'Console': 'Browser console and logging tools',
|
|
362
|
+
'Files': 'File upload, download, and management tools',
|
|
363
|
+
'General': 'General browser automation tools'
|
|
364
|
+
};
|
|
365
|
+
return descriptions[category] || 'Browser automation tools';
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Creates an OpenAPI generator for the given tools
|
|
370
|
+
*/
|
|
371
|
+
export function createOpenAPIGenerator(tools, baseUrl) {
|
|
372
|
+
return new OpenAPIGenerator(tools, baseUrl);
|
|
373
|
+
}
|