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
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"version": "0.2.1",
"description": "MCP server for Chrome DevTools",
"type": "module",
"bin": {
"chrome-devtools-mcp": "./build/src/index.js"
},
"bin": "./build/src/index.js",
"main": "index.js",
"scripts": {
"build": "tsc && node --experimental-strip-types --no-warnings=ExperimentalWarning scripts/post-build.ts",
Expand Down
34 changes: 18 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ export const cliOptions = {
},
};

function readPackageJson(): {version?: string} {
const currentDir = import.meta.dirname;
const packageJsonPath = path.join(currentDir, '..', '..', 'package.json');
if (!fs.existsSync(packageJsonPath)) {
return {};
}
try {
const json = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
assert.strict(json['name'], 'chrome-devtools-mcp');
return json;
} catch {
return {};
}
}

const version = readPackageJson().version ?? 'unknown';

const yargsInstance = yargs(hideBin(process.argv))
.scriptName('npx chrome-devtools-mcp@latest')
.options(cliOptions)
Expand Down Expand Up @@ -111,26 +128,11 @@ const yargsInstance = yargs(hideBin(process.argv))
export const args = yargsInstance
.wrap(Math.min(120, yargsInstance.terminalWidth()))
.help()
.version(version)
.parseSync();

const logFile = args.logFile ? saveLogsToFile(args.logFile) : undefined;

function readPackageJson(): {version?: string} {
const currentDir = import.meta.dirname;
const packageJsonPath = path.join(currentDir, '..', '..', 'package.json');
if (!fs.existsSync(packageJsonPath)) {
return {};
}
try {
const json = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
assert.strict(json['name'], 'chrome-devtools-mcp');
return json;
} catch {
return {};
}
}

const version = readPackageJson().version ?? 'unknown';
logger(`Starting Chrome DevTools MCP Server v${version}`);
const server = new McpServer(
{
Expand Down
Loading