@posthog/wizard
Version:
The PostHog wizard helps you to configure your project
69 lines (66 loc) • 3.21 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPersonalApiKey = exports.runMCPRemove = exports.runMCPInstall = void 0;
const chalk_1 = __importDefault(require("chalk"));
const add_mcp_server_to_clients_1 = require("./steps/add-mcp-server-to-clients");
const clack_1 = __importDefault(require("./utils/clack"));
const clack_utils_1 = require("./utils/clack-utils");
const opn_1 = __importDefault(require("opn"));
const urls_1 = require("./utils/urls");
const helper_functions_1 = require("./lib/helper-functions");
const runMCPInstall = async (options) => {
clack_1.default.intro('Installing the PostHog MCP server.');
await (0, add_mcp_server_to_clients_1.addMCPServerToClientsStep)({
cloudRegion: options.region,
askPermission: false,
});
clack_1.default.outro(`${chalk_1.default.green('You might need to restart your MCP clients to see the changes.')}
Get started with some prompts like:
- What feature flags do I have active?
- Add a new feature flag for our homepage redesign
- What are my most common errors?
`);
};
exports.runMCPInstall = runMCPInstall;
const runMCPRemove = async () => {
const results = await (0, add_mcp_server_to_clients_1.removeMCPServerFromClientsStep)({});
if (results.length === 0) {
clack_1.default.outro(`No PostHog MCP servers found to remove.`);
return;
}
clack_1.default.outro(`PostHog MCP server removed from:
${results.map((c) => `- ${c}`).join('\n ')}
${chalk_1.default.green('You might need to restart your MCP clients to see the changes.')}`);
};
exports.runMCPRemove = runMCPRemove;
const getPersonalApiKey = async (options) => {
const cloudUrl = (0, urls_1.getCloudUrlFromRegion)(options.cloudRegion);
const urlToOpen = `${cloudUrl}/settings/user-api-keys?preset=mcp_server`;
const spinner = clack_1.default.spinner();
spinner.start(`Opening your project settings so you can get a Personal API key...`);
await (0, helper_functions_1.sleep)(1500);
spinner.stop(`Opened your project settings. If the link didn't open automatically, open the following URL in your browser to get a Personal API key: \n\n${chalk_1.default.cyan(urlToOpen)}`);
(0, opn_1.default)(urlToOpen, { wait: false }).catch(() => {
// opn throws in environments that don't have a browser (e.g. remote shells) so we just noop here
});
const personalApiKey = await clack_1.default.password({
message: 'Paste in your Personal API key:',
validate(value) {
if (value.length === 0)
return `Value is required!`;
if (!value.startsWith('phx_')) {
return `That doesn't look right, are you sure you copied the right key? It should start with 'phx_'`;
}
},
});
if (!personalApiKey) {
await (0, clack_utils_1.abort)('Unable to proceed without a personal API key.');
return '';
}
return personalApiKey;
};
exports.getPersonalApiKey = getPersonalApiKey;
//# sourceMappingURL=mcp.js.map