Skip to content
68 changes: 53 additions & 15 deletions scripts/generate-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {Client} from '@modelcontextprotocol/sdk/client/index.js';
import {StdioClientTransport} from '@modelcontextprotocol/sdk/client/stdio.js';

import {parseArguments} from '../build/src/bin/chrome-devtools-mcp-cli-options.js';
import {labels} from '../build/src/tools/categories.js';
import {CONDITION_TO_FLAG, buildFlag} from '../build/src/index.js';
import {
labels,
ToolCategory,
OFF_BY_DEFAULT_CATEGORIES,
} from '../build/src/tools/categories.js';
import {createTools} from '../build/src/tools/tools.js';

const OUTPUT_PATH = path.join(
Expand All @@ -29,7 +34,7 @@ async function fetchTools() {

const transport = new StdioClientTransport({
command: 'node',
args: [serverPath],
args: [serverPath, '--viaCli'],
env: {...process.env, CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS: 'true'},
});

Expand Down Expand Up @@ -103,6 +108,15 @@ function schemaToCLIOptions(schema: JsonSchema): CliOption[] {
async function generateCli() {
const tools = await fetchTools();

const staticTools = createTools(parseArguments());
const toolNameToCategoryEnum = new Map<string, string>();
const toolNameToConditions = new Map<string, string[]>();

for (const tool of staticTools) {
toolNameToCategoryEnum.set(tool.name, tool.annotations.category);
toolNameToConditions.set(tool.name, tool.annotations.conditions || []);
}

// Sort tools by name
const sortedTools = tools
.sort((a, b) => a.name.localeCompare(b.name))
Expand All @@ -117,18 +131,17 @@ async function generateCli() {
if (tool.name === 'wait_for') {
return false;
}
// Skipping get_tab_id as it is for internal integrations
if (tool.name === 'get_tab_id') {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this if we do delete startCliOptions.experimentalInteropTools;?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I remove these, it generates also the get_tab_id in the chrome-devtools-cli-options.ts

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it mean get_tab_id is available on the server we fetch tools from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. the tool is present but if it's disabled it returns an error:

        if (disabledReason) {
          return {
            content: [
              {
                type: 'text',
                text: disabledReason,
              },
            ],
            isError: true,
          };
        }

This is only when --viaCli is passed. When we are not passing --viaCli the previous behaviour is preserved (removing the tool completely)
If we don't want these tool at all appearing then we have also to filter them out from the generate-cli. Unless we want to change the logic. I am open to change it

return false;
}
// Skipping in_page tools as they are not launched yet
if (toolNameToCategoryEnum.get(tool.name) === ToolCategory.IN_PAGE) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can remove this if we delete the category cli flag from the cli options in chrome-devtools.ts?

return false;
}
return true;
});

const staticTools = createTools(parseArguments());
const toolNameToCategory = new Map<string, string>();
for (const tool of staticTools) {
toolNameToCategory.set(
tool.name,
labels[tool.annotations.category as keyof typeof labels],
);
}

const commands: Record<
string,
{description: string; category: string; args: Record<string, CliOption>}
Expand All @@ -140,15 +153,40 @@ async function generateCli() {
for (const opt of options) {
args[opt.name] = opt;
}
const category = toolNameToCategory.get(tool.name);
if (!category) {

const categoryEnum = toolNameToCategoryEnum.get(tool.name);
if (!categoryEnum) {
throw new Error(`Tool ${tool.name} has no category.`);
}
const category = labels[categoryEnum as unknown as keyof typeof labels];
if (!tool.description) {
throw new Error(`Tool ${tool.name} is missing descripttion`);
throw new Error(`Tool ${tool.name} is missing description`);
}

let description = tool.description;
const requiredFlags: string[] = [];

const isOffByDefault = OFF_BY_DEFAULT_CATEGORIES.includes(categoryEnum);
if (isOffByDefault) {
const categoryFlag = buildFlag(categoryEnum);
requiredFlags.push(`--${categoryFlag}=true`);
}

const conditions = toolNameToConditions.get(tool.name) || [];
for (const condition of conditions) {
const flag =
CONDITION_TO_FLAG[condition as keyof typeof CONDITION_TO_FLAG];
if (flag) {
requiredFlags.push(`--${flag}=true`);
}
}

if (requiredFlags.length > 0) {
description += ` (requires flag: ${requiredFlags.join(', ')})`;
}

commands[tool.name] = {
description: tool.description,
description,
category,
args,
};
Expand Down
21 changes: 21 additions & 0 deletions skills/chrome-devtools-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,27 @@ chrome-devtools take_snapshot # Take a text snapshot of the page from the a11y t
chrome-devtools take_snapshot --verbose true --filePath "s.txt" # Take a verbose snapshot and save to file
```

## Extensions

```bash
chrome-devtools list_extensions # Lists all the Chrome extensions installed in the browser
chrome-devtools install_extension "/path/to/extension" # Installs a Chrome extension from the given path
chrome-devtools uninstall_extension "extension_id" # Uninstalls a Chrome extension by its ID
chrome-devtools reload_extension "extension_id" # Reloads an unpacked Chrome extension by its ID
chrome-devtools trigger_extension_action "extension_id" # Triggers the default action of an extension by its ID
```

## Experimental Features

Experimental tools are disabled by default. Enable them with the corresponding flag during `start`.

```bash
chrome-devtools click_at 100 200 # Clicks at the provided coordinates (requires --experimentalVision=true)
chrome-devtools screencast_start # Starts a screencast recording (requires --experimentalScreencast=true and ffmpeg)
chrome-devtools screencast_stop # Stops the active screencast
chrome-devtools list_webmcp_tools # List all WebMCP tools (requires --experimentalWebmcp=true)
```

## Service Management

```bash
Expand Down
Loading
Loading