Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,21 @@ The Chrome DevTools MCP server supports the following configuration option:
Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.
- **Type:** array

- **`--categoryEmulation`**
Set to false to exlcude tools related to emulation.
- **Type:** boolean
- **Default:** `true`

- **`--categoryPerformance`**
Set to false to exlcude tools related to performance.
- **Type:** boolean
- **Default:** `true`

- **`--categoryNetwork`**
Set to false to exlcude tools related to network.
- **Type:** boolean
- **Default:** `true`

<!-- END AUTO GENERATED OPTIONS -->

Pass them via the `args` property in the JSON configuration. For example:
Expand Down
15 changes: 8 additions & 7 deletions scripts/generate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {StdioClientTransport} from '@modelcontextprotocol/sdk/client/stdio.js';
import type {Tool} from '@modelcontextprotocol/sdk/types.js';

import {cliOptions} from '../build/src/cli.js';
import {ToolCategories} from '../build/src/tools/categories.js';
import {ToolCategory, labels} from '../build/src/tools/categories.js';

const MCP_SERVER_PATH = 'build/src/index.js';
const OUTPUT_PATH = './docs/tool-reference.md';
Expand All @@ -21,7 +21,7 @@ const README_PATH = './README.md';
interface ToolWithAnnotations extends Tool {
annotations?: {
title?: string;
category?: ToolCategories;
category?: typeof ToolCategory;
};
}

Expand Down Expand Up @@ -67,7 +67,7 @@ function generateToolsTOC(

for (const category of sortedCategories) {
const categoryTools = categories[category];
const categoryName = category;
const categoryName = labels[category];
toc += `- **${categoryName}** (${categoryTools.length} tools)\n`;

// Sort tools within category for TOC
Expand Down Expand Up @@ -209,7 +209,7 @@ async function generateToolDocumentation(): Promise<void> {
});

// Sort categories using the enum order
const categoryOrder = Object.values(ToolCategories);
const categoryOrder = Object.values(ToolCategory);
const sortedCategories = Object.keys(categories).sort((a, b) => {
const aIndex = categoryOrder.indexOf(a);
const bIndex = categoryOrder.indexOf(b);
Expand All @@ -223,8 +223,8 @@ async function generateToolDocumentation(): Promise<void> {
// Generate table of contents
for (const category of sortedCategories) {
const categoryTools = categories[category];
const categoryName = category;
const anchorName = category.toLowerCase().replace(/\s+/g, '-');
const categoryName = labels[category];
const anchorName = categoryName.toLowerCase().replace(/\s+/g, '-');
markdown += `- **[${categoryName}](#${anchorName})** (${categoryTools.length} tools)\n`;

// Sort tools within category for TOC
Expand All @@ -239,8 +239,9 @@ async function generateToolDocumentation(): Promise<void> {

for (const category of sortedCategories) {
const categoryTools = categories[category];
const categoryName = labels[category];

markdown += `## ${category}\n\n`;
markdown += `## ${categoryName}\n\n`;

// Sort tools within category
categoryTools.sort((a: Tool, b: Tool) => a.name.localeCompare(b.name));
Expand Down
21 changes: 21 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ export const cliOptions = {
describe:
'Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
},
categoryEmulation: {
type: 'boolean',
default: true,
describe: 'Set to false to exlcude tools related to emulation.',
},
categoryPerformance: {
type: 'boolean',
default: true,
describe: 'Set to false to exlcude tools related to performance.',
},
categoryNetwork: {
type: 'boolean',
default: true,
describe: 'Set to false to exlcude tools related to network.',
},
} satisfies Record<string, YargsOptions>;

export function parseArguments(version: string, argv = process.argv) {
Expand Down Expand Up @@ -185,6 +200,12 @@ export function parseArguments(version: string, argv = process.argv) {
`$0 --chrome-arg='--no-sandbox' --chrome-arg='--disable-setuid-sandbox'`,
'Launch Chrome without sandboxes. Use with caution.',
],
['$0 --no-category-emulation', 'Disable tools in the emulation category'],
[
'$0 --no-category-performance',
'Disable tools in the performance category',
],
['$0 --no-category-network', 'Disable tools in the network category'],
]);

return yargsInstance
Expand Down
19 changes: 19 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
type CallToolResult,
SetLevelRequestSchema,
} from './third_party/index.js';
import {ToolCategory} from './tools/categories.js';
import * as consoleTools from './tools/console.js';
import * as emulationTools from './tools/emulation.js';
import * as inputTools from './tools/input.js';
Expand Down Expand Up @@ -96,6 +97,24 @@ Avoid sharing sensitive or personal information that you do not want to share wi
const toolMutex = new Mutex();

function registerTool(tool: ToolDefinition): void {
if (
tool.annotations.category === ToolCategory.EMULATION &&
args.categoryEmulation === false
) {
return;
}
if (
tool.annotations.category === ToolCategory.PERFORMANCE &&
args.categoryPerformance === false
) {
return;
}
if (
tool.annotations.category === ToolCategory.NETWORK &&
args.categoryNetwork === false
) {
return;
}
server.registerTool(
tool.name,
{
Expand Down
4 changes: 2 additions & 2 deletions src/tools/ToolDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {Dialog, ElementHandle, Page} from '../third_party/index.js';
import type {TraceResult} from '../trace-processing/parse.js';
import type {PaginationOptions} from '../utils/types.js';

import type {ToolCategories} from './categories.js';
import type {ToolCategory} from './categories.js';

export interface ToolDefinition<
Schema extends zod.ZodRawShape = zod.ZodRawShape,
Expand All @@ -19,7 +19,7 @@ export interface ToolDefinition<
description: string;
annotations: {
title?: string;
category: ToolCategories;
category: ToolCategory;
/**
* If true, the tool does not modify its environment.
*/
Expand Down
23 changes: 16 additions & 7 deletions src/tools/categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@
* SPDX-License-Identifier: Apache-2.0
*/

export enum ToolCategories {
INPUT_AUTOMATION = 'Input automation',
NAVIGATION_AUTOMATION = 'Navigation automation',
EMULATION = 'Emulation',
PERFORMANCE = 'Performance',
NETWORK = 'Network',
DEBUGGING = 'Debugging',
export enum ToolCategory {
INPUT = 'input',
NAVIGATION = 'navigation',
EMULATION = 'emulation',
PERFORMANCE = 'performance',
NETWORK = 'network',
DEBUGGING = 'debugging',
}

export const labels = {
[ToolCategory.INPUT]: 'Input automation',
[ToolCategory.NAVIGATION]: 'Navigation automation',
[ToolCategory.EMULATION]: 'Emulation',
[ToolCategory.PERFORMANCE]: 'Performance',
[ToolCategory.NETWORK]: 'Network',
[ToolCategory.DEBUGGING]: 'Debugging',
};
6 changes: 3 additions & 3 deletions src/tools/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import {zod} from '../third_party/index.js';
import type {ConsoleMessageType} from '../third_party/index.js';

import {ToolCategories} from './categories.js';
import {ToolCategory} from './categories.js';
import {defineTool} from './ToolDefinition.js';

const FILTERABLE_MESSAGE_TYPES: readonly [
Expand Down Expand Up @@ -40,7 +40,7 @@ export const listConsoleMessages = defineTool({
description:
'List all console messages for the currently selected page since the last navigation.',
annotations: {
category: ToolCategories.DEBUGGING,
category: ToolCategory.DEBUGGING,
readOnlyHint: true,
},
schema: {
Expand Down Expand Up @@ -86,7 +86,7 @@ export const getConsoleMessage = defineTool({
name: 'get_console_message',
description: `Gets a console message by its ID. You can get all messages by calling ${listConsoleMessages.name}.`,
annotations: {
category: ToolCategories.DEBUGGING,
category: ToolCategory.DEBUGGING,
readOnlyHint: true,
},
schema: {
Expand Down
6 changes: 3 additions & 3 deletions src/tools/emulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import {zod, PredefinedNetworkConditions} from '../third_party/index.js';

import {ToolCategories} from './categories.js';
import {ToolCategory} from './categories.js';
import {defineTool} from './ToolDefinition.js';

const throttlingOptions: [string, ...string[]] = [
Expand All @@ -19,7 +19,7 @@ export const emulateNetwork = defineTool({
name: 'emulate_network',
description: `Emulates network conditions such as throttling or offline mode on the selected page.`,
annotations: {
category: ToolCategories.EMULATION,
category: ToolCategory.EMULATION,
readOnlyHint: false,
},
schema: {
Expand Down Expand Up @@ -65,7 +65,7 @@ export const emulateCpu = defineTool({
name: 'emulate_cpu',
description: `Emulates CPU throttling by slowing down the selected page's execution.`,
annotations: {
category: ToolCategories.EMULATION,
category: ToolCategory.EMULATION,
readOnlyHint: false,
},
schema: {
Expand Down
14 changes: 7 additions & 7 deletions src/tools/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import type {McpContext, TextSnapshotNode} from '../McpContext.js';
import {zod} from '../third_party/index.js';
import type {ElementHandle} from '../third_party/index.js';

import {ToolCategories} from './categories.js';
import {ToolCategory} from './categories.js';
import {defineTool} from './ToolDefinition.js';

export const click = defineTool({
name: 'click',
description: `Clicks on the provided element`,
annotations: {
category: ToolCategories.INPUT_AUTOMATION,
category: ToolCategory.INPUT,
readOnlyHint: false,
},
schema: {
Expand Down Expand Up @@ -54,7 +54,7 @@ export const hover = defineTool({
name: 'hover',
description: `Hover over the provided element`,
annotations: {
category: ToolCategories.INPUT_AUTOMATION,
category: ToolCategory.INPUT,
readOnlyHint: false,
},
schema: {
Expand Down Expand Up @@ -138,7 +138,7 @@ export const fill = defineTool({
name: 'fill',
description: `Type text into a input, text area or select an option from a <select> element.`,
annotations: {
category: ToolCategories.INPUT_AUTOMATION,
category: ToolCategory.INPUT,
readOnlyHint: false,
},
schema: {
Expand Down Expand Up @@ -166,7 +166,7 @@ export const drag = defineTool({
name: 'drag',
description: `Drag an element onto another element`,
annotations: {
category: ToolCategories.INPUT_AUTOMATION,
category: ToolCategory.INPUT,
readOnlyHint: false,
},
schema: {
Expand Down Expand Up @@ -195,7 +195,7 @@ export const fillForm = defineTool({
name: 'fill_form',
description: `Fill out multiple form elements at once`,
annotations: {
category: ToolCategories.INPUT_AUTOMATION,
category: ToolCategory.INPUT,
readOnlyHint: false,
},
schema: {
Expand Down Expand Up @@ -227,7 +227,7 @@ export const uploadFile = defineTool({
name: 'upload_file',
description: 'Upload a file through a provided element.',
annotations: {
category: ToolCategories.INPUT_AUTOMATION,
category: ToolCategory.INPUT,
readOnlyHint: false,
},
schema: {
Expand Down
6 changes: 3 additions & 3 deletions src/tools/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import {zod} from '../third_party/index.js';
import type {ResourceType} from '../third_party/index.js';

import {ToolCategories} from './categories.js';
import {ToolCategory} from './categories.js';
import {defineTool} from './ToolDefinition.js';

const FILTERABLE_RESOURCE_TYPES: readonly [ResourceType, ...ResourceType[]] = [
Expand Down Expand Up @@ -36,7 +36,7 @@ export const listNetworkRequests = defineTool({
name: 'list_network_requests',
description: `List all requests for the currently selected page since the last navigation.`,
annotations: {
category: ToolCategories.NETWORK,
category: ToolCategory.NETWORK,
readOnlyHint: true,
},
schema: {
Expand Down Expand Up @@ -82,7 +82,7 @@ export const getNetworkRequest = defineTool({
name: 'get_network_request',
description: `Gets a network request by URL. You can get all requests by calling ${listNetworkRequests.name}.`,
annotations: {
category: ToolCategories.NETWORK,
category: ToolCategory.NETWORK,
readOnlyHint: true,
},
schema: {
Expand Down
Loading