Skip to content

: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.

feat(mcp): explain interview recruitment eligibility (#118083)

Adam Bowker1f5caca9fa05
diff --git a/docs/published/handbook/engineering/ai/implementing-mcp-tools.md b/docs/published/handbook/engineering/ai/implementing-mcp-tools.md
index db9b1337b250..af0e2e1006a1 100644
--- a/docs/published/handbook/engineering/ai/implementing-mcp-tools.md
+++ b/docs/published/handbook/engineering/ai/implementing-mcp-tools.md
@@ -226,6 +226,31 @@ Recruitment analytics use the existing PostHog SDK and the MCP server's analytic
| `mcp interview booking link opened` | The invitation's redirect URL receives its first GET request. Repeated opens do not add events. |
| `mcp interview invitation responded` | A valid response is saved, with `response` equal to `accept`, `decline`, or `cancel`. |
+Tool-call events also carry recruitment diagnostics through the existing SDK capture path, without
+an extra event per eligibility check:
+
+| Property | Meaning |
+| ------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `interview_recruitment_reason` | The first gate that skipped recruitment, or `continuation` when resuming an invitation. |
+| `interview_recruitment_url_supported`, `interview_recruitment_form_supported` | Whether this request explicitly advertises each elicitation mode. `null` means the request carries no capability metadata; it does not prove the client lacks support. |
+| `interview_recruitment_campaign_id` | Selected campaign, when a valid recruitment configuration exists. |
+| `interview_recruitment_completed_calls`, `interview_recruitment_session_age_seconds` | Progress before the current call, when the warmup check was reached. |
+
+Reasons distinguish `legacy_protocol`, `url_unsupported`, `surface_excluded`, `internal_run`,
+`task_bound`, `flag_disabled`, `flag_unavailable`, `invalid_configuration`, `configuration_unavailable`,
+`not_product_call`, `missing_conversation`, `request_state_present`, `insufficient_tool_calls`,
+`session_too_young`, `suppressed`, `reservation_conflict`, and `redis_error`.
+`flag_unavailable` includes evaluation failures; it is not proof that the flag was evaluated as disabled.
+Only the first failing gate is recorded. A call with `flag_disabled` can also lack URL support; use the
+capability booleans to compare clients independently of the selected reason.
+
+The existing `mcp interview invitation sent` event includes these diagnostics with reason `invited`.
+A paused invitation has not executed a tool, so do not expect a completed tool-call event until its
+continuation runs. Exec emits one tool-call event relabeled to the inner tool. Filter
+`$mcp_exec_verb = 'call'` to exclude exec discovery commands, and include direct-tool events
+separately. Private scout tools, impersonated requests, and analytics-suppressed calls do not expose
+these diagnostics. No raw capability objects, tool arguments, or invitation answers are added.
+
Every event carries the authenticated user's distinct ID, `campaign_id`, `invitation_id`, and the `feature_flag`
key. The campaign comes from the selected variant and is retained for link opens and responses. Count distinct people for reach and invitation IDs for attempts. Invitations without a response
are unanswered, which can include abandonment, an open dialog, or a lost connection. An accepted
diff --git a/services/mcp/src/hono/analytics.ts b/services/mcp/src/hono/analytics.ts
index 4e4b0d769acb..911055534f5d 100644
--- a/services/mcp/src/hono/analytics.ts
+++ b/services/mcp/src/hono/analytics.ts
@@ -22,6 +22,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 { interviewRecruitmentProperties } from './interview-recruitment'
import { buildMCPSessionAnalyticsProperties, getEffectiveMCPClientIdentity } from './mcp-context'
import type { ResolvedState } from './request-state-resolver'
@@ -218,6 +219,9 @@ export async function trackToolCall(
properties: {
...properties,
tool_name: toolName,
+ ...(state.interviewRecruitmentDiagnostics && !state.isImpersonated && !state.suppressAnalytics
+ ? interviewRecruitmentProperties(state.interviewRecruitmentDiagnostics)
+ : {}),
...(!analyticsMeta?.llmModel && analyticsMeta?.llmModelMissingReason
? { $mcp_llm_model_missing_reason: analyticsMeta.llmModelMissingReason }
: {}),
diff --git a/services/mcp/src/hono/dispatcher.ts b/services/mcp/src/hono/dispatcher.ts
index 0ae4779d874b..8ff602ec3732 100644
--- a/services/mcp/src/hono/dispatcher.ts
+++ b/services/mcp/src/hono/dispatcher.ts
@@ -354,7 +354,7 @@ class McpDispatcher {
return await this.toolExecutor.handleToolCall(
params,
state!,
- stateless && params
+ params
? {
beforeExecute: (callState) =>
this.interviewRecruitment.beforeToolCall(
diff --git a/services/mcp/src/hono/interview-recruitment.ts b/services/mcp/src/hono/interview-recruitment.ts
index fe6336234807..003062deb346 100644
--- a/services/mcp/src/hono/interview-recruitment.ts
+++ b/services/mcp/src/hono/interview-recruitment.ts
@@ -2,7 +2,11 @@ import { createHash, randomUUID } from 'node:crypto'
import { z } from 'zod'
import { getPostHogClient } from '@/lib/posthog'
-import { META_CLIENT_CAPABILITIES } from '@/lib/stateless-protocol'
+import {
+ META_CLIENT_CAPABILITIES,
+ parseRequestProtocolMeta,
+ STATELESS_PROTOCOL_VERSION,
+} from '@/lib/stateless-protocol'
import { isPrivateScoutTrialTool } from '@/lib/tool-privacy'
import { parseExecCallInnerToolName } from '@/tools/exec'
@@ -30,6 +34,52 @@ const interviewRecruitmentConfigSchema = z.object({
export type InterviewRecruitmentConfig = z.infer<typeof interviewRecruitmentConfigSchema> & { campaign_id: string }
+export type InterviewRecruitmentUnavailableReason =
+ | 'surface_excluded'
+ | 'internal_run'
+ | 'task_bound'
+ | 'flag_disabled'
+ | 'flag_unavailable'
+ | 'invalid_configuration'
+
+export interface InterviewRecruitmentDiagnostics {
+ reason:
+ | InterviewRecruitmentUnavailableReason
+ | 'legacy_protocol'
+ | 'continuation'
+ | 'request_state_present'
+ | 'configuration_unavailable'
+ | 'url_unsupported'
+ | 'not_product_call'
+ | 'missing_conversation'
+ | 'suppressed'
+ | 'insufficient_tool_calls'
+ | 'session_too_young'
+ | 'reservation_conflict'
+ | 'redis_error'
+ | 'invited'
+ urlSupported: boolean | null
+ formSupported: boolean | null
+ campaignId?: string
+ completedCalls?: number
+ sessionAgeSeconds?: number
+}
+
+export function interviewRecruitmentProperties(diagnostics: InterviewRecruitmentDiagnostics): Record<string, unknown> {
+ return {
+ interview_recruitment_reason: diagnostics.reason,
+ interview_recruitment_url_supported: diagnostics.urlSupported,
+ interview_recruitment_form_supported: diagnostics.formSupported,
+ ...(diagnostics.campaignId ? { interview_recruitment_campaign_id: diagnostics.campaignId } : {}),
+ ...(diagnostics.completedCalls !== undefined
+ ? { interview_recruitment_completed_calls: diagnostics.completedCalls }
+ : {}),
+ ...(diagnostics.sessionAgeSeconds !== undefined
+ ? { interview_recruitment_session_age_seconds: diagnostics.sessionAgeSeconds }
+ : {}),
+ }
+}
+
export function resolveInterviewRecruitmentConfig(
value: unknown,
payload: unknown
@@ -107,7 +157,8 @@ export class InterviewRecruitment {
distinctId: string,
invitationId: string,
campaignId: string,
- response?: string
+ response?: string,
+ diagnostics?: InterviewRecruitmentDiagnostics
): void {
try {
getPostHogClient().capture({
@@ -118,6 +169,7 @@ export class InterviewRecruitment {
campaign_id: campaignId,
feature_flag: MCP_INTERVIEW_RECRUITMENT_FLAG,
...(response ? { response } : {}),
+ ...(diagnostics ? interviewRecruitmentProperties(diagnostics) : {}),
},
})
} catch {
@@ -177,12 +229,6 @@ export class InterviewRecruitment {
.digest('hex')
}
- private supportsUrl(params: Record<string, unknown>): boolean {
- return z
- .object({ elicitation: z.object({ url: z.object({}) }) })
- .safeParse((params._meta as Record<string, unknown> | undefined)?.[META_CLIENT_CAPABILITIES]).success
- }
-
private isProductCall(params: Record<string, unknown>, state: ResolvedState): boolean {
const args = params.arguments as Record<string, unknown> | undefined
const name =
@@ -203,21 +249,33 @@ export class InterviewRecruitment {
private eligibleConversation(
params: Record<string, unknown>,
state: ResolvedState
- ): { config: InterviewRecruitmentConfig; key: string } | undefined {
+ ): { config: InterviewRecruitmentConfig; key: string } | { reason: InterviewRecruitmentDiagnostics['reason'] } {
+ if (parseRequestProtocolMeta(params).protocolVersion !== STATELESS_PROTOCOL_VERSION) {
+ return { reason: 'legacy_protocol' }
+ }
+ if (params.requestState !== undefined) {
+ return { reason: 'request_state_present' }
+ }
const config = state.interviewRecruitmentConfig
+ if (!config) {
+ return { reason: state.interviewRecruitmentUnavailableReason ?? 'configuration_unavailable' }
+ }
+ if (state.isImpersonated || state.suppressAnalytics) {
+ return { reason: 'suppressed' }
+ }
if (
- params.requestState !== undefined ||
- !config ||
- state.isImpersonated ||
- state.suppressAnalytics ||
- !this.supportsUrl(params) ||
- !this.isProductCall(params, state)
+ !z
+ .object({ elicitation: z.object({ url: z.object({}) }) })
+ .safeParse((params._meta as Record<string, unknown> | undefined)?.[META_CLIENT_CAPABILITIES]).success
) {
- return undefined
+ return { reason: 'url_unsupported' }
+ }
+ if (!this.isProductCall(params, state)) {
+ return { reason: 'not_product_call' }
}
const conversation = resolveSessionKey(state.requestContext)
if (!conversation) {
- return undefined
+ return { reason: 'missing_conversation' }
}
const client = state.requestContext
const hash = createHash('sha256')
@@ -242,7 +300,7 @@ export class InterviewRecruitment {
return
}
const conversation = this.eligibleConversation(params, state)
- if (!conversation) {
+ if ('reason' in conversation) {
return
}
try {
@@ -340,13 +398,35 @@ export class InterviewRecruitment {
userHash: string,
requestOrigin: string
): Promise<Record<string, unknown> | undefined> {
- if (typeof params.requestState === 'string' && params.requestState.startsWith(STATE_PREFIX)) {
+ const capabilities = (params._meta as Record<string, unknown> | undefined)?.[META_CLIENT_CAPABILITIES]
+ const capabilitiesAvailable = z.record(z.string(), z.unknown()).safeParse(capabilities).success
+ const diagnostics: InterviewRecruitmentDiagnostics = {
+ reason: 'continuation',
+ urlSupported: capabilitiesAvailable
+ ? z.object({ elicitation: z.object({ url: z.object({}) }) }).safeParse(capabilities).success
+ : null,
+ formSupported: capabilitiesAvailable
+ ? z
+ .object({
+ elicitation: z.union([z.object({ form: z.object({}) }), z.object({}).strict()]),
+ })
+ .safeParse(capabilities).success
+ : null,
+ ...(state.interviewRecruitmentConfig ? { campaignId: state.interviewRecruitmentConfig.campaign_id } : {}),
+ }
+ state.interviewRecruitmentDiagnostics = diagnostics
+ if (
+ parseRequestProtocolMeta(params).protocolVersion === STATELESS_PROTOCOL_VERSION &&
+ typeof params.requestState === 'string' &&
+ params.requestState.startsWith(STATE_PREFIX)
+ ) {
// A flag change must not discard a response to an invitation that was already displayed.
await this.resume(params, state, userHash)
return undefined
}
const conversation = this.eligibleConversation(params, state)
- if (!conversation) {
+ if ('reason' in conversation) {
+ diagnostics.reason = conversation.reason
return undefined
}
const { config, key: conversationKey } = conversation
@@ -357,6 +437,7 @@ export class InterviewRecruitment {
const preferenceKey = this.preferenceKey(state)
try {
if ((await this.redis.get(preferenceKey)) !== null) {
+ diagnostics.reason = 'suppressed'
return undefined
}
const now = Date.now()
@@ -365,10 +446,14 @@ export class InterviewRecruitment {
.parse(
await this.redis.eval(OBSERVE_CONVERSATION, 1, conversationKey, now, CONVERSATION_IDLE_SECONDS, '')
)
- if (
- progress[0] < config.min_completed_tool_calls ||
- now - progress[1] < config.min_session_age_seconds * 1000
- ) {
+ diagnostics.completedCalls = progress[0]
+ diagnostics.sessionAgeSeconds = Math.max(0, Math.floor((now - progress[1]) / 1000))
+ if (progress[0] < config.min_completed_tool_calls) {
+ diagnostics.reason = 'insufficient_tool_calls'
+ return undefined
+ }
+ if (now - progress[1] < config.min_session_age_seconds * 1000) {
+ diagnostics.reason = 'session_too_young'
return undefined
}
const [organizationId, projectId] = await Promise.all([
@@ -406,15 +491,25 @@ export class InterviewRecruitment {
PENDING_SECONDS
)
if (reserved !== 1) {
+ diagnostics.reason = 'reservation_conflict'
await this.redis.del(linkKey)
return undefined
}
} catch {
// If suppression cannot be checked atomically, skip recruitment and let the user's task proceed.
+ diagnostics.reason = 'redis_error'
return undefined
}
- this.track('mcp interview invitation sent', state.distinctId, invitationId, config.campaign_id)
+ diagnostics.reason = 'invited'
+ this.track(
+ 'mcp interview invitation sent',
+ state.distinctId,
+ invitationId,
+ config.campaign_id,
+ undefined,
+ diagnostics
+ )
const bookingLink = new URL(`/interview/${invitationId}`, requestOrigin).toString()
return {
resultType: 'input_required',
diff --git a/services/mcp/src/hono/request-state-resolver.ts b/services/mcp/src/hono/request-state-resolver.ts
index 08cfbd19d962..b0e2701f0f10 100644
--- a/services/mcp/src/hono/request-state-resolver.ts
+++ b/services/mcp/src/hono/request-state-resolver.ts
@@ -30,6 +30,8 @@ import { MCP_EXEC_SKILLS_FEATURE_FLAG } from './constants'
import { MCP_INTENT_PROMPT_FLAG, resolveIntentPrompt } from './intent-prompt'
import {
type InterviewRecruitmentConfig,
+ type InterviewRecruitmentDiagnostics,
+ type InterviewRecruitmentUnavailableReason,
resolveInterviewRecruitmentConfig,
MCP_INTERVIEW_RECRUITMENT_FLAG,
} from './interview-recruitment'
@@ -52,6 +54,8 @@ export interface ResolvedState {
toolFeatureFlags: EvaluatedFlags | undefined
interviewRecruitmentConfig?: InterviewRecruitmentConfig
intentPrompt?: string
+ interviewRecruitmentUnavailableReason?: InterviewRecruitmentUnavailableReason
+ interviewRecruitmentDiagnostics?: InterviewRecruitmentDiagnostics
apiKeyScopes: string[]
isImpersonated?: boolean
suppressAnalytics?: boolean
@@ -213,13 +217,25 @@ export class RequestStateResolver {
// Local opt-in still requires explicit, valid invitation content.
}
}
- const interviewRecruitmentConfig =
- source === EVENT_SOURCE.MCP &&
- !_apiKey?.scopes?.includes('internal_run:read') &&
- !props.taskId &&
- !props.taskOriginProduct
- ? resolveInterviewRecruitmentConfig(mergedFlags[MCP_INTERVIEW_RECRUITMENT_FLAG], recruitmentPayload)
- : undefined
+ const recruitmentFlagValue = mergedFlags[MCP_INTERVIEW_RECRUITMENT_FLAG]
+ let interviewRecruitmentUnavailableReason: InterviewRecruitmentUnavailableReason | undefined
+ if (source !== EVENT_SOURCE.MCP) {
+ interviewRecruitmentUnavailableReason = 'surface_excluded'
+ } else if (_apiKey?.scopes?.includes('internal_run:read')) {
+ interviewRecruitmentUnavailableReason = 'internal_run'
+ } else if (props.taskId || props.taskOriginProduct) {
+ interviewRecruitmentUnavailableReason = 'task_bound'
+ } else if (recruitmentFlagValue === undefined) {
+ interviewRecruitmentUnavailableReason = 'flag_unavailable'
+ } else if (recruitmentFlagValue === false) {
+ interviewRecruitmentUnavailableReason = 'flag_disabled'
+ }
+ const interviewRecruitmentConfig = interviewRecruitmentUnavailableReason
+ ? undefined
+ : resolveInterviewRecruitmentConfig(recruitmentFlagValue, recruitmentPayload)
+ if (!interviewRecruitmentUnavailableReason && !interviewRecruitmentConfig) {
+ interviewRecruitmentUnavailableReason = 'invalid_configuration'
+ }
// Preserve variant strings (and `undefined` for unevaluated flags) — the
// tool filter needs raw values to support `feature_flag_variant` matching.
// Include override keys so a forced flag reaches the tool/instructions layer
@@ -297,6 +313,7 @@ export class RequestStateResolver {
toolFeatureFlags,
interviewRecruitmentConfig,
intentPrompt,
+ interviewRecruitmentUnavailableReason,
apiKeyScopes,
isImpersonated: _apiKey?.is_impersonated === true,
suppressAnalytics: props.suppressAnalytics,
diff --git a/services/mcp/tests/hono/analytics.test.ts b/services/mcp/tests/hono/analytics.test.ts
index a4ff8b46197b..4c3941c78245 100644
--- a/services/mcp/tests/hono/analytics.test.ts
+++ b/services/mcp/tests/hono/analytics.test.ts
@@ -93,6 +93,36 @@ describe('Hono MCP analytics contexts', () => {
mockCapture.mockClear()
})
+ it.each([false, true])(
+ 'records recruitment diagnostics without exposing them on suppressed calls: %s',
+ async (suppressed) => {
+ const state = makeState({
+ suppressAnalytics: suppressed,
+ interviewRecruitmentDiagnostics: {
+ reason: 'url_unsupported',
+ urlSupported: false,
+ formSupported: true,
+ campaignId: 'synthetic-study',
+ },
+ })
+ await trackToolCall('user-get', 12, false, state)
+ const properties = mockCaptureToolCall.mock.calls[0]![0].properties
+ if (suppressed) {
+ expect(properties).not.toHaveProperty('interview_recruitment_reason')
+ expect(properties).not.toHaveProperty('interview_recruitment_form_supported')
+ } else {
+ expect(properties).toMatchObject({
+ interview_recruitment_reason: 'url_unsupported',
+ interview_recruitment_url_supported: false,
+ interview_recruitment_form_supported: true,
+ interview_recruitment_campaign_id: 'synthetic-study',
+ })
+ expect(properties).not.toHaveProperty('interview_recruitment_completed_calls')
+ }
+ expect(mockCapture).not.toHaveBeenCalled()
+ }
+ )
+
it('does not dual-emit the retired legacy mcp_tool_call / mcp_initialize names', async () => {
// Guards against reintroducing the legacy dual-emit, which double-counted every call.
await trackInitEvent(makeState())
diff --git a/services/mcp/tests/hono/interview-recruitment.test.ts b/services/mcp/tests/hono/interview-recruitment.test.ts
index 6515375b4798..54809bc380cd 100644
--- a/services/mcp/tests/hono/interview-recruitment.test.ts
+++ b/services/mcp/tests/hono/interview-recruitment.test.ts
@@ -221,6 +221,8 @@ describe('MCP interview recruitment', () => {
distinctId: 'test-person',
properties: expect.objectContaining({
invitation_id: String(invitation.result?.requestState).slice('mcp-interview:'.length),
+ interview_recruitment_reason: 'invited',
+ interview_recruitment_url_supported: true,
}),
})
)
@@ -257,6 +259,7 @@ describe('MCP interview recruitment', () => {
)
expect(storage.redis.set).not.toHaveBeenCalled()
expect(storage.redis.eval).not.toHaveBeenCalled()
+ expect(state.interviewRecruitmentDiagnostics?.reason).toBe('suppressed')
storage.entries.delete(key)
expect((await call(reconnected)).result?.resultType).toBe('input_required')
}
@@ -283,13 +286,20 @@ describe('MCP interview recruitment', () => {
expect((await call(dispatcher)).result?.resultType).toBe('input_required')
})
- it.each([{}, { elicitation: {} }, { elicitation: { form: {} } }, { elicitation: false }])(
- 'skips clients without URL support: %j',
- async (capabilities) => {
- expect((await call(dispatcher, callParams(capabilities))).result).toMatchObject(toolResult)
- expect(storage.entries.size).toBe(0)
- }
- )
+ it.each([
+ [{}, false],
+ [{ elicitation: {} }, true],
+ [{ elicitation: { form: {} } }, true],
+ [{ elicitation: false }, false],
+ ] as const)('skips clients without URL support: %j', async (capabilities, formSupported) => {
+ expect((await call(dispatcher, callParams(capabilities))).result).toMatchObject(toolResult)
+ expect(state.interviewRecruitmentDiagnostics).toMatchObject({
+ reason: 'url_unsupported',
+ urlSupported: false,
+ formSupported,
+ })
+ expect(storage.entries.size).toBe(0)
+ })
it.each(['disabled', 'missing', 'impersonated', 'suppressed', 'invalid-payload'])(
'skips recruitment when %s',
@@ -336,11 +346,27 @@ describe('MCP interview recruitment', () => {
booking_url: 'https://example.com/book',
})
expect((await call(dispatcher)).result).toMatchObject(toolResult)
+ expect(state.interviewRecruitmentDiagnostics).toMatchObject({
+ reason: 'insufficient_tool_calls',
+ completedCalls: 0,
+ sessionAgeSeconds: 0,
+ })
expect((await call(dispatcher)).result).toMatchObject(toolResult)
- vi.advanceTimersByTime(120_000)
expect((await call(dispatcher)).result).toMatchObject(toolResult)
+ expect((await call(dispatcher)).result).toMatchObject(toolResult)
+ expect(state.interviewRecruitmentDiagnostics).toMatchObject({
+ reason: 'session_too_young',
+ completedCalls: 3,
+ sessionAgeSeconds: 0,
+ })
+ vi.advanceTimersByTime(120_000)
expect((await call(dispatcher)).result?.resultType).toBe('input_required')
- expect(executeTool).toHaveBeenCalledTimes(3)
+ expect(state.interviewRecruitmentDiagnostics).toMatchObject({
+ reason: 'invited',
+ completedCalls: 4,
+ sessionAgeSeconds: 120,
+ })
+ expect(executeTool).toHaveBeenCalledTimes(4)
})
it.each(['failed', 'search', 'learn', 'skill', 'docs'])(
@@ -447,6 +473,11 @@ describe('MCP interview recruitment', () => {
const result = (await (await dispatcher.handleRequest(legacy, props)).json()) as { result: unknown }
expect(result.result).toEqual(toolResult)
expect(storage.entries.size).toBe(0)
+ expect(state.interviewRecruitmentDiagnostics).toMatchObject({
+ reason: 'legacy_protocol',
+ urlSupported: null,
+ formSupported: null,
+ })
})
it.each(['token', 'person', 'arguments', 'project', 'organization', 'expired', 'replayed', 'invalid-answer'])(
@@ -502,6 +533,7 @@ describe('MCP interview recruitment', () => {
it('skips the invitation if Redis fails, but retries a response write before executing the tool', async () => {
vi.mocked(storage.redis.eval).mockRejectedValueOnce(new Error('unavailable'))
expect((await call(dispatcher)).result).toMatchObject(toolResult)
+ expect(state.interviewRecruitmentDiagnostics?.reason).toBe('redis_error')
executeTool.mockClear()
const invitation = await call(dispatcher)
const resumed = continuation(invitation.result?.requestState, { action: 'decline' })
diff --git a/services/mcp/tests/hono/request-state-resolver.test.ts b/services/mcp/tests/hono/request-state-resolver.test.ts
index deb0ad349995..4db69da2237a 100644
--- a/services/mcp/tests/hono/request-state-resolver.test.ts
+++ b/services/mcp/tests/hono/request-state-resolver.test.ts
@@ -545,6 +545,9 @@ describe('RequestStateResolver MCP client contexts', () => {
expect(result.oauthClientId).toBe(input.oauthClientId)
}
expect(result.interviewRecruitmentConfig).toBeUndefined()
+ expect(result.interviewRecruitmentUnavailableReason).toBe(
+ input.oauthClientId || input.mcpConsumer ? 'surface_excluded' : input.scopes ? 'internal_run' : 'task_bound'
+ )
})
it.each([
@@ -597,8 +600,12 @@ describe('RequestStateResolver MCP client contexts', () => {
const state = await makeResolver().resolve(makeProps())
if (expected) {
expect(state.interviewRecruitmentConfig).toMatchObject(expected)
+ expect(state.interviewRecruitmentUnavailableReason).toBeUndefined()
} else {
expect(state.interviewRecruitmentConfig).toBeUndefined()
+ expect(state.interviewRecruitmentUnavailableReason).toBe(
+ value === false ? 'flag_disabled' : 'invalid_configuration'
+ )
}
}
)
diff --git a/services/mcp/tests/hono/tool-executor-intent.test.ts b/services/mcp/tests/hono/tool-executor-intent.test.ts
index 01562529c401..97030b78c395 100644
--- a/services/mcp/tests/hono/tool-executor-intent.test.ts
+++ b/services/mcp/tests/hono/tool-executor-intent.test.ts
@@ -501,6 +501,11 @@ describe('ToolExecutor analytics capture', () => {
const hooks = {
beforeExecute: async (callState: ResolvedState): Promise<undefined> => {
observedHandles.push(callState.requestContext.mcpConversationId)
+ callState.interviewRecruitmentDiagnostics = {
+ reason: 'url_unsupported',
+ urlSupported: false,
+ formSupported: true,
+ }
return undefined
},
afterExecute: async (): Promise<void> => {},
@@ -511,6 +516,12 @@ describe('ToolExecutor analytics capture', () => {
expect(handle).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/)
await vi.waitFor(() => expect(captureSpy).toHaveBeenCalledTimes(1))
expect(captureSpy.mock.calls[0]![0].conversationId).toBe(handle)
+ expect(captureSpy.mock.calls[0]![0].properties).toMatchObject({
+ interview_recruitment_reason: 'url_unsupported',
+ interview_recruitment_url_supported: false,
+ interview_recruitment_form_supported: true,
+ })
+ expect(state.interviewRecruitmentDiagnostics).toBeUndefined()
const secondState = statelessState()
const second = await executor.handleToolCall(