@posthog/wizard
Version:
The PostHog wizard helps you to configure your project
164 lines • 6.8 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClaudeCodeMCPClient = exports.ClaudeCodeMCPConfig = void 0;
const MCPClient_1 = require("../MCPClient");
const defaults_1 = require("../defaults");
const child_process_1 = require("child_process");
const analytics_1 = require("../../../utils/analytics");
const debug_1 = require("../../../utils/debug");
const os = __importStar(require("os"));
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
exports.ClaudeCodeMCPConfig = defaults_1.DefaultMCPClientConfig;
class ClaudeCodeMCPClient extends MCPClient_1.DefaultMCPClient {
name = 'Claude Code';
claudeBinaryPath = null;
constructor() {
super();
}
findClaudeBinary() {
if (this.claudeBinaryPath) {
return this.claudeBinaryPath;
}
// Common installation paths for Claude Code CLI
const possiblePaths = [
path.join(os.homedir(), '.claude', 'local', 'claude'),
'/usr/local/bin/claude',
'/opt/homebrew/bin/claude',
];
for (const claudePath of possiblePaths) {
if (fs.existsSync(claudePath)) {
(0, debug_1.debug)(` Found claude binary at: ${claudePath}`);
this.claudeBinaryPath = claudePath;
return claudePath;
}
}
// Try PATH as fallback
try {
(0, child_process_1.execSync)('command -v claude', { stdio: 'pipe' });
(0, debug_1.debug)(' Found claude in PATH');
this.claudeBinaryPath = 'claude';
return 'claude';
}
catch {
// Not in PATH
}
return null;
}
isClientSupported() {
try {
(0, debug_1.debug)(' Checking for Claude Code...');
const claudeBinary = this.findClaudeBinary();
if (!claudeBinary) {
(0, debug_1.debug)(' Claude Code not found. Installation paths checked:');
(0, debug_1.debug)(` - ${path.join(os.homedir(), '.claude', 'local', 'claude')}`);
(0, debug_1.debug)(` - /usr/local/bin/claude`);
(0, debug_1.debug)(` - /opt/homebrew/bin/claude`);
(0, debug_1.debug)(` - PATH`);
return Promise.resolve(false);
}
const output = (0, child_process_1.execSync)(`${claudeBinary} --version`, { stdio: 'pipe' });
const version = output.toString().trim();
(0, debug_1.debug)(` Claude Code detected: ${version}`);
return Promise.resolve(true);
}
catch (error) {
(0, debug_1.debug)(` Claude Code check failed: ${error instanceof Error ? error.message : String(error)}`);
return Promise.resolve(false);
}
}
isServerInstalled(local) {
try {
const claudeBinary = this.findClaudeBinary();
if (!claudeBinary) {
return Promise.resolve(false);
}
// check if specific server name exists in output
const output = (0, child_process_1.execSync)(`${claudeBinary} mcp list`, {
stdio: 'pipe',
});
const outputStr = output.toString();
const serverName = local ? 'posthog-local' : 'posthog';
if (outputStr.includes(serverName)) {
return Promise.resolve(true);
}
}
catch {
//
}
return Promise.resolve(false);
}
getConfigPath() {
throw new Error('Not implemented');
}
addServer(apiKey, selectedFeatures, local, region) {
const claudeBinary = this.findClaudeBinary();
if (!claudeBinary) {
return Promise.resolve({ success: false });
}
const serverName = local ? 'posthog-local' : 'posthog';
const url = (0, defaults_1.buildMCPUrl)('streamable-http', selectedFeatures, local, region);
// OAuth mode: no auth header
const authArgs = apiKey ? `--header "Authorization: Bearer ${apiKey}"` : '';
const command = `${claudeBinary} mcp add --transport http ${serverName} ${url} ${authArgs} -s user`.trim();
try {
(0, child_process_1.execSync)(command);
}
catch (error) {
analytics_1.analytics.captureException(new Error(`Failed to add server to Claude Code: ${error instanceof Error ? error.message : String(error)}`));
return Promise.resolve({ success: false });
}
return Promise.resolve({ success: true });
}
removeServer(local) {
const claudeBinary = this.findClaudeBinary();
if (!claudeBinary) {
return Promise.resolve({ success: false });
}
const serverName = local ? 'posthog-local' : 'posthog';
const command = `${claudeBinary} mcp remove --scope user ${serverName}`;
try {
(0, child_process_1.execSync)(command);
}
catch (error) {
analytics_1.analytics.captureException(new Error(`Failed to remove server from Claude Code: ${error instanceof Error ? error.message : String(error)}`));
return Promise.resolve({ success: false });
}
return Promise.resolve({ success: true });
}
}
exports.ClaudeCodeMCPClient = ClaudeCodeMCPClient;
//# sourceMappingURL=claude-code.js.map