Skip to main content
Back to the PostHog MCP server

MCP Gateway · Codex

PostHog icon

Connect PostHog to Codex

Shipping a change behind a flag involves PostHog at both ends. Codex can create the flag for a new code path and check how many users a release condition would reach, mark the deploy on PostHog charts, and search logs afterward. Agent hooks send each prompt and PostHog tool call to Speakeasy, which allows or denies it before Codex runs it.

Category
Data & analytics
Tools
172
Authentication
API key
Codex
CLI and ChatGPT desktop app

Behind the MCP Gateway

Run PostHog MCP behind the MCP Gateway

One URL for every agent, sign-in through your IdP, RBAC down to the tool, and every PostHog call inspected and logged.

Deploy on MCP Gateway

Set up

Add PostHog to Codex in 4 steps

  1. 01

    Add PostHog from the catalog

    An admin finds PostHog in the MCP Catalog (MCP Gateway > MCP > Catalog) and clicks Add. Speakeasy registers the vendor's server as a remote MCP server and proxies sessions to it. Nothing is copied or re-hosted.

    PostHog authenticates with an API key. Enter it under Upstream headers in the install dialog, or later on the server's Settings tab. The key is stored on the server, sent with every upstream request, and never reaches anyone's client configuration.

    Where MCP-scoped policies are enabled, the install offers a recommended risk policy for the new server that detects secrets and PII and inspects tool requests and responses.

  2. 02

    Choose who can use PostHog

    Give teams the mcp:connect scope on the PostHog server through team access or a role. The organization gateway works out each person's servers from their live access, so granting access adds PostHog to their gateway on the next call, and removing it takes it away.

  3. 03

    Connect Codex

    Add the gateway as an MCP server, then log in.

    Run the first command with your organization gateway URL.

    Run the second command to sign in.

    codex mcp add 'speakeasy' \
      --url 'https://<organization host>/mcp/gateway/<organization slug>'
    codex mcp login 'speakeasy'
  4. 04

    Sign in and use PostHog from Codex

    The first time Codex connects, it opens a browser so the person can sign in to Speakeasy through your identity provider.

    From then on, PostHog's tools appear in Codex, limited to what the person's access allows, and every call lands in the gateway's tool logs.

To roll it out to a team, a ChatGPT workspace admin imports the plugin marketplace under Admin > Plugins and sets an installation policy per role. Imported plugins reach nobody until a policy is set.

Use cases

What Codex users do with PostHog

Gate a new code path behind a flag

Codex creates the feature flag your change checks, then assesses how many users the release condition would reach before you turn it on.

create-feature-flagfeature-flags-user-blast-radius-create

Mark the deploy on charts

After a release, Codex adds an annotation with the version and date, so anyone reading a PostHog trend can see when the change went out.

annotation-create

Search logs after a release

Codex lists the available log attributes, then queries logs by severity, service and date range to check that the new code isn't producing errors.

logs-attributes-listquery-logs

Tools

172 tools

Each PostHog tool can be allowed or denied per team and role at the MCP Gateway before Codex sees it.

experiment-get-all

Get all experiments in the project.

experiment-create

Create a comprehensive A/B test experiment. , ['product_view', 'add_to_cart', 'purchase']) and use funnel_steps parameter 6) Configure variants (default 50/50 control/test unless they specify otherwise) 7) Set targeting criteria if needed.

experiment-delete

Delete an experiment by ID.

experiment-update

Update an existing experiment by ID. Can update name, description, lifecycle state, variants, metrics, and other properties. RESTART WORKFLOW: To restart a concluded experiment, set end_date=null, conclusion=null, conclusion_comment=null, and optionally set a new start_date.

experiment-get

Get details of a specific experiment by ID.

See all 172 tools

Control

What Speakeasy can see and stop in Codex

The gateway covers every client the same way. The rest depends on what Codex exposes to Speakeasy.

Tool logs

Gateway

Every PostHog call is logged with the person and the client that made it.

Access by role

Gateway

People reach only the PostHog tools their team or role allows.

Request and response blocking

Gateway

A risk policy scoped to PostHog can reject a tool request before it reaches the server, or withhold a result from Codex. MCP-scoped policies are enabled per organization.

Prompt and tool-call blocking

Codex

Agent hooks send each prompt and tool call to Speakeasy, which allows or denies it before Codex runs it.

User attribution

Codex

An [otel] block in ~/.codex/config.toml sends telemetry to Speakeasy. Export is off by default.

Budgets

Codex

Spend limits can block Codex traffic once a budget is reached.

Device agent and MDM

Codex

The device agent keeps Codex's configuration in sync on managed laptops.

  • Codex cloud tasks and GitHub code review run off the device. Neither the plugin nor OpenTelemetry covers them; OpenAI's Compliance Logs record them after the fact.
  • The workspace rollout needs a ChatGPT Business, Enterprise or Edu admin.

Questions

Frequently asked questions

Are Codex cloud tasks that call PostHog covered by Speakeasy?
Codex cloud tasks and GitHub code review run off the device, so neither the plugin nor OpenTelemetry covers them. OpenAI's Compliance Logs record them after the fact.
Does PostHog data pass through any checks on its way to Codex?
Yes. Prompt injection detection and PII redaction run on every PostHog tool call at the gateway, and each call lands in an audit log tied to a named employee.
How do Codex users get PostHog?
An admin adds PostHog from the Speakeasy MCP Catalog and grants access by team or role. Add the gateway as an MCP server, then log in. Each person then sees only the PostHog tools their access allows.
Are PostHog calls from Codex logged?
Yes. PostHog calls go through the MCP Gateway, which logs each tool call and attributes it to the person and the client that made it.

Connect more

PostHog in other clients

AI everywhere.

Control here.