get_business_metrics
Retrieve high-level business metrics like Revenue, Conversion, and Customers from the Semantic Layer. Specify time windows to analyze performance data.
Instructions
Retrieve high-level business metrics (Revenue, Conversion, Customers) from the Semantic Layer.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| window | No | Analytics window (today, 7d, 30d, all) |
Implementation Reference
- scripts/semantic-layer.js:47-79 (handler)The handler function `getBusinessMetrics` that aggregates data from billing, telemetry, and feedback to calculate metrics.
async function getBusinessMetrics(options = {}) { const window = resolveAnalyticsWindow(options); const billing = getBillingSummary(window); const { getFeedbackPaths } = require('./feedback-loop'); const feedbackDir = options.feedbackDir || getFeedbackPaths().FEEDBACK_DIR; const telemetry = getTelemetryAnalytics(feedbackDir, window); const uniqueVisitors = telemetry.visitors.uniqueVisitors || 0; const paidCustomers = billing.revenue.paidCustomers || 0; const bookedRevenueCents = billing.revenue.bookedRevenueCents || 0; return { generatedAt: new Date().toISOString(), window: billing.window, metrics: { uniqueVisitors, checkoutStarts: telemetry.ctas.checkoutStarts || 0, acquisitionLeads: billing.signups.uniqueLeads || 0, paidCustomers, bookedRevenueCents, bookedRevenueFormatted: `$${(bookedRevenueCents / 100).toFixed(2)}`, conversionRate: safeRate(paidCustomers, uniqueVisitors), leadToPaidRate: safeRate(paidCustomers, billing.signups.uniqueLeads || 0), activeProKeys: billing.keys.active || 0, totalUsage: billing.keys.totalUsage || 0, }, attribution: billing.attribution, status: { isPostFirstDollar: paidCustomers > 0 || bookedRevenueCents > 0, hasActivePipeline: (telemetry.ctas.checkoutStarts || 0) > 0 || billing.signups.uniqueLeads > 0, } }; } - scripts/tool-registry.js:438-444 (registration)Registration of the `get_business_metrics` tool in the tool registry.
readOnlyTool({ name: 'get_business_metrics', description: 'Retrieve high-level business metrics (Revenue, Conversion, Customers) from the Semantic Layer.', inputSchema: { type: 'object', properties: { window: { type: 'string', description: 'Analytics window (today, 7d, 30d, all)' }, - adapters/mcp/server-stdio.js:428-431 (handler)MCP server-stdio handler dispatching the `get_business_metrics` request to the semantic layer.
case 'get_business_metrics': { const { getBusinessMetrics } = require('../../scripts/semantic-layer'); const metrics = await getBusinessMetrics(args); return toTextResult(metrics);