: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): skip tool spans for posthog connection tools (#123893)
Tom Owers80c40f9eef6e
diff --git a/services/mcp/src/hono/analytics.ts b/services/mcp/src/hono/analytics.tsindex 8b23146ed948..9176b1d0822c 100644--- a/services/mcp/src/hono/analytics.ts+++ b/services/mcp/src/hono/analytics.ts@@ -337,6 +337,15 @@ function isMetadataQuery(query: string): boolean {// way. `$mcp_tool_call` still records that the call happened.const PRESIGNED_UPLOAD_TOOL_NAME = 'media-image-upload-start'+// Their output is another project's data, possibly from another region: a wrapped+// execute-sql result or any API response. The execute-sql exemption below checks only+// the outer tool name, so without this check the wrapped query's rows land in+// `$ai_output_state`.+const POSTHOG_CONNECTION_TOOL_NAMES: ReadonlySet<string> = new Set([+ 'posthog-connection-call',+ 'posthog-connection-forward',+])+function shouldCaptureToolSpan(toolName: string, input: unknown): boolean {if (isPrivateScoutTrialTool(toolName)) {return false@@ -353,6 +362,9 @@ function shouldCaptureToolSpan(toolName: string, input: unknown): boolean {if (toolName === PRESIGNED_UPLOAD_TOOL_NAME) {return false}+ if (POSTHOG_CONNECTION_TOOL_NAMES.has(toolName)) {+ return false+ }// execute-sql can't be captured wholesale: its payload is the query result,// which is the bulk of MCP response volume. Metadata queries are the// exception, because their results are small and describe what the agentdiff --git a/services/mcp/tests/hono/analytics.test.ts b/services/mcp/tests/hono/analytics.test.tsindex 5d45bc60aab6..f4725cde2c02 100644--- a/services/mcp/tests/hono/analytics.test.ts+++ b/services/mcp/tests/hono/analytics.test.ts@@ -609,6 +609,18 @@ describe('Hono MCP analytics contexts', () => {// Its result is a live presigned S3 POST (policy, signature, credential) — output// fields, not secret-shaped keys, so key-based redaction can't catch them.['the presigned upload tool', 'media-image-upload-start', { name: 'logo.png', purpose: 'email' }, false],+ [+ 'execute-sql wrapped in a connection call',+ 'posthog-connection-call',+ { connection_id: '1', tool: 'execute-sql', arguments: { query: 'SELECT count() FROM events' } },+ false,+ ],+ [+ 'a connection forward',+ 'posthog-connection-forward',+ { id: '1', method: 'GET', path: 'api/projects/1/persons/' },+ false,+ ],])('gates capture for %s', async (_case, toolName, input, captured) => {await trackToolSpan(toolName, makeState(), { durationMs: 100, isError: false, input, output: 'rows' })