: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(cli): remove agent api experimental gate (#64697)
Chris Volzerf0bb5426d516
diff --git a/cli/.sampo/changesets/remove-agent-api-gate.md b/cli/.sampo/changesets/remove-agent-api-gate.mdnew file mode 100644index 000000000000..2e5f722b100d--- /dev/null+++ b/cli/.sampo/changesets/remove-agent-api-gate.md@@ -0,0 +1,5 @@+---+cargo/posthog-cli: patch+---++Remove the `posthog-cli api` experimental opt-in and skip unavailable generated tools without warning noise.diff --git a/cli/src/commands.rs b/cli/src/commands.rsindex a0e0116943ba..a946f6e4be16 100644--- a/cli/src/commands.rs+++ b/cli/src/commands.rs@@ -137,8 +137,6 @@ pub enum Commands {skill install [--force] <skill-id> Install a skill into .agents/skills/\n \agents-md install [--path AGENTS.md] Install the PostHog steering snippet\n\n\Run `posthog-cli api --agent-help` for the full agent-facing usage guide.\n\n\- This command group is experimental: pass `--experimental` after `api`, or set \- POSTHOG_CLI_EXPERIMENTAL_API=1.\n\Destructive tools require --confirm. Use --dry-run before mutations.\n\n\Limitation: `login` grants the MCP scope set minus the writes PostHog \withholds from long-lived API keys, so a few tools (desktop file-system \diff --git a/services/mcp/src/cli/agent-help.ts b/services/mcp/src/cli/agent-help.tsindex 7db9cd82e4ec..a4280ab0ed93 100644--- a/services/mcp/src/cli/agent-help.ts+++ b/services/mcp/src/cli/agent-help.ts@@ -3,14 +3,10 @@ import { type InstructionsContext, InstructionsFormatter } from '@/lib/instructiimport { getToolDefinition } from '@/tools/toolDefinitions'import type { Tool, ZodObjectAny } from '@/tools/types'-import { EXPERIMENTAL_API_ENV } from './experimental'-const AGENT_HELP_HEADER = `# PostHog API guide for agents\`posthog-cli api\` is the agent-first interface to the PostHog API. It exposes the same tool surface as the PostHog MCP server's \`exec\` tool, so the reference below is the canonical guide for interacting with PostHog. Treat it as instructions to follow, not just documentation.-The command group is experimental: pass \`--experimental\` right after \`api\`, or set \`${EXPERIMENTAL_API_ENV}=1\` in the environment.-On top of the reference below, the CLI adds:- \`posthog-cli api call --dry-run <tool> '<json>'\` — validate input against the tool schema without executing. Use it before any mutation.diff --git a/services/mcp/src/cli/agents-md-snippet.md b/services/mcp/src/cli/agents-md-snippet.mdindex 518c5a1e25cd..05e421fce74b 100644--- a/services/mcp/src/cli/agents-md-snippet.md+++ b/services/mcp/src/cli/agents-md-snippet.md@@ -1,8 +1,6 @@## PostHog-Use `posthog-cli api` for all PostHog-related queries and operations. You should use `posthog-cli api` over direct MCP tool calls whenever the CLI is available. If `posthog-cli` is not installed, run it with `npx -y @posthog/cli@latest` instead (for example `npx -y @posthog/cli@latest api search feature-flag`).--The `posthog-cli api` command group is experimental. If it reports that the command group is disabled, rerun commands with `POSTHOG_CLI_EXPERIMENTAL_API=1` in the environment or pass `--experimental` immediately after `api`.+Use `posthog-cli api` for all PostHog-related data queries and operations. You should use `posthog-cli api` over direct MCP tool calls whenever the CLI is available.Before your first PostHog command in a session, run `posthog-cli api --agent-help` and load its full output into your context. It prints the complete agent guide — command reference, schema drill-down rules, data discovery workflow, and the tool index — for interacting with PostHog APIs. Treat that output as instructions to follow, not just documentation.diff --git a/services/mcp/src/cli/experimental.ts b/services/mcp/src/cli/experimental.tsdeleted file mode 100644index 75e921897f84..000000000000--- a/services/mcp/src/cli/experimental.ts+++ /dev/null@@ -1,18 +0,0 @@-export const EXPERIMENTAL_API_ENV = 'POSTHOG_CLI_EXPERIMENTAL_API'--const ENABLED_VALUES = new Set(['1', 'true', 'yes', 'on'])--export function isExperimentalApiEnabled(env: NodeJS.ProcessEnv = process.env): boolean {- const value = env[EXPERIMENTAL_API_ENV]- return value ? ENABLED_VALUES.has(value.toLowerCase()) : false-}--export function requireExperimentalApiEnabled(opts: { flagEnabled?: boolean; env?: NodeJS.ProcessEnv } = {}): void {- if (opts.flagEnabled || isExperimentalApiEnabled(opts.env)) {- return- }-- throw new Error(- `The \`posthog-cli api\` command group is experimental. Set ${EXPERIMENTAL_API_ENV}=1 or pass --experimental to use it.`- )-}diff --git a/services/mcp/src/cli/index.ts b/services/mcp/src/cli/index.tsindex 5fe8215367a3..627c9b45bdd9 100644--- a/services/mcp/src/cli/index.ts+++ b/services/mcp/src/cli/index.ts@@ -9,7 +9,6 @@ import { takeOption } from './args'import type { CliConfig } from './config'import { resolveCliConfig, requireApiKey } from './config'import { buildCliContext } from './context'-import { EXPERIMENTAL_API_ENV, requireExperimentalApiEnabled } from './experimental'import { installSkill, listSkills } from './skills'import { getCliTools } from './tools'@@ -31,7 +30,6 @@ function usage(): string {return `PostHog agent CLIUsage:- posthog-cli api --experimental <command>posthog-cli api --agent-helpposthog-cli api toolsposthog-cli api search <regex>@@ -42,7 +40,6 @@ Usage:posthog-cli api skill install [--force] <skill-id>posthog-cli api agents-md install [--path AGENTS.md]-Experimental: set ${EXPERIMENTAL_API_ENV}=1 or pass --experimental to enable this command group.Destructive tools require --confirm when executed. Use --dry-run before mutations.Agents: run \`posthog-cli api --agent-help\` and load the output into context before anything else.`}@@ -184,7 +181,6 @@ async function runAgentsMdCommand(args: string[]): Promise<void> {async function main(): Promise<void> {const args = process.argv.slice(2)- const experimental = takeFlag(args, '--experimental')const command = args.shift()if (!command || command === 'help' || command === '--help' || command === '-h') {@@ -197,8 +193,6 @@ async function main(): Promise<void> {return}- requireExperimentalApiEnabled({ flagEnabled: experimental })-switch (command) {case 'tools':await runExecCommand('tools')diff --git a/services/mcp/src/cli/tools.ts b/services/mcp/src/cli/tools.tsindex 32f4c7722792..5c6e21f06799 100644--- a/services/mcp/src/cli/tools.ts+++ b/services/mcp/src/cli/tools.ts@@ -7,8 +7,6 @@ interface CliToolOptions {aiConsentGiven?: boolean | undefined}-const warnedSkippedTools = new Set<string>()-function materializeTool(name: string,factory: () => ToolBase<ZodObjectAny>,@@ -23,16 +21,6 @@ function materializeTool(}}-function warnSkippedTool(name: string, reason: unknown): void {- const detail = reason instanceof Error ? reason.message : String(reason)- const warningKey = `${name}:${detail}`- if (warnedSkippedTools.has(warningKey)) {- return- }- warnedSkippedTools.add(warningKey)- process.stderr.write(`Warning: Skipping PostHog API tool "${name}": ${detail}\n`)-}-export function getCliTools(options: CliToolOptions = {}): Tool<ZodObjectAny>[] {const factories: Record<string, () => ToolBase<ZodObjectAny>> = {...TOOL_MAP,@@ -46,15 +34,13 @@ export function getCliTools(options: CliToolOptions = {}): Tool<ZodObjectAny>[]for (const name of names) {const factory = factories[name]if (!factory) {- warnSkippedTool(name, 'no implementation factory was registered')continue}try {const definition = getToolDefinition(name)tools.push(materializeTool(name, () => factory(), definition))- } catch (error) {- warnSkippedTool(name, error)+ } catch {continue}}diff --git a/services/mcp/tests/unit/cli-agent-help.test.ts b/services/mcp/tests/unit/cli-agent-help.test.tsindex e2730dd01918..8c723e9afd5d 100644--- a/services/mcp/tests/unit/cli-agent-help.test.ts+++ b/services/mcp/tests/unit/cli-agent-help.test.ts@@ -1,4 +1,4 @@-import { describe, expect, it } from 'vitest'+import { describe, expect, it, vi } from 'vitest'import { buildAgentHelp, toCliSyntax } from '@/cli/agent-help'import { getCliTools } from '@/cli/tools'@@ -23,7 +23,6 @@ describe('CLI agent help', () => {expect(help).toContain('posthog-cli api info <tool_name>')expect(help).toContain('SCHEMA DRILL-DOWN RULE')expect(help).not.toContain('posthog:exec(')- expect(help).toContain('POSTHOG_CLI_EXPERIMENTAL_API')// Tool-domain index and query-tool catalog come from the bundled registry.expect(help).toContain('query-trends')})@@ -32,6 +31,19 @@ describe('CLI agent help', () => {expect(() => buildAgentHelp(getCliTools())).not.toThrow()})+ it('skips unavailable tools without stderr warnings', () => {+ const stderrWrite = vi.spyOn(process.stderr, 'write').mockImplementation(() => true)++ try {+ const toolNames = getCliTools().map((tool) => tool.name)++ expect(toolNames).not.toContain('evaluations-get')+ expect(stderrWrite).not.toHaveBeenCalled()+ } finally {+ stderrWrite.mockRestore()+ }+ })+it('hides AI-consent tools unless consent is confirmed', () => {const withoutConsent = getCliTools().map((tool) => tool.name)const withConsent = getCliTools({ aiConsentGiven: true }).map((tool) => tool.name)diff --git a/services/mcp/tests/unit/cli-experimental.test.ts b/services/mcp/tests/unit/cli-experimental.test.tsdeleted file mode 100644index 109cb30c9eed..000000000000--- a/services/mcp/tests/unit/cli-experimental.test.ts+++ /dev/null@@ -1,30 +0,0 @@-import { describe, expect, it } from 'vitest'--import { EXPERIMENTAL_API_ENV, isExperimentalApiEnabled, requireExperimentalApiEnabled } from '@/cli/experimental'--describe('CLI experimental gate', () => {- it('is disabled by default', () => {- expect(isExperimentalApiEnabled({})).toBe(false)- })-- it('accepts explicit enabled environment values', () => {- for (const value of ['1', 'true', 'TRUE', 'yes', 'on']) {- expect(isExperimentalApiEnabled({ [EXPERIMENTAL_API_ENV]: value })).toBe(true)- }- })-- it('rejects non-enabled environment values', () => {- for (const value of ['0', 'false', 'no', '']) {- expect(isExperimentalApiEnabled({ [EXPERIMENTAL_API_ENV]: value })).toBe(false)- }- })-- it('allows the per-command flag override', () => {- expect(() => requireExperimentalApiEnabled({ flagEnabled: true, env: {} })).not.toThrow()- })-- it('explains how to enable the command group', () => {- expect(() => requireExperimentalApiEnabled({ env: {} })).toThrow(EXPERIMENTAL_API_ENV)- expect(() => requireExperimentalApiEnabled({ env: {} })).toThrow('--experimental')- })-})