mirror of
https://github.com/ChromeDevTools/chrome-devtools-mcp.git
synced 2026-09-14 19:45:30 +08:00
refactor: move config files out of bin (#2578)
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@
|
||||
"typecheck": "tsc --noEmit",
|
||||
"format": "eslint --cache --fix . && prettier --write --cache .",
|
||||
"check-format": "eslint --cache . && prettier --check --cache .;",
|
||||
"gen": "npm run build && npm run docs:generate && npm run cli:generate && npm run update-metrics && npm run format",
|
||||
"gen": "npm run build && npm run cli:generate && npm run docs:generate && npm run update-metrics && npm run format",
|
||||
"docs:generate": "node scripts/generate-docs.ts",
|
||||
"start": "npm run build && node build/src/bin/chrome-devtools-mcp.js",
|
||||
"start-debug": "NODE_DEBUG=mcp:* npm run build && node build/src/bin/chrome-devtools-mcp.js",
|
||||
|
||||
@@ -10,7 +10,7 @@ import path from 'node:path';
|
||||
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 {parseArguments} from '../build/src/config/mcp-options.js';
|
||||
import {buildFlag} from '../build/src/index.js';
|
||||
import {
|
||||
labels,
|
||||
@@ -21,7 +21,7 @@ import {createTools} from '../build/src/tools/tools.js';
|
||||
|
||||
const OUTPUT_PATH = path.join(
|
||||
import.meta.dirname,
|
||||
'../src/bin/chrome-devtools-cli-options.ts',
|
||||
'../src/config/cli-options.ts',
|
||||
);
|
||||
|
||||
async function fetchTools() {
|
||||
@@ -108,7 +108,7 @@ function schemaToCLIOptions(schema: JsonSchema): CliOption[] {
|
||||
async function generateCli() {
|
||||
const tools = await fetchTools();
|
||||
|
||||
const staticTools = createTools(parseArguments());
|
||||
const staticTools = createTools(parseArguments('0.0.0', [], {}));
|
||||
const toolNameToCategoryEnum = new Map<string, string>();
|
||||
const toolNameToConditions = new Map<string, string[]>();
|
||||
|
||||
@@ -195,7 +195,12 @@ async function generateCli() {
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
// NOTE: do not edit manually. Auto-generated by 'npm run cli:generate'.
|
||||
/**
|
||||
* @fileoverview
|
||||
* WARNING: This file is auto-generated by 'npm run cli:generate'.
|
||||
* Do not edit this file manually.
|
||||
*/
|
||||
|
||||
|
||||
export interface ArgDef {
|
||||
name: string;
|
||||
|
||||
@@ -8,9 +8,11 @@ import fs from 'node:fs';
|
||||
|
||||
import type {Tool} from '@modelcontextprotocol/sdk/types.js';
|
||||
|
||||
import {cliOptions} from '../build/src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../build/src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import {buildFlag} from '../build/src/index.js';
|
||||
import {
|
||||
mcpOptions,
|
||||
type ParsedArguments,
|
||||
} from '../build/src/config/mcp-options.js';
|
||||
import {buildFlag} from '../build/src/ToolHandler.js';
|
||||
import {
|
||||
ToolCategory,
|
||||
OFF_BY_DEFAULT_CATEGORIES,
|
||||
@@ -154,7 +156,7 @@ function updateReadmeWithToolsTOC(toolsTOC: string): void {
|
||||
function generateConfigOptionsMarkdown(): string {
|
||||
let markdown = '';
|
||||
|
||||
for (const [optionName, optionConfig] of Object.entries(cliOptions)) {
|
||||
for (const [optionName, optionConfig] of Object.entries(mcpOptions)) {
|
||||
// Skip hidden options
|
||||
if (optionConfig.hidden) {
|
||||
continue;
|
||||
|
||||
@@ -7,10 +7,7 @@
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
|
||||
import {
|
||||
cliOptions,
|
||||
parseArguments,
|
||||
} from '../build/src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import {mcpOptions, parseArguments} from '../build/src/config/mcp-options.js';
|
||||
import {ErrorCode} from '../build/src/telemetry/errors.js';
|
||||
import {
|
||||
getPossibleFlagMetrics,
|
||||
@@ -92,7 +89,7 @@ function writeFlagUsageMetrics() {
|
||||
}
|
||||
}
|
||||
|
||||
const newMetrics = getPossibleFlagMetrics(cliOptions);
|
||||
const newMetrics = getPossibleFlagMetrics(mcpOptions);
|
||||
const mergedMetrics = applyToExisting<FlagMetric>(
|
||||
existingMetrics,
|
||||
newMetrics,
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
|
||||
import type {WebMCPTool} from 'puppeteer-core';
|
||||
|
||||
import type {ParsedArguments} from './bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from './config/mcp-options.js';
|
||||
import {ConsoleFormatter} from './formatters/ConsoleFormatter.js';
|
||||
import {
|
||||
HeapSnapshotFormatter,
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type {ParsedArguments} from './bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from './config/mcp-options.js';
|
||||
import type {McpContext} from './McpContext.js';
|
||||
import type {McpPage} from './McpPage.js';
|
||||
import type {DataFormat} from './McpResponse.js';
|
||||
|
||||
@@ -17,7 +17,7 @@ import {checkForUpdates} from '../utils/check-for-updates.js';
|
||||
import {logger, saveLogsToFile} from '../utils/logger.js';
|
||||
import {VERSION} from '../version.js';
|
||||
|
||||
import {cliOptions, parseArguments} from './chrome-devtools-mcp-cli-options.js';
|
||||
import {mcpOptions, parseArguments} from '../config/mcp-options.js';
|
||||
|
||||
await checkForUpdates(
|
||||
'Run `npm install chrome-devtools-mcp@latest` to update.',
|
||||
@@ -80,4 +80,4 @@ await server.connect(transport);
|
||||
logger?.('Chrome DevTools MCP Server connected');
|
||||
logDisclaimers(args);
|
||||
void ClearcutLogger.get()?.logDailyActiveIfNeeded();
|
||||
void ClearcutLogger.get()?.logServerStart(computeFlagUsage(args, cliOptions));
|
||||
void ClearcutLogger.get()?.logServerStart(computeFlagUsage(args, mcpOptions));
|
||||
|
||||
@@ -30,8 +30,8 @@ import {hideBin, yargs, type CallToolResult} from '../third_party/index.js';
|
||||
import {checkForUpdates} from '../utils/check-for-updates.js';
|
||||
import {VERSION} from '../version.js';
|
||||
|
||||
import {commands} from './chrome-devtools-cli-options.js';
|
||||
import {cliOptions, parseArguments} from './chrome-devtools-mcp-cli-options.js';
|
||||
import {commands} from '../config/cli-options.js';
|
||||
import {mcpOptions, parseArguments} from '../config/mcp-options.js';
|
||||
|
||||
await checkForUpdates(
|
||||
'Run `npm install -g chrome-devtools-mcp@latest` and `chrome-devtools start` to update and restart the daemon.',
|
||||
@@ -46,8 +46,8 @@ async function start(args: string[], sessionId: string) {
|
||||
const defaultArgs = ['--viaCli', '--experimentalStructuredContent'];
|
||||
|
||||
const startCliOptions = {
|
||||
...cliOptions,
|
||||
} as Partial<typeof cliOptions>;
|
||||
...mcpOptions,
|
||||
} as Partial<typeof mcpOptions>;
|
||||
|
||||
// Missing CLI serialization.
|
||||
delete startCliOptions.viewport;
|
||||
@@ -56,10 +56,10 @@ delete startCliOptions.viewport;
|
||||
delete startCliOptions.experimentalStructuredContent;
|
||||
delete startCliOptions.experimentalInteropTools;
|
||||
delete startCliOptions.experimentalPageIdRouting;
|
||||
if (!('default' in cliOptions.headless)) {
|
||||
if (!('default' in mcpOptions.headless)) {
|
||||
throw new Error('headless cli option unexpectedly does not have a default');
|
||||
}
|
||||
if ('default' in cliOptions.isolated) {
|
||||
if ('default' in mcpOptions.isolated) {
|
||||
throw new Error('isolated cli option unexpectedly has a default');
|
||||
}
|
||||
startCliOptions.headless!.default = true;
|
||||
@@ -149,7 +149,7 @@ y.command(
|
||||
if (argv.headless === undefined) {
|
||||
argv.headless = true;
|
||||
}
|
||||
const args = serializeArgs(cliOptions, argv);
|
||||
const args = serializeArgs(mcpOptions, argv);
|
||||
await start(args, argv.sessionId);
|
||||
process.exit(0);
|
||||
},
|
||||
@@ -276,7 +276,7 @@ for (const [commandName, commandDef] of Object.entries(commands)) {
|
||||
: Promise.resolve(undefined);
|
||||
|
||||
if (!isDaemonRunning(sessionId)) {
|
||||
await start(serializeArgs(cliOptions, argv), sessionId);
|
||||
await start(serializeArgs(mcpOptions, argv), sessionId);
|
||||
}
|
||||
|
||||
const commandArgs: Record<string, unknown> = {};
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
// NOTE: do not edit manually. Auto-generated by 'npm run cli:generate'.
|
||||
/**
|
||||
* @fileoverview
|
||||
* WARNING: This file is auto-generated by 'npm run cli:generate'.
|
||||
* Do not edit this file manually.
|
||||
*/
|
||||
|
||||
export interface ArgDef {
|
||||
name: string;
|
||||
@@ -7,7 +7,7 @@
|
||||
import type {YargsOptions} from '../third_party/index.js';
|
||||
import {yargs, hideBin} from '../third_party/index.js';
|
||||
|
||||
export const cliOptions = {
|
||||
export const mcpOptions = {
|
||||
autoConnect: {
|
||||
type: 'boolean',
|
||||
description:
|
||||
@@ -390,7 +390,7 @@ export function parser(
|
||||
'strip-aliased': true,
|
||||
'strip-dashed': true,
|
||||
})
|
||||
.options(cliOptions)
|
||||
.options(mcpOptions)
|
||||
.showHelpOnFail(false, 'Specify --help for available options')
|
||||
.middleware(args => {
|
||||
// We can't set default in the options else
|
||||
@@ -411,7 +411,7 @@ export function parser(
|
||||
}
|
||||
|
||||
const cliOptionsAllowedArgs = [
|
||||
...Object.keys(cliOptions),
|
||||
...Object.keys(mcpOptions),
|
||||
// Yargs populated with positional args
|
||||
'_',
|
||||
'$0',
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
|
||||
import type fs from 'node:fs';
|
||||
|
||||
import {type ParsedArguments} from './bin/chrome-devtools-mcp-cli-options.js';
|
||||
import {type ParsedArguments} from './config/mcp-options.js';
|
||||
import type {Channel} from './browser.js';
|
||||
import {ensureBrowserConnected, ensureBrowserLaunched} from './browser.js';
|
||||
import {loadIssueDescriptions} from './devtools/issueDescriptions.js';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type {cliOptions} from '../bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {mcpOptions} from '../config/mcp-options.js';
|
||||
import {DevTools} from '../third_party/index.js';
|
||||
|
||||
import {stripUnderscoreBeforeNumber} from './transformation.js';
|
||||
@@ -12,7 +12,7 @@ import type {FlagUsage} from './types.js';
|
||||
|
||||
const {StringUtilities} = DevTools.Platform;
|
||||
|
||||
type CliOptions = typeof cliOptions;
|
||||
type CliOptions = typeof mcpOptions;
|
||||
|
||||
/**
|
||||
* For enums, log the value as uppercase.
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type {ParsedArguments} from '../bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../config/mcp-options.js';
|
||||
import type {
|
||||
HeapSnapshotAggregateData,
|
||||
HeapSnapshotClassDiff,
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type {ParsedArguments} from '../bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../config/mcp-options.js';
|
||||
|
||||
import * as consoleTools from './console.js';
|
||||
import * as emulationTools from './emulation.js';
|
||||
|
||||
@@ -12,7 +12,7 @@ import {describe, it} from 'node:test';
|
||||
|
||||
import sinon from 'sinon';
|
||||
|
||||
import type {ParsedArguments} from '../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../src/config/mcp-options.js';
|
||||
import type {McpContext} from '../src/McpContext.js';
|
||||
import type {McpResponse} from '../src/McpResponse.js';
|
||||
import type {Extension} from '../src/third_party/index.js';
|
||||
|
||||
@@ -12,7 +12,7 @@ import {pathToFileURL} from 'node:url';
|
||||
|
||||
import sinon from 'sinon';
|
||||
|
||||
import {parseArguments} from '../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import {parseArguments} from '../src/config/mcp-options.js';
|
||||
import {McpContext} from '../src/McpContext.js';
|
||||
import {McpPage} from '../src/McpPage.js';
|
||||
import {ClearcutLogger} from '../src/telemetry/ClearcutLogger.js';
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
import assert from 'node:assert';
|
||||
import {describe, it} from 'node:test';
|
||||
|
||||
import {parser} from '../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import {parser} from '../src/config/mcp-options.js';
|
||||
|
||||
function parseArguments(argv: string[], env: NodeJS.ProcessEnv = {}) {
|
||||
return parser('0.0.0', ['node', 'main.js', ...argv], env)
|
||||
|
||||
@@ -13,7 +13,7 @@ import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import {afterEach, beforeEach, describe, it} from 'node:test';
|
||||
|
||||
import type {ParsedArguments} from '../../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../../src/config/mcp-options.js';
|
||||
import {
|
||||
serializeArgs,
|
||||
assertValidSessionId,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import {describe, it} from 'node:test';
|
||||
|
||||
import type {cliOptions} from '../../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {mcpOptions} from '../../src/config/mcp-options.js';
|
||||
import {
|
||||
computeFlagUsage,
|
||||
getPossibleFlagMetrics,
|
||||
@@ -33,7 +33,7 @@ describe('computeFlagUsage', () => {
|
||||
description: 'A flag with a default value',
|
||||
default: false,
|
||||
},
|
||||
} as unknown as typeof cliOptions;
|
||||
} as unknown as typeof mcpOptions;
|
||||
|
||||
it('logs boolean flags directly with snake_case keys', () => {
|
||||
const args = {boolFlag: true};
|
||||
@@ -113,7 +113,7 @@ describe('computeFlagUsage', () => {
|
||||
type: 'boolean' as const,
|
||||
description: 'A 3p flag',
|
||||
},
|
||||
} as unknown as typeof cliOptions;
|
||||
} as unknown as typeof mcpOptions;
|
||||
const args = {experimental3pTool: true};
|
||||
const usage = computeFlagUsage(args, mock3pOptions);
|
||||
assert.equal(usage.experimental3p_tool, true);
|
||||
@@ -136,7 +136,7 @@ describe('getPossibleFlagMetrics', () => {
|
||||
description: 'An enum flag',
|
||||
choices: ['a', 'b'],
|
||||
},
|
||||
} as unknown as typeof cliOptions;
|
||||
} as unknown as typeof mcpOptions;
|
||||
|
||||
it('returns all possible metrics for given options', () => {
|
||||
const metrics = getPossibleFlagMetrics(mockOptions);
|
||||
@@ -160,7 +160,7 @@ describe('getPossibleFlagMetrics', () => {
|
||||
type: 'boolean' as const,
|
||||
description: 'A 3p flag',
|
||||
},
|
||||
} as unknown as typeof cliOptions;
|
||||
} as unknown as typeof mcpOptions;
|
||||
const metrics = getPossibleFlagMetrics(mock3pOptions);
|
||||
|
||||
assert.deepEqual(metrics, [
|
||||
|
||||
@@ -10,7 +10,7 @@ import {before, describe, it} from 'node:test';
|
||||
|
||||
import type {Dialog} from 'puppeteer-core';
|
||||
|
||||
import type {ParsedArguments} from '../../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../../src/config/mcp-options.js';
|
||||
import {loadIssueDescriptions} from '../../src/devtools/issueDescriptions.js';
|
||||
import {McpResponse} from '../../src/McpResponse.js';
|
||||
import {TextSnapshot} from '../../src/TextSnapshot.js';
|
||||
|
||||
@@ -10,7 +10,7 @@ import {afterEach, describe, it} from 'node:test';
|
||||
|
||||
import sinon from 'sinon';
|
||||
|
||||
import type {ParsedArguments} from '../../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../../src/config/mcp-options.js';
|
||||
import {listConsoleMessages} from '../../src/tools/console.js';
|
||||
import {
|
||||
installExtension,
|
||||
|
||||
@@ -11,7 +11,7 @@ import {describe, it} from 'node:test';
|
||||
|
||||
import sinon from 'sinon';
|
||||
|
||||
import type {ParsedArguments} from '../../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../../src/config/mcp-options.js';
|
||||
import {McpResponse} from '../../src/McpResponse.js';
|
||||
import {TextSnapshot} from '../../src/TextSnapshot.js';
|
||||
import {
|
||||
|
||||
@@ -11,7 +11,7 @@ import {afterEach, describe, it} from 'node:test';
|
||||
import type {Dialog} from 'puppeteer-core';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import type {ParsedArguments} from '../../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../../src/config/mcp-options.js';
|
||||
import {
|
||||
listPages,
|
||||
newPage,
|
||||
|
||||
@@ -12,7 +12,7 @@ import {describe, it, afterEach} from 'node:test';
|
||||
|
||||
import sinon from 'sinon';
|
||||
|
||||
import type {ParsedArguments} from '../../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../../src/config/mcp-options.js';
|
||||
import {startScreencast, stopScreencast} from '../../src/tools/screencast.js';
|
||||
import {withMcpContext} from '../utils.js';
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import {describe, it, afterEach} from 'node:test';
|
||||
|
||||
import sinon from 'sinon';
|
||||
|
||||
import type {ParsedArguments} from '../../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../../src/config/mcp-options.js';
|
||||
import {TextSnapshot} from '../../src/TextSnapshot.js';
|
||||
import {screenshot} from '../../src/tools/screenshot.js';
|
||||
import {screenshots} from '../snapshot.js';
|
||||
|
||||
@@ -10,7 +10,7 @@ import {describe, it} from 'node:test';
|
||||
|
||||
import sinon from 'sinon';
|
||||
|
||||
import type {ParsedArguments} from '../../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../../src/config/mcp-options.js';
|
||||
import {TextSnapshot} from '../../src/TextSnapshot.js';
|
||||
import {installExtension} from '../../src/tools/extensions.js';
|
||||
import {evaluateScript} from '../../src/tools/script.js';
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import type {
|
||||
} from 'puppeteer-core';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import type {ParsedArguments} from '../src/bin/chrome-devtools-mcp-cli-options.js';
|
||||
import type {ParsedArguments} from '../src/config/mcp-options.js';
|
||||
import {McpContext} from '../src/McpContext.js';
|
||||
import {McpResponse} from '../src/McpResponse.js';
|
||||
import {TextSnapshot} from '../src/TextSnapshot.js';
|
||||
|
||||
Reference in New Issue
Block a user