Skip to content

Commit d6bab91

Browse files
authored
fix: cli version being reported as unknown (#74)
1 parent 17edcd8 commit d6bab91

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"version": "0.2.1",
44
"description": "MCP server for Chrome DevTools",
55
"type": "module",
6-
"bin": {
7-
"chrome-devtools-mcp": "./build/src/index.js"
8-
},
6+
"bin": "./build/src/index.js",
97
"main": "index.js",
108
"scripts": {
119
"build": "tsc && node --experimental-strip-types --no-warnings=ExperimentalWarning scripts/post-build.ts",

src/index.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ export const cliOptions = {
8484
},
8585
};
8686

87+
function readPackageJson(): {version?: string} {
88+
const currentDir = import.meta.dirname;
89+
const packageJsonPath = path.join(currentDir, '..', '..', 'package.json');
90+
if (!fs.existsSync(packageJsonPath)) {
91+
return {};
92+
}
93+
try {
94+
const json = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
95+
assert.strict(json['name'], 'chrome-devtools-mcp');
96+
return json;
97+
} catch {
98+
return {};
99+
}
100+
}
101+
102+
const version = readPackageJson().version ?? 'unknown';
103+
87104
const yargsInstance = yargs(hideBin(process.argv))
88105
.scriptName('npx chrome-devtools-mcp@latest')
89106
.options(cliOptions)
@@ -111,26 +128,11 @@ const yargsInstance = yargs(hideBin(process.argv))
111128
export const args = yargsInstance
112129
.wrap(Math.min(120, yargsInstance.terminalWidth()))
113130
.help()
131+
.version(version)
114132
.parseSync();
115133

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

118-
function readPackageJson(): {version?: string} {
119-
const currentDir = import.meta.dirname;
120-
const packageJsonPath = path.join(currentDir, '..', '..', 'package.json');
121-
if (!fs.existsSync(packageJsonPath)) {
122-
return {};
123-
}
124-
try {
125-
const json = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
126-
assert.strict(json['name'], 'chrome-devtools-mcp');
127-
return json;
128-
} catch {
129-
return {};
130-
}
131-
}
132-
133-
const version = readPackageJson().version ?? 'unknown';
134136
logger(`Starting Chrome DevTools MCP Server v${version}`);
135137
const server = new McpServer(
136138
{

0 commit comments

Comments
 (0)