mcp-chrome-bridge
Version:
Chrome Native-Messaging host (Node)
77 lines • 3.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const utils_1 = require("./scripts/utils");
commander_1.program
.version(require('../package.json').version)
.description('Mcp Chrome Bridge - Local service for communicating with Chrome extension');
// Register Native Messaging host
commander_1.program
.command('register')
.description('Register Native Messaging host')
.option('-f, --force', 'Force re-registration')
.option('-s, --system', 'Use system-level installation (requires administrator/sudo privileges)')
.action(async (options) => {
try {
// Detect if running with root/administrator privileges
const isRoot = process.getuid && process.getuid() === 0; // Unix/Linux/Mac
let isAdmin = false;
if (process.platform === 'win32') {
try {
isAdmin = require('is-admin')(); // Windows requires additional package
}
catch (error) {
console.warn((0, utils_1.colorText)('Warning: Unable to detect administrator privileges on Windows', 'yellow'));
isAdmin = false;
}
}
const hasElevatedPermissions = isRoot || isAdmin;
// If --system option is specified or running with root/administrator privileges
if (options.system || hasElevatedPermissions) {
await (0, utils_1.registerWithElevatedPermissions)();
console.log((0, utils_1.colorText)('System-level Native Messaging host registered successfully!', 'green'));
console.log((0, utils_1.colorText)('You can now use connectNative in Chrome extension to connect to this service.', 'blue'));
}
else {
// Regular user-level installation
console.log((0, utils_1.colorText)('Registering user-level Native Messaging host...', 'blue'));
const success = await (0, utils_1.tryRegisterUserLevelHost)();
if (success) {
console.log((0, utils_1.colorText)('Native Messaging host registered successfully!', 'green'));
console.log((0, utils_1.colorText)('You can now use connectNative in Chrome extension to connect to this service.', 'blue'));
}
else {
console.log((0, utils_1.colorText)('User-level registration failed, please try the following methods:', 'yellow'));
console.log((0, utils_1.colorText)(' 1. sudo mcp-chrome-bridge register', 'yellow'));
console.log((0, utils_1.colorText)(' 2. mcp-chrome-bridge register --system', 'yellow'));
process.exit(1);
}
}
}
catch (error) {
console.error((0, utils_1.colorText)(`Registration failed: ${error.message}`, 'red'));
process.exit(1);
}
});
// Fix execution permissions
commander_1.program
.command('fix-permissions')
.description('Fix execution permissions for native host files')
.action(async () => {
try {
console.log((0, utils_1.colorText)('Fixing execution permissions...', 'blue'));
await (0, utils_1.ensureExecutionPermissions)();
console.log((0, utils_1.colorText)('✓ Execution permissions fixed successfully!', 'green'));
}
catch (error) {
console.error((0, utils_1.colorText)(`Failed to fix permissions: ${error.message}`, 'red'));
process.exit(1);
}
});
commander_1.program.parse(process.argv);
// If no command provided, show help
if (!process.argv.slice(2).length) {
commander_1.program.outputHelp();
}
//# sourceMappingURL=cli.js.map