@posthog/wizard
Version:
The PostHog wizard helps you to configure your project
159 lines (158 loc) • 6.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeMCPServer = exports.addMCPServer = exports.getInstalledClients = exports.removeMCPServerFromClientsStep = exports.addMCPServerToClientsStep = exports.getSupportedClients = void 0;
const telemetry_1 = require("../../telemetry");
const analytics_1 = require("../../utils/analytics");
const clack_1 = __importDefault(require("../../utils/clack"));
const clack_utils_1 = require("../../utils/clack-utils");
const cursor_1 = require("./clients/cursor");
const claude_1 = require("./clients/claude");
const mcp_1 = require("../../mcp");
const getSupportedClients = async () => {
const allClients = [new cursor_1.CursorMCPClient(), new claude_1.ClaudeMCPClient()];
const supportedClients = [];
for (const client of allClients) {
if (await client.isClientSupported()) {
supportedClients.push(client);
}
}
return supportedClients;
};
exports.getSupportedClients = getSupportedClients;
const addMCPServerToClientsStep = async ({ integration, cloudRegion, askPermission = true, }) => {
const region = cloudRegion ?? (await (0, clack_utils_1.askForCloudRegion)());
if (region === 'eu') {
if (!askPermission) {
await (0, clack_utils_1.abort)('The MCP server is not available in the EU region. It is coming soon!');
}
return [];
}
const hasPermission = askPermission
? await (0, clack_utils_1.abortIfCancelled)(clack_1.default.select({
message: 'Would you like to install the PostHog MCP server to use PostHog in your editor?',
options: [
{ value: true, label: 'Yes' },
{ value: false, label: 'No' },
],
}), integration)
: true;
if (!hasPermission) {
return [];
}
const clients = await (0, exports.getSupportedClients)();
const installedClients = await (0, exports.getInstalledClients)();
if (installedClients.length > 0) {
clack_1.default.log.warn(`The PostHog MCP server is already configured for:
${installedClients.map((c) => `- ${c.name}`).join('\n ')}`);
const reinstall = await (0, clack_utils_1.abortIfCancelled)(clack_1.default.select({
message: 'Would you like to reinstall it?',
options: [
{
value: true,
label: 'Yes',
hint: 'Reinstall the MCP server',
},
{
value: false,
label: 'No',
hint: 'Keep the existing installation',
},
],
}), integration);
if (!reinstall) {
analytics_1.analytics.capture('wizard interaction', {
action: 'declined to reinstall mcp servers',
clients: installedClients.map((c) => c.name),
integration,
});
return [];
}
await (0, exports.removeMCPServer)(installedClients);
clack_1.default.log.info('Removed existing installation.');
}
const personalApiKey = await (0, mcp_1.getPersonalApiKey)({ cloudRegion: region });
await (0, telemetry_1.traceStep)('adding mcp servers', async () => {
await (0, exports.addMCPServer)(clients, personalApiKey);
});
clack_1.default.log.success(`Added the PostHog MCP server to:
${clients.map((c) => `- ${c.name}`).join('\n ')} `);
analytics_1.analytics.capture('wizard interaction', {
action: 'added mcp servers',
clients: clients.map((c) => c.name),
integration,
});
return clients.map((c) => c.name);
};
exports.addMCPServerToClientsStep = addMCPServerToClientsStep;
const removeMCPServerFromClientsStep = async ({ integration, }) => {
const installedClients = await (0, exports.getInstalledClients)();
if (installedClients.length === 0) {
analytics_1.analytics.capture('wizard interaction', {
action: 'no mcp servers to remove',
integration,
});
return [];
}
const removeServers = await (0, clack_utils_1.abortIfCancelled)(clack_1.default.select({
message: `Found the PostHog MCP server in ${installedClients.length} clients. Would you like to remove it?`,
options: [
{
value: true,
label: 'Yes',
hint: `Remove PostHog MCP server`,
},
{
value: false,
label: 'No',
hint: 'Keep the MCP server configuration',
},
],
}), integration);
if (!removeServers) {
analytics_1.analytics.capture('wizard interaction', {
action: 'declined to remove mcp servers',
clients: installedClients.map((c) => c.name),
integration,
});
await (0, clack_utils_1.abort)('The MCP server was not removed.');
return [];
}
const results = await (0, telemetry_1.traceStep)('removing mcp servers', async () => {
await (0, exports.removeMCPServer)(installedClients);
return installedClients.map((c) => c.name);
});
analytics_1.analytics.capture('wizard interaction', {
action: 'removed mcp servers',
clients: results,
integration,
});
return results;
};
exports.removeMCPServerFromClientsStep = removeMCPServerFromClientsStep;
const getInstalledClients = async () => {
const clients = await (0, exports.getSupportedClients)();
const installedClients = [];
for (const client of clients) {
if (await client.isServerInstalled()) {
installedClients.push(client);
}
}
return installedClients;
};
exports.getInstalledClients = getInstalledClients;
const addMCPServer = async (clients, personalApiKey) => {
for (const client of clients) {
await client.addServer(personalApiKey);
}
};
exports.addMCPServer = addMCPServer;
const removeMCPServer = async (clients) => {
for (const client of clients) {
await client.removeServer();
}
};
exports.removeMCPServer = removeMCPServer;
//# sourceMappingURL=index.js.map