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.
Files changed (44) hide show
  1. package/README.md +22 -5
  2. package/build/src/McpContext.js +12 -2
  3. package/build/src/McpPage.js +9 -4
  4. package/build/src/McpResponse.js +35 -17
  5. package/build/src/TextSnapshot.js +2 -2
  6. package/build/src/WaitForHelper.js +5 -0
  7. package/build/src/bin/brave-devtools-cli-options.js +228 -46
  8. package/build/src/bin/brave-devtools-mcp-cli-options.js +9 -5
  9. package/build/src/bin/brave-devtools-mcp-main.js +0 -5
  10. package/build/src/bin/brave-devtools.js +4 -13
  11. package/build/src/formatters/HeapSnapshotFormatter.js +3 -3
  12. package/build/src/index.js +93 -50
  13. package/build/src/telemetry/ClearcutLogger.js +12 -1
  14. package/build/src/third_party/index.js +2 -1
  15. package/build/src/third_party/issue-descriptions/genericFormModelContextMissingToolDescription.md +5 -0
  16. package/build/src/third_party/issue-descriptions/genericFormModelContextMissingToolName.md +5 -0
  17. package/build/src/third_party/issue-descriptions/genericFormModelContextParameterMissingName.md +5 -0
  18. package/build/src/third_party/issue-descriptions/genericFormModelContextParameterMissingTitleAndDescription.md +5 -0
  19. package/build/src/third_party/issue-descriptions/genericFormModelContextRequiredParameterMissingName.md +5 -0
  20. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +21716 -20261
  21. package/build/src/tools/categories.js +9 -3
  22. package/build/src/tools/console.js +2 -0
  23. package/build/src/tools/emulation.js +1 -0
  24. package/build/src/tools/extensions.js +5 -0
  25. package/build/src/tools/input.js +54 -1
  26. package/build/src/tools/lighthouse.js +15 -9
  27. package/build/src/tools/memory.js +4 -0
  28. package/build/src/tools/network.js +2 -0
  29. package/build/src/tools/pages.js +13 -5
  30. package/build/src/tools/performance.js +3 -0
  31. package/build/src/tools/screencast.js +4 -2
  32. package/build/src/tools/screenshot.js +1 -0
  33. package/build/src/tools/script.js +1 -0
  34. package/build/src/tools/slim/tools.js +3 -0
  35. package/build/src/tools/snapshot.js +2 -0
  36. package/build/src/tools/{inPage.js → thirdPartyDeveloper.js} +17 -17
  37. package/build/src/tools/tools.js +2 -2
  38. package/build/src/tools/webmcp.js +4 -4
  39. package/build/src/version.js +1 -1
  40. package/package.json +6 -7
  41. package/build/src/bin/cliDefinitions.js +0 -622
  42. package/build/src/third_party/THIRD_PARTY_NOTICES +0 -4297
  43. package/build/src/third_party/bundled-packages.json +0 -9
  44. package/build/src/utils/ExtensionRegistry.js +0 -35
@@ -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 { ToolCategory } from './tools/categories.js';
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
- if (tool.annotations.category === ToolCategory.EMULATION &&
110
- serverArgs.categoryEmulation === false) {
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
- if ('pageScoped' in tool && tool.pageScoped) {
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
- await tool.handler({
180
- params,
181
- page,
182
- }, response, context);
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
- else {
185
- await tool.handler(
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;
@@ -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.
@@ -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.