: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): track intent prompt flag on tool calls (#121368)
Adam Bowkerf355225a60b2
diff --git a/docs/published/handbook/engineering/ai/implementing-mcp-tools.md b/docs/published/handbook/engineering/ai/implementing-mcp-tools.mdindex fb56a8b4755e..d7e68d62c493 100644--- a/docs/published/handbook/engineering/ai/implementing-mcp-tools.md+++ b/docs/published/handbook/engineering/ai/implementing-mcp-tools.md@@ -128,7 +128,9 @@ Start with a release condition matching one authenticated user's distinct ID; doClients cache tool schemas. Refresh the client's tool list or reconnect after deployment before collecting trial data.Use the targeted user's calls after that refresh for offline evaluation, and record when the payload changes.-Existing intent analytics stay unchanged; the server does not capture the prompt text separately.+Each `$mcp_tool_call` records the evaluated flag as `$feature/mcp-intent-prompt`: `true` for enabled and `false` for disabled.+If evaluation is unavailable, the property is omitted. This records flag assignment; clients may still have cached an earlier prompt.+The server does not capture the prompt text separately.This collection trial changes no tool results and adds no recommendations or elicitation.Evaluate intent against independently recorded abstract task goals, checking invented goals, identifying details, and appropriate uncertainty.diff --git a/services/mcp/src/hono/analytics.ts b/services/mcp/src/hono/analytics.tsindex 7a01efc1a1a5..7a099a5e88d9 100644--- a/services/mcp/src/hono/analytics.ts+++ b/services/mcp/src/hono/analytics.ts@@ -23,6 +23,7 @@ import { EXECUTE_SQL_TOOL_NAME } from '@/tools/posthogAiTools/executeSql'import { MAX_CAPTURED_DESCRIPTION_LENGTH, getToolCategory, getToolDescription } from '@/tools/toolDefinitions'import { APP_DATA_META_KEY } from '@/ui-apps/types'+import { MCP_INTENT_PROMPT_FLAG } from './intent-prompt'import { interviewRecruitmentProperties } from './interview-recruitment'import { buildMCPSessionAnalyticsProperties, getEffectiveMCPClientIdentity } from './mcp-context'import type { ResolvedState } from './request-state-resolver'@@ -239,6 +240,7 @@ export async function trackToolCall(state.noDataAction),...extraProperties,+ [`$feature/${MCP_INTENT_PROMPT_FLAG}`]: state.toolFeatureFlags?.[MCP_INTENT_PROMPT_FLAG],is_impersonated: state.isImpersonated === true,suppress_analytics: state.suppressAnalytics === true,},diff --git a/services/mcp/tests/hono/analytics.test.ts b/services/mcp/tests/hono/analytics.test.tsindex 4e4810640970..5d45bc60aab6 100644--- a/services/mcp/tests/hono/analytics.test.ts+++ b/services/mcp/tests/hono/analytics.test.ts@@ -27,6 +27,7 @@ import {} from '@/hono/analytics'import { MCP_EXEC_SKILLS_FEATURE_FLAG } from '@/hono/constants'import { InstructionsBuilder } from '@/hono/instructions'+import { MCP_INTENT_PROMPT_FLAG } from '@/hono/intent-prompt'import type { ResolvedState } from '@/hono/request-state-resolver'import { MCPClientProfile } from '@/lib/client-detection'import { MCP_NO_DATA_INSTALL_NOTICE_FLAG } from '@/lib/no-data-guard'@@ -202,6 +203,14 @@ describe('Hono MCP analytics contexts', () => {}})+ it.each([true, false, undefined])('records the evaluated intent prompt flag: %s', async (flagValue) => {+ const state = makeState({ toolFeatureFlags: { [MCP_INTENT_PROMPT_FLAG]: flagValue } })++ await trackToolCall('user-get', 12, false, state)++ expect(mockCaptureToolCall.mock.calls[0]![0].properties[`$feature/${MCP_INTENT_PROMPT_FLAG}`]).toBe(flagValue)+ })+it('emits request properties on $mcp fields and session properties on mcp_session fields', async () => {await trackInitEvent(makeState())