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.

fix(mcp): serve exec learn guides to every claude.ai connector surface (#106310)

Jake Ruth343466df175c
diff --git a/services/mcp/src/hono/instructions.ts b/services/mcp/src/hono/instructions.ts
index c24e29415663..8a92893a6abc 100644
--- a/services/mcp/src/hono/instructions.ts
+++ b/services/mcp/src/hono/instructions.ts
@@ -200,8 +200,10 @@ export class InstructionsBuilder {
if (clientContext.mcpConsumer === 'plugin' || isPostHogCodeConsumer(clientContext.mcpConsumer)) {
return { guidesEnabled: false, skillsEnabled: false }
}
+ // The connector's header-less `tools/list` advertises guides to every surface, so the call serves them too.
+ const { clientProfile } = state
return {
- guidesEnabled: state.clientProfile.isClaudeChatHost(),
+ guidesEnabled: clientProfile.isClaudeChatHost() || clientProfile.isAnthropicConnector(),
skillsEnabled: state.toolFeatureFlags?.[MCP_EXEC_SKILLS_FEATURE_FLAG] === true,
}
}
diff --git a/services/mcp/src/lib/client-detection.ts b/services/mcp/src/lib/client-detection.ts
index d501c129bf1a..63cd03401b66 100644
--- a/services/mcp/src/lib/client-detection.ts
+++ b/services/mcp/src/lib/client-detection.ts
@@ -297,8 +297,12 @@ export class MCPClientProfile {
// `clientInfo.name`. Unlike `isClaudeUiHost`, matching the pooled name here
// is safe and intended: every Anthropic product belongs in CLI mode, so
// there is nothing to misclassify.
+ return matchesAnyFragment(this.vendorClient, ANTHROPIC_CLIENT_NAME_FRAGMENTS) || this.isAnthropicConnector()
+ }
+
+ isAnthropicConnector(): boolean {
+ // The connector omits `x-anthropic-client` on `tools/list` and sends it on the call, so this must not read it.
return (
- matchesAnyFragment(this.vendorClient, ANTHROPIC_CLIENT_NAME_FRAGMENTS) ||
matchesAnyFragment(this.userAgent, ANTHROPIC_USER_AGENT_FRAGMENTS) ||
normalizeClientName(this.clientName ?? '').startsWith('anthropic')
)
diff --git a/services/mcp/tests/hono/analytics.test.ts b/services/mcp/tests/hono/analytics.test.ts
index 34b6c14b275a..bbe7b5843d48 100644
--- a/services/mcp/tests/hono/analytics.test.ts
+++ b/services/mcp/tests/hono/analytics.test.ts
@@ -599,7 +599,7 @@ describe('Hono MCP analytics contexts', () => {
function skillsState(): ResolvedState {
return makeState({
- clientProfile: { isClaudeChatHost: () => false } as any,
+ clientProfile: { isClaudeChatHost: () => false, isAnthropicConnector: () => false } as any,
toolFeatureFlags: { [MCP_EXEC_SKILLS_FEATURE_FLAG]: true },
})
}
diff --git a/services/mcp/tests/hono/tool-executor.test.ts b/services/mcp/tests/hono/tool-executor.test.ts
index dc49331f8a08..4768dac55b43 100644
--- a/services/mcp/tests/hono/tool-executor.test.ts
+++ b/services/mcp/tests/hono/tool-executor.test.ts
@@ -17,6 +17,7 @@ import { InstructionsBuilder } from '@/hono/instructions'
import type { ResolvedState } from '@/hono/request-state-resolver'
import { ToolCatalog } from '@/hono/tool-catalog'
import { ToolExecutor } from '@/hono/tool-executor'
+import { MCPClientProfile } from '@/lib/client-detection'
import { PostHogApiError } from '@/lib/errors'
import { buildToolDomainsCompact } from '@/lib/instructions'
import { RENDER_UI_RESOURCE_URI, URI_MAP } from '@/resources/ui-apps.generated'
@@ -268,7 +269,7 @@ describe('ToolExecutor', () => {
expectSkills: true,
},
{
- label: 'Claude Code with flag off',
+ label: 'directly connected Claude Code with flag off',
isClaudeChatHost: false,
skillsEnabled: false,
consumer: undefined,
@@ -276,7 +277,7 @@ describe('ToolExecutor', () => {
expectSkills: false,
},
{
- label: 'Claude Code with flag on',
+ label: 'directly connected Claude Code with flag on',
isClaudeChatHost: false,
skillsEnabled: true,
consumer: undefined,
@@ -321,6 +322,7 @@ describe('ToolExecutor', () => {
isClaudeUiHost: vi.fn(() => isClaudeChatHost),
isInlineExecUiHost: vi.fn(() => false),
isClaudeChatHost: vi.fn(() => isClaudeChatHost),
+ isAnthropicConnector: vi.fn(() => isClaudeChatHost),
} as any,
...(consumer
? {
@@ -375,6 +377,71 @@ describe('ToolExecutor', () => {
}
)
+ it.each([
+ { vendorClient: 'ClaudeCode', skillsEnabled: false },
+ { vendorClient: 'ClaudeCode', skillsEnabled: true },
+ { vendorClient: 'Cowork', skillsEnabled: false },
+ { vendorClient: 'Cowork', skillsEnabled: true },
+ ])(
+ 'serves the advertised guides when the call names $vendorClient (skills flag: $skillsEnabled)',
+ async ({ vendorClient, skillsEnabled }) => {
+ const tools = catalog
+ .getPreBuiltEntries()
+ .slice(0, 5)
+ .map(({ name }) => ({ name }))
+ const connectorState = (profile: MCPClientProfile): ResolvedState =>
+ makeToolExecutorState(tools, {
+ useSingleExec: true,
+ toolFeatureFlags: { [MCP_EXEC_SKILLS_FEATURE_FLAG]: skillsEnabled },
+ clientProfile: profile,
+ })
+ const listState = connectorState(
+ new MCPClientProfile({ clientName: 'Anthropic/ClaudeAI', userAgent: 'Claude-User' })
+ )
+ const callState = connectorState(
+ new MCPClientProfile({ clientName: 'Anthropic/ClaudeAI', vendorClient, userAgent: 'Claude-User' })
+ )
+
+ const listed = await executor.handleToolsList(listState)
+ const commandDescription = (listed.tools[0]!.inputSchema.properties as any).command
+ .description as string
+ expect(commandDescription).toContain('- analytics:')
+
+ const result = (await executor.handleToolCall(
+ { name: 'exec', arguments: { command: 'learn analytics' } },
+ callState
+ )) as { content: { text: string }[]; isError?: boolean }
+ expect(result.isError).toBeFalsy()
+ expect(result.content[0]!.text).toContain('### Retrieving data')
+ }
+ )
+
+ it.each([{ skillsEnabled: false }, { skillsEnabled: true }])(
+ 'keeps guides off a directly connected Claude Code CLI (skills flag: $skillsEnabled)',
+ async ({ skillsEnabled }) => {
+ const state = makeToolExecutorState(
+ catalog
+ .getPreBuiltEntries()
+ .slice(0, 5)
+ .map(({ name }) => ({ name })),
+ {
+ useSingleExec: true,
+ toolFeatureFlags: { [MCP_EXEC_SKILLS_FEATURE_FLAG]: skillsEnabled },
+ clientProfile: new MCPClientProfile({ clientName: 'claude-code', vendorClient: 'ClaudeCode' }),
+ }
+ )
+
+ const result = (await executor.handleToolCall(
+ { name: 'exec', arguments: { command: 'learn analytics' } },
+ state
+ )) as { content: { text: string }[]; isError?: boolean }
+ expect(result.isError).toBe(true)
+ expect(result.content[0]!.text).toContain(
+ skillsEnabled ? 'Unknown learning topic' : 'learn command is not available'
+ )
+ }
+ )
+
it('discovers and searches current-project skills when the connection has read scope', async () => {
const apiRequest = vi.fn().mockImplementation(async ({ path }: { path: string }) => {
if (path.endsWith('/search/')) {
@@ -491,6 +558,7 @@ describe('ToolExecutor', () => {
isClaudeUiHost: vi.fn(() => false),
isInlineExecUiHost: vi.fn(() => false),
isClaudeChatHost: vi.fn(() => isClaudeChatHost),
+ isAnthropicConnector: vi.fn(() => isClaudeChatHost),
} as any,
})
@@ -526,6 +594,7 @@ describe('ToolExecutor', () => {
isClaudeUiHost: vi.fn(() => false),
isInlineExecUiHost: vi.fn(() => false),
isClaudeChatHost: vi.fn(() => true),
+ isAnthropicConnector: vi.fn(() => true),
} as any,
}
)
diff --git a/services/mcp/tests/integration/skill-analytics.integration.test.ts b/services/mcp/tests/integration/skill-analytics.integration.test.ts
index 931fb0d6cca4..0d6bcf2c72be 100644
--- a/services/mcp/tests/integration/skill-analytics.integration.test.ts
+++ b/services/mcp/tests/integration/skill-analytics.integration.test.ts
@@ -114,6 +114,7 @@ describe.skipIf(!API_TOKEN)('skill read reaches PostHog with $mcp_skill_name', (
isClaudeUiHost: () => false,
isInlineExecUiHost: () => false,
isClaudeChatHost: () => false,
+ isAnthropicConnector: () => false,
},
requestContext: {
authMethod: 'personal_api_key',
diff --git a/services/mcp/tests/shared/test-utils.ts b/services/mcp/tests/shared/test-utils.ts
index 9232319555b1..cccd54c645c3 100644
--- a/services/mcp/tests/shared/test-utils.ts
+++ b/services/mcp/tests/shared/test-utils.ts
@@ -685,6 +685,7 @@ export function makeToolExecutorState(
isClaudeUiHost: vi.fn(() => false),
isInlineExecUiHost: vi.fn(() => false),
isClaudeChatHost: vi.fn(() => false),
+ isAnthropicConnector: vi.fn(() => false),
} as any,
requestContext: {
authMethod: 'personal_api_key',
diff --git a/services/mcp/tests/unit/client-detection.test.ts b/services/mcp/tests/unit/client-detection.test.ts
index 60e52dcbc1f1..ee719b4ec3bc 100644
--- a/services/mcp/tests/unit/client-detection.test.ts
+++ b/services/mcp/tests/unit/client-detection.test.ts
@@ -488,6 +488,20 @@ describe('MCPClientProfile', () => {
})
})
+ describe('isAnthropicConnector()', () => {
+ it.each([
+ [{ clientName: 'Anthropic/ClaudeAI', userAgent: 'Claude-User' }, true],
+ [{ clientName: 'Anthropic/ClaudeAI', vendorClient: 'ClaudeCode', userAgent: 'Claude-User' }, true],
+ [{ clientName: 'Anthropic/ClaudeAI', vendorClient: 'Cowork', userAgent: 'Claude-User' }, true],
+ [{ vendorClient: 'ClaudeAI', userAgent: 'Claude-User' }, true],
+ [{ clientName: 'claude-code', vendorClient: 'ClaudeCode' }, false],
+ [{ vendorClient: 'ClaudeCode' }, false],
+ [{}, false],
+ ])('resolves %j to %s', (input, expected) => {
+ expect(new MCPClientProfile(input).isAnthropicConnector()).toBe(expected)
+ })
+ })
+
describe('capabilities.supportsInstructions', () => {
it.each([['codex'], ['Codex'], ['CODEX'], ['codex-cli'], ['Codex CLI'], ['codex/1.2.3'], ['openai-codex']])(
'is false for Codex variant %s',