: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): gate get_more_tools registration on single-exec mode (#58164)
Georgiy Tarasov9a34b4b54747
diff --git a/services/mcp/src/lib/posthog-mcp-analytics.ts b/services/mcp/src/lib/posthog-mcp-analytics.tsindex 6b769d49061b..0045347f124d 100644--- a/services/mcp/src/lib/posthog-mcp-analytics.ts+++ b/services/mcp/src/lib/posthog-mcp-analytics.ts@@ -7,6 +7,11 @@ export type PostHogMcpAnalyticsIdentityProvider = McpCatIdentityProviderexport type PostHogMcpAnalyticsOptions = {contextEnabled: boolean+ // Gate `get_more_tools` registration on non-single-exec mode. With the full+ // tool roster registered, a missing-tool report maps to a real gap in the+ // catalog. In single-exec mode the wrapper handles every call, so the+ // signal has nothing to map to and the extra slot is just noise.+ reportMissingEnabled: boolean}export type PostHogMcpAnalyticsInitResult =@@ -15,7 +20,7 @@ export type PostHogMcpAnalyticsInitResult =contextEnabled: booleantracingEnabled: trueaiTracingEnabled: true- reportMissingEnabled: true+ reportMissingEnabled: boolean}| {action: 'skipped'@@ -99,7 +104,7 @@ async function buildEventProperties(identity: PostHogMcpAnalyticsIdentityProvideexport async function initPostHogMcpAnalytics(server: McpServer,identity: PostHogMcpAnalyticsIdentityProvider,- options: PostHogMcpAnalyticsOptions = { contextEnabled: false }+ options: PostHogMcpAnalyticsOptions = { contextEnabled: false, reportMissingEnabled: false }): Promise<PostHogMcpAnalyticsInitResult> {const posthogApiKey = env.POSTHOG_ANALYTICS_API_KEYconst posthogHost = env.POSTHOG_ANALYTICS_HOST@@ -129,7 +134,7 @@ export async function initPostHogMcpAnalytics(flushInterval: 0,host: posthogHost,},- reportMissing: true,+ reportMissing: options.reportMissingEnabled,eventTags: async () => buildEventTags(identity),eventProperties: async () => buildEventProperties(identity),redactSensitiveInformation: (text) => Promise.resolve(redactSensitiveInformation(text)),@@ -140,7 +145,7 @@ export async function initPostHogMcpAnalytics(contextEnabled: options.contextEnabled,tracingEnabled: true,aiTracingEnabled: true,- reportMissingEnabled: true,+ reportMissingEnabled: options.reportMissingEnabled,}} catch (error) {return {diff --git a/services/mcp/src/mcp.ts b/services/mcp/src/mcp.tsindex 24d641870512..0fa0d972876e 100644--- a/services/mcp/src/mcp.ts+++ b/services/mcp/src/mcp.ts@@ -759,9 +759,14 @@ export class MCP extends McpAgent<Env> {// AI spans, context capture, and get_more_tools for flagged sessions.// Avoid initializing both wrappers because both patch tool handlers and// would double-capture every call.+ // `get_more_tools` only earns its keep outside single-exec mode — there+ // it lets the model report a gap in our discrete tool catalog. In+ // single-exec mode the wrapper handles every call, so the missing-tool+ // signal has nothing to map to and the extra slot is pure noise.if (posthogMcpAnalyticsOn) {const initResult = await initPostHogMcpAnalytics(this.server, mcpAnalyticsIdentity, {contextEnabled: true,+ reportMissingEnabled: !useSingleExec,})Object.assign(this.requestProperties, {posthogMcpAnalyticsInitAction: initResult.action,diff --git a/services/mcp/tests/unit/posthog-mcp-analytics.test.ts b/services/mcp/tests/unit/posthog-mcp-analytics.test.tsindex b2a722146c35..a05de6e73b42 100644--- a/services/mcp/tests/unit/posthog-mcp-analytics.test.ts+++ b/services/mcp/tests/unit/posthog-mcp-analytics.test.ts@@ -78,27 +78,59 @@ describe('initPostHogMcpAnalytics', () => {flushInterval: 0,host: TEST_HOST,},- reportMissing: true,+ reportMissing: false,}))- expect(result).toMatchObject({ action: 'initialized', contextEnabled: false })+ expect(result).toMatchObject({+ action: 'initialized',+ contextEnabled: false,+ reportMissingEnabled: false,+ })})it('enables required context only when explicitly requested', async () => {const server = new McpServer({ name: 'test', version: '1.0.0' })const identity = createMockIdentity()- const result = await initPostHogMcpAnalytics(server, identity, { contextEnabled: true })+ const result = await initPostHogMcpAnalytics(server, identity, {+ contextEnabled: true,+ reportMissingEnabled: false,+ })expect(track).toHaveBeenCalledWith(server,expect.objectContaining({context: true,enableAITracing: true,+ reportMissing: false,+ })+ )+ expect(result).toMatchObject({+ action: 'initialized',+ contextEnabled: true,+ reportMissingEnabled: false,+ })+ })++ it('enables get_more_tools (reportMissing) only when explicitly requested', async () => {+ const server = new McpServer({ name: 'test', version: '1.0.0' })+ const identity = createMockIdentity()++ const result = await initPostHogMcpAnalytics(server, identity, {+ contextEnabled: false,+ reportMissingEnabled: true,+ })++ expect(track).toHaveBeenCalledWith(+ server,+ expect.objectContaining({reportMissing: true,}))- expect(result).toMatchObject({ action: 'initialized', contextEnabled: true })+ expect(result).toMatchObject({+ action: 'initialized',+ reportMissingEnabled: true,+ })})it.each(['POSTHOG_ANALYTICS_API_KEY', 'POSTHOG_ANALYTICS_HOST'] as const)(