: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): stamp no_consent when consent-gated tools leave the roster (#127421)
Adam Bowkera14e661e86eb
diff --git a/services/mcp/src/hono/guidance/engine.ts b/services/mcp/src/hono/guidance/engine.tsindex bd0e206ff1b8..d2890413fe25 100644--- a/services/mcp/src/hono/guidance/engine.ts+++ b/services/mcp/src/hono/guidance/engine.ts@@ -76,9 +76,11 @@ function isGuidanceAudience(state: ResolvedState): boolean {// flag off, or without AI consent, is counted the same way, so the stamped outcome gives a// control group and a measure of how often consent blocks the notice.function ruleApplies(rule: GuidanceRule, state: ResolvedState, preset: string): boolean {+ // The roster drops consent-gated tools without org consent, so it cannot decide these callers.+ const withheldForConsent = rule.requiresAiConsent === true && state.aiConsentGiven !== truereturn (rule.trigger.presets.includes(preset as GuidanceRule['trigger']['presets'][number]) &&- rule.requiresTool.every((name) => state.allTools.some((tool) => tool.name === name))+ (withheldForConsent || rule.requiresTool.every((name) => state.allTools.some((tool) => tool.name === name))))}diff --git a/services/mcp/tests/hono/guidance-engine.test.ts b/services/mcp/tests/hono/guidance-engine.test.tsindex 86978a1a6ee6..5880d49ddd4c 100644--- a/services/mcp/tests/hono/guidance-engine.test.ts+++ b/services/mcp/tests/hono/guidance-engine.test.ts@@ -83,7 +83,10 @@ describe('GuidanceEngine', () => {['with org consent', true, 'shown'],])('stamps the consent outcome %s for a rule that needs it', async (_label, aiConsentGiven, outcome) => {const engine = new GuidanceEngine(makeGuidanceRedis(), [{ ...rule, requiresAiConsent: true }])- const state = makeState({ aiConsentGiven })+ const state = makeState({+ aiConsentGiven,+ ...(aiConsentGiven === true ? {} : { allTools: [{ name: 'execute-sql' }] as ResolvedState['allTools'] }),+ })await engine.evaluate(state, replayQuery)const notice = await engine.evaluate(state, replayQuery)expect(notice).toMatchObject({ ruleId: 'test-rule', outcome })