UNPKG

@posthog/wizard

Version:

The PostHog wizard helps you to configure your project

131 lines 4.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDefaultServerConfig = exports.getNativeHTTPServerConfig = exports.buildMCPUrl = exports.ALL_FEATURE_VALUES = exports.AVAILABLE_FEATURES = exports.DefaultMCPClientConfig = void 0; const zod_1 = __importDefault(require("zod")); exports.DefaultMCPClientConfig = zod_1.default .object({ mcpServers: zod_1.default.record(zod_1.default.string(), zod_1.default.union([ zod_1.default.object({ command: zod_1.default.string().optional(), args: zod_1.default.array(zod_1.default.string()).optional(), env: zod_1.default.record(zod_1.default.string(), zod_1.default.string()).optional(), }), zod_1.default.object({ url: zod_1.default.string(), headers: zod_1.default.record(zod_1.default.string(), zod_1.default.string()).optional(), }), ])), }) .passthrough(); exports.AVAILABLE_FEATURES = { 'Data & Analytics': [ { value: 'dashboards', label: 'Dashboards', hint: 'Dashboard creation and management', }, { value: 'insights', label: 'Insights', hint: 'Analytics insights and SQL queries', }, { value: 'experiments', label: 'Experiments', hint: 'A/B testing experiments', }, { value: 'llm-analytics', label: 'LLM Analytics', hint: 'LLM usage and cost tracking', }, ], 'Development Tools': [ { value: 'error-tracking', label: 'Error Tracking', hint: 'Error monitoring and debugging', }, { value: 'flags', label: 'Feature Flags', hint: 'Feature flag management' }, ], 'Platform & Management': [ { value: 'workspace', label: 'Workspace', hint: 'Organization and project management', }, { value: 'docs', label: 'Documentation', hint: 'PostHog documentation search', }, ], }; exports.ALL_FEATURE_VALUES = Object.values(exports.AVAILABLE_FEATURES) .flat() .map((feature) => feature.value); const buildMCPUrl = (type, selectedFeatures, local, region) => { // Use subdomain for EU to work around Claude Code's OAuth bug where it ignores // the authorization_servers field and fetches /.well-known/oauth-authorization-server // directly from the MCP server hostname. See: https://github.com/anthropics/claude-code/issues/2267 const host = local ? 'http://localhost:8787' : region === 'eu' ? 'https://mcp-eu.posthog.com' : 'https://mcp.posthog.com'; const baseUrl = `${host}/${type === 'sse' ? 'sse' : 'mcp'}`; const isAllFeaturesSelected = selectedFeatures && selectedFeatures.length === exports.ALL_FEATURE_VALUES.length && exports.ALL_FEATURE_VALUES.every((feature) => selectedFeatures.includes(feature)); const params = []; // Add features param if not all features selected if (selectedFeatures && selectedFeatures.length > 0 && !isAllFeaturesSelected) { params.push(`features=${selectedFeatures.join(',')}`); } return params.length > 0 ? `${baseUrl}?${params.join('&')}` : baseUrl; }; exports.buildMCPUrl = buildMCPUrl; const getNativeHTTPServerConfig = (apiKey, type, selectedFeatures, local, region) => { const config = { url: (0, exports.buildMCPUrl)(type, selectedFeatures, local, region), }; // Only add auth header if API key is provided (not OAuth mode) if (apiKey) { config.headers = { Authorization: `Bearer ${apiKey}`, }; } return config; }; exports.getNativeHTTPServerConfig = getNativeHTTPServerConfig; const getDefaultServerConfig = (apiKey, type, selectedFeatures, local, region) => { const urlWithFeatures = (0, exports.buildMCPUrl)(type, selectedFeatures, local, region); // OAuth mode: no auth header, let MCP handle OAuth if (!apiKey) { return { command: 'npx', args: ['-y', 'mcp-remote@latest', urlWithFeatures], }; } // API key mode: include auth header return { command: 'npx', args: [ '-y', 'mcp-remote@latest', urlWithFeatures, '--header', `Authorization:\${POSTHOG_AUTH_HEADER}`, ], env: { POSTHOG_AUTH_HEADER: `Bearer ${apiKey}`, }, }; }; exports.getDefaultServerConfig = getDefaultServerConfig; //# sourceMappingURL=defaults.js.map