:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(mcp): fold metric discovery into the execute-sql prompt body (#73214)
Georgiy Tarasov12a267ad2ac8
diff --git a/services/mcp/src/hono/instructions.ts b/services/mcp/src/hono/instructions.tsindex e609a43c2e87..dbe173f8bb46 100644--- a/services/mcp/src/hono/instructions.ts+++ b/services/mcp/src/hono/instructions.ts@@ -140,13 +140,14 @@ export class InstructionsBuilder {formatExecuteSqlDescription(toolFeatureFlags?: EvaluatedFlags): string {const dataCatalogEnabled = toolFeatureFlags?.[PRODUCT_DATA_CATALOG_FLAG] === true+ // Metric discovery leads the splice so catalog-first routing still precedes+ // raw schema discovery, without displacing the tool's own intro line.const schemaDiscovery = dataCatalogEnabled- ? `${SCHEMA_DISCOVERY.trim()}\n\n${CATALOG_TRUST_DISCOVERY.trim()}`+ ? `${METRIC_DISCOVERY.trim()}\n\n${SCHEMA_DISCOVERY.trim()}\n\n${CATALOG_TRUST_DISCOVERY.trim()}`: SCHEMA_DISCOVERY.trim()- const description = formatPrompt(EXECUTE_SQL_PROMPT, {+ return formatPrompt(EXECUTE_SQL_PROMPT, {guidelines: this.guidelines.trim(),schema_discovery: schemaDiscovery,})- return dataCatalogEnabled ? `${METRIC_DISCOVERY.trim()}\n\n${description}` : description}}diff --git a/services/mcp/tests/unit/execute-sql-description.test.ts b/services/mcp/tests/unit/execute-sql-description.test.tsindex 5c258d75c2c6..e2b03a5ab263 100644--- a/services/mcp/tests/unit/execute-sql-description.test.ts+++ b/services/mcp/tests/unit/execute-sql-description.test.ts@@ -15,9 +15,12 @@ describe('formatExecuteSqlDescription', () => {expect(flagged).toContain('#### Metric discovery (semantic layer)')expect(flagged).toContain('system.information_schema.metrics')expect(flagged).toContain('data-catalog-metric-run')+ // The tool's own intro must stay first; metric discovery sits after the+ // query-* routing section but keeps catalog-first precedence over raw+ // schema discovery.+ expect(flagged.startsWith('Executes HogQL')).toBe(true)const metricRoutingPosition = flagged.indexOf('#### Metric discovery (semantic layer)')- expect(metricRoutingPosition).toBeLessThan(flagged.indexOf('some guidelines'))- expect(metricRoutingPosition).toBeLessThan(flagged.indexOf('### When to use `execute-sql`'))+ expect(metricRoutingPosition).toBeGreaterThan(flagged.indexOf('### When to use `execute-sql`'))expect(metricRoutingPosition).toBeLessThan(flagged.indexOf('#### Regular schema discovery'))const baseline = builder.formatExecuteSqlDescription()