-
Notifications
You must be signed in to change notification settings - Fork 2.3k
chore: update CLI generator to generate all possible tools #1962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nroscino
wants to merge
10
commits into
main
Choose a base branch
from
feat/update-cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7dfba95
chore: update CLI generator to generate all possible tools
nroscino 44949e7
docs: generate cli options
nroscino d76caf8
chore: update doc generation to specify flag
nroscino 873ee08
tests: fix broken tests
nroscino 9c3063c
Merge branch 'main' into feat/update-cli
nroscino b507475
chore: PR feedbacks
nroscino 3a04c33
chore: unify condition names with experimental convention
nroscino 1e45b75
chore: unify category flags style
nroscino e8d943b
chore: unify in page tools category convention
nroscino 5e0e16b
chore: changing category in mcp-cli-options
nroscino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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( | ||
|
|
@@ -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'}, | ||
| }); | ||
|
|
||
|
|
@@ -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)) | ||
|
|
@@ -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') { | ||
| return false; | ||
| } | ||
| // Skipping in_page tools as they are not launched yet | ||
| if (toolNameToCategoryEnum.get(tool.name) === ToolCategory.IN_PAGE) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>} | ||
|
|
@@ -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, | ||
| }; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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;?There was a problem hiding this comment.
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_idin thechrome-devtools-cli-options.tsThere was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
This is only when --viaCli is passed. When we are not passing
--viaClithe 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