brave-mcp 0.3.0 → 0.4.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/README.md +22 -5
- package/build/src/McpContext.js +12 -2
- package/build/src/McpPage.js +9 -4
- package/build/src/McpResponse.js +35 -17
- package/build/src/TextSnapshot.js +2 -2
- package/build/src/WaitForHelper.js +5 -0
- package/build/src/bin/brave-devtools-cli-options.js +228 -46
- package/build/src/bin/brave-devtools-mcp-cli-options.js +9 -5
- package/build/src/bin/brave-devtools-mcp-main.js +0 -5
- package/build/src/bin/brave-devtools.js +4 -13
- package/build/src/formatters/HeapSnapshotFormatter.js +3 -3
- package/build/src/index.js +93 -50
- package/build/src/telemetry/ClearcutLogger.js +12 -1
- package/build/src/third_party/index.js +2 -1
- package/build/src/third_party/issue-descriptions/genericFormModelContextMissingToolDescription.md +5 -0
- package/build/src/third_party/issue-descriptions/genericFormModelContextMissingToolName.md +5 -0
- package/build/src/third_party/issue-descriptions/genericFormModelContextParameterMissingName.md +5 -0
- package/build/src/third_party/issue-descriptions/genericFormModelContextParameterMissingTitleAndDescription.md +5 -0
- package/build/src/third_party/issue-descriptions/genericFormModelContextRequiredParameterMissingName.md +5 -0
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +21716 -20261
- package/build/src/tools/categories.js +9 -3
- package/build/src/tools/console.js +2 -0
- package/build/src/tools/emulation.js +1 -0
- package/build/src/tools/extensions.js +5 -0
- package/build/src/tools/input.js +54 -1
- package/build/src/tools/lighthouse.js +15 -9
- package/build/src/tools/memory.js +4 -0
- package/build/src/tools/network.js +2 -0
- package/build/src/tools/pages.js +13 -5
- package/build/src/tools/performance.js +3 -0
- package/build/src/tools/screencast.js +4 -2
- package/build/src/tools/screenshot.js +1 -0
- package/build/src/tools/script.js +1 -0
- package/build/src/tools/slim/tools.js +3 -0
- package/build/src/tools/snapshot.js +2 -0
- package/build/src/tools/{inPage.js → thirdPartyDeveloper.js} +17 -17
- package/build/src/tools/tools.js +2 -2
- package/build/src/tools/webmcp.js +4 -4
- package/build/src/version.js +1 -1
- package/package.json +6 -7
- package/build/src/bin/cliDefinitions.js +0 -622
- package/build/src/third_party/THIRD_PARTY_NOTICES +0 -4297
- package/build/src/third_party/bundled-packages.json +0 -9
- package/build/src/utils/ExtensionRegistry.js +0 -35
package/build/src/index.js
CHANGED
|
@@ -13,10 +13,67 @@ import { SlimMcpResponse } from './SlimMcpResponse.js';
|
|
|
13
13
|
import { ClearcutLogger } from './telemetry/ClearcutLogger.js';
|
|
14
14
|
import { bucketizeLatency } from './telemetry/metricUtils.js';
|
|
15
15
|
import { McpServer, SetLevelRequestSchema, ListRootsResultSchema, RootsListChangedNotificationSchema, } from './third_party/index.js';
|
|
16
|
-
import {
|
|
16
|
+
import { labels, OFF_BY_DEFAULT_CATEGORIES } from './tools/categories.js';
|
|
17
17
|
import { pageIdSchema } from './tools/ToolDefinition.js';
|
|
18
18
|
import { createTools } from './tools/tools.js';
|
|
19
19
|
import { VERSION } from './version.js';
|
|
20
|
+
export function buildFlag(category) {
|
|
21
|
+
return `category${category.charAt(0).toUpperCase() + category.slice(1)}`;
|
|
22
|
+
}
|
|
23
|
+
function buildDisabledMessage(toolName, flag, categoryLabel) {
|
|
24
|
+
const reason = categoryLabel
|
|
25
|
+
? `is in category ${categoryLabel} which`
|
|
26
|
+
: `requires experimental feature ${flag} and`;
|
|
27
|
+
return `Tool ${toolName} ${reason} is currently disabled. Enable it by running chrome-devtools start ${flag}=true. For more information check the README.`;
|
|
28
|
+
}
|
|
29
|
+
function getCategoryStatus(category, serverArgs) {
|
|
30
|
+
const categoryFlag = buildFlag(category);
|
|
31
|
+
const flagValue = serverArgs[categoryFlag];
|
|
32
|
+
const isDisabled = OFF_BY_DEFAULT_CATEGORIES.includes(category)
|
|
33
|
+
? !flagValue
|
|
34
|
+
: flagValue === false;
|
|
35
|
+
if (isDisabled) {
|
|
36
|
+
return {
|
|
37
|
+
categoryFlag,
|
|
38
|
+
disabled: true,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
disabled: false,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function getConditionStatus(condition, serverArgs) {
|
|
46
|
+
if (condition && !serverArgs[condition]) {
|
|
47
|
+
return { conditionFlag: condition, disabled: true };
|
|
48
|
+
}
|
|
49
|
+
return { disabled: false };
|
|
50
|
+
}
|
|
51
|
+
function getToolStatusInfo(tool, serverArgs) {
|
|
52
|
+
const category = tool.annotations.category;
|
|
53
|
+
const categoryCheck = getCategoryStatus(category, serverArgs);
|
|
54
|
+
if (category && categoryCheck.disabled) {
|
|
55
|
+
if (!categoryCheck.categoryFlag) {
|
|
56
|
+
throw new Error('when the category is disabled there should always be a flag set');
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
disabled: true,
|
|
60
|
+
reason: buildDisabledMessage(tool.name, `--${categoryCheck.categoryFlag}`, labels[category]),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
for (const condition of tool.annotations.conditions || []) {
|
|
64
|
+
const conditionCheck = getConditionStatus(condition, serverArgs);
|
|
65
|
+
if (conditionCheck.disabled) {
|
|
66
|
+
if (!conditionCheck.conditionFlag) {
|
|
67
|
+
throw new Error('when the condition is disabled there should always be a flag set');
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
disabled: true,
|
|
71
|
+
reason: buildDisabledMessage(tool.name, `--${conditionCheck.conditionFlag}`),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { disabled: false };
|
|
76
|
+
}
|
|
20
77
|
export async function createMcpServer(serverArgs, options) {
|
|
21
78
|
let clearcutLogger;
|
|
22
79
|
if (serverArgs.usageStatistics) {
|
|
@@ -106,44 +163,8 @@ export async function createMcpServer(serverArgs, options) {
|
|
|
106
163
|
}
|
|
107
164
|
const toolMutex = new Mutex();
|
|
108
165
|
function registerTool(tool) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (tool.annotations.category === ToolCategory.PERFORMANCE &&
|
|
114
|
-
serverArgs.categoryPerformance === false) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (tool.annotations.category === ToolCategory.NETWORK &&
|
|
118
|
-
serverArgs.categoryNetwork === false) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (tool.annotations.category === ToolCategory.EXTENSIONS &&
|
|
122
|
-
serverArgs.categoryExtensions === false) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
if (tool.annotations.category === ToolCategory.IN_PAGE &&
|
|
126
|
-
!serverArgs.categoryInPageTools) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
if (tool.annotations.conditions?.includes('computerVision') &&
|
|
130
|
-
!serverArgs.experimentalVision) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
if (tool.annotations.conditions?.includes('experimentalMemory') &&
|
|
134
|
-
!serverArgs.experimentalMemory) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (tool.annotations.conditions?.includes('experimentalInteropTools') &&
|
|
138
|
-
!serverArgs.experimentalInteropTools) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (tool.annotations.conditions?.includes('screencast') &&
|
|
142
|
-
!serverArgs.experimentalScreencast) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (tool.annotations.conditions?.includes('experimentalWebmcp') &&
|
|
146
|
-
!serverArgs.experimentalWebmcp) {
|
|
166
|
+
const { disabled, reason: disabledReason } = getToolStatusInfo(tool, serverArgs);
|
|
167
|
+
if (disabled && !serverArgs.viaCli) {
|
|
147
168
|
return;
|
|
148
169
|
}
|
|
149
170
|
const schema = 'pageScoped' in tool &&
|
|
@@ -157,6 +178,17 @@ export async function createMcpServer(serverArgs, options) {
|
|
|
157
178
|
inputSchema: schema,
|
|
158
179
|
annotations: tool.annotations,
|
|
159
180
|
}, async (params) => {
|
|
181
|
+
if (disabledReason) {
|
|
182
|
+
return {
|
|
183
|
+
content: [
|
|
184
|
+
{
|
|
185
|
+
type: 'text',
|
|
186
|
+
text: disabledReason,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
isError: true,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
160
192
|
const guard = await toolMutex.acquire();
|
|
161
193
|
const startTime = Date.now();
|
|
162
194
|
let success = false;
|
|
@@ -169,29 +201,40 @@ export async function createMcpServer(serverArgs, options) {
|
|
|
169
201
|
? new SlimMcpResponse(serverArgs)
|
|
170
202
|
: new McpResponse(serverArgs);
|
|
171
203
|
response.setRedactNetworkHeaders(serverArgs.redactNetworkHeaders);
|
|
172
|
-
|
|
204
|
+
try {
|
|
173
205
|
const page = serverArgs.experimentalPageIdRouting &&
|
|
174
206
|
params.pageId &&
|
|
175
207
|
!serverArgs.slim
|
|
176
208
|
? context.getPageById(params.pageId)
|
|
177
209
|
: context.getSelectedMcpPage();
|
|
178
210
|
response.setPage(page);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
211
|
+
if (tool.blockedByDialog) {
|
|
212
|
+
page.throwIfDialogOpen();
|
|
213
|
+
}
|
|
214
|
+
if ('pageScoped' in tool && tool.pageScoped) {
|
|
215
|
+
await tool.handler({
|
|
216
|
+
params,
|
|
217
|
+
page,
|
|
218
|
+
}, response, context);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
await tool.handler(
|
|
222
|
+
// @ts-expect-error types do not match.
|
|
223
|
+
{
|
|
224
|
+
params,
|
|
225
|
+
}, response, context);
|
|
226
|
+
}
|
|
183
227
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
// @ts-expect-error types do not match.
|
|
187
|
-
{
|
|
188
|
-
params,
|
|
189
|
-
}, response, context);
|
|
228
|
+
catch (err) {
|
|
229
|
+
response.setError(err);
|
|
190
230
|
}
|
|
191
231
|
const { content, structuredContent } = await response.handle(tool.name, context);
|
|
192
232
|
const result = {
|
|
193
233
|
content,
|
|
194
234
|
};
|
|
235
|
+
if (response.error) {
|
|
236
|
+
result.isError = true;
|
|
237
|
+
}
|
|
195
238
|
success = true;
|
|
196
239
|
if (serverArgs.experimentalStructuredContent) {
|
|
197
240
|
result.structuredContent = structuredContent;
|
|
@@ -64,9 +64,20 @@ export function transformArgType(zodType) {
|
|
|
64
64
|
throw new Error(`Unsupported zod type for tool parameter: ${zodType}`);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
const BUCKETS = [
|
|
68
|
+
0, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000,
|
|
69
|
+
];
|
|
70
|
+
function bucketize(value) {
|
|
71
|
+
for (const bucket of BUCKETS) {
|
|
72
|
+
if (bucket >= value) {
|
|
73
|
+
return bucket;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return BUCKETS[BUCKETS.length - 1];
|
|
77
|
+
}
|
|
67
78
|
function transformValue(zodType, value) {
|
|
68
79
|
if (zodType === 'ZodString') {
|
|
69
|
-
return value.length;
|
|
80
|
+
return bucketize(value.length);
|
|
70
81
|
}
|
|
71
82
|
else if (zodType === 'ZodArray') {
|
|
72
83
|
return value.length;
|
|
@@ -22,7 +22,8 @@ export { Locator, PredefinedNetworkConditions, KnownDevices, CDPSessionEvent, }
|
|
|
22
22
|
export { default as puppeteer } from 'puppeteer-core';
|
|
23
23
|
export { PipeTransport } from 'puppeteer-core/internal/node/PipeTransport.js';
|
|
24
24
|
export { resolveDefaultUserDataDir, detectBrowserPlatform, Browser as BrowserEnum, } from '@puppeteer/browsers';
|
|
25
|
-
import { snapshot as snapshotImpl, navigation as navigationImpl, generateReport as generateReportImpl, } from './lighthouse-devtools-mcp-bundle.js';
|
|
25
|
+
import { snapshot as snapshotImpl, navigation as navigationImpl, generateReport as generateReportImpl, agenticBrowsingConfig as agenticBrowsingConfigImpl, } from './lighthouse-devtools-mcp-bundle.js';
|
|
26
|
+
export const agenticBrowsingConfig = agenticBrowsingConfigImpl;
|
|
26
27
|
export const snapshot = snapshotImpl;
|
|
27
28
|
export const navigation = navigationImpl;
|
|
28
29
|
export const generateReport = generateReportImpl;
|
package/build/src/third_party/issue-descriptions/genericFormModelContextMissingToolDescription.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Missing tool description for a WebMCP declarative tool definition
|
|
2
|
+
|
|
3
|
+
This form is intended to be used as a WebMCP declarative tool definition, but it lacks a description explaining what the tool does. Descriptions are critical for AI models to decide when to use a given tool.
|
|
4
|
+
|
|
5
|
+
To fix this issue, provide a tool description via the `tooldescription` attribute.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Missing tool name for a WebMCP declarative tool definition
|
|
2
|
+
|
|
3
|
+
This form is intended to be used as a WebMCP declarative tool definition, but it does not specify a name. A tool name is required for an AI model to correctly identify and invoke the tool.
|
|
4
|
+
|
|
5
|
+
To fix this issue, provide a tool name via the `toolname` attribute.
|
package/build/src/third_party/issue-descriptions/genericFormModelContextParameterMissingName.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Parameter missing name for a WebMCP declarative tool definition
|
|
2
|
+
|
|
3
|
+
An input element within this form lacks a `name` attribute. Without a name, the AI model cannot format the parameter payload correctly when invoking the tool.
|
|
4
|
+
|
|
5
|
+
To fix this issue, ensure form parameters have a `name` attribute.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Missing parameter title and description for a WebMCP declarative tool definition
|
|
2
|
+
|
|
3
|
+
A parameter within this form (such as an `<input>` field) is missing both a title and a description. An AI model needs this metadata to understand what information should be passed to this parameter when invoking the tool.
|
|
4
|
+
|
|
5
|
+
To fix this issue, add a title and description to the form parameter.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Required parameter missing name for a WebMCP declarative tool definition
|
|
2
|
+
|
|
3
|
+
A required input element within this form lacks a `name` attribute. Without a name, the AI model cannot format the parameter payload correctly when invoking the tool.
|
|
4
|
+
|
|
5
|
+
To fix this issue, ensure all required form parameters have a `name` attribute.
|