Skip to main content
Back to the PostHog MCP server

MCP Gateway · Claude Code

PostHog icon

Connect PostHog to Claude Code

PostHog's error tracking and feature flags sit close to the code, which makes them a good fit for a terminal agent. Claude Code can find the errors hitting users, read the full issue, mark it resolved after a fix, and explain why a flag evaluated the way it did for one user. Every PostHog call through the Speakeasy gateway is logged against the developer.

Category
Data & analytics
Tools
172
Authentication
API key
Claude Code
CLI

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 Claude Code 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 Claude Code

    Add the organization gateway as an HTTP MCP server, then authenticate from /mcp.

    Run the command below with your organization gateway URL.

    Open /mcp in Claude Code and choose Authenticate to sign in.

    claude mcp add --transport http --scope user \
      'speakeasy' \
      'https://<organization host>/mcp/gateway/<organization slug>'
  4. 04

    Sign in and use PostHog from Claude Code

    The first time Claude Code 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 Claude Code, limited to what the person's access allows, and every call lands in the gateway's tool logs.

To roll it out to a whole team, publish the server in a plugin and register the plugin marketplace in Claude Code's managed settings, so every member gets it without running the command. The device agent can also write and reapply these settings on each laptop.

Use cases

What Claude Code users do with PostHog

Triage errors hitting users

Ask Claude Code which errors affect the most users this week. It queries error tracking for occurrence counts and affected users, then opens the top issue so you can trace it in the code.

query-error-tracking-issueserror-tracking-issues-retrieve

Resolve an issue after the fix

Once your fix is merged, Claude Code sets the error tracking issue's status to resolved and assigns it to you, so the team knows it has been dealt with.

error-tracking-issues-partial-update

Debug a flag for one user

When a user sees the wrong variant, give Claude Code their distinct ID. It shows how each flag evaluated for them and why, next to the flag's definition.

feature-flags-evaluation-reasons-retrievefeature-flag-get-definition

Tools

172 tools

Each PostHog tool can be allowed or denied per team and role at the MCP Gateway before Claude Code 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 Claude Code

The gateway covers every client the same way. The rest depends on what Claude Code 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 Claude Code. MCP-scoped policies are enabled per organization.

Prompt and tool-call blocking

Claude Code

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

User attribution

Claude Code

Claude Code's OpenTelemetry exporter ties each session to a named person. Without it, activity can't be attributed.

Budgets

Claude Code

Spend limits can block Claude Code traffic once a budget is reached.

Device agent and MDM

Claude Code

The device agent installs the marketplace, plugin and telemetry settings and reapplies them every minute. It deploys through MDM.

Anthropic inference hooks

Claude Code

On Claude Enterprise, prompts can be checked before inference with nothing installed on the device (beta).

  • Claude Code on the web doesn't use the laptop setup. It needs the device agent in a shared Anthropic-hosted environment.
  • Plugin marketplace URLs for Claude Code carry an access token, so share install snippets only through a private channel.

Questions

Frequently asked questions

Can I keep destructive PostHog tools away from Claude Code?
Yes. Each of the 172 PostHog tools can be allowed or denied per team and role at the gateway. A developer role could read errors and flags without access to tools such as persons-bulk-delete or delete-feature-flag.
Can Claude Code's PostHog usage be capped?
Spend limits can block Claude Code traffic once a budget is reached. Agent hooks also let Speakeasy allow or deny each prompt and tool call before Claude Code runs it.
How do Claude Code users get PostHog?
An admin adds PostHog from the Speakeasy MCP Catalog and grants access by team or role. Add the organization gateway as an HTTP MCP server, then authenticate from /mcp. Each person then sees only the PostHog tools their access allows.
Are PostHog calls from Claude Code 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.