MCP Gateway · OpenCode
Connect PostHog to OpenCode
Teams building LLM features often track them in PostHog's LLM analytics. From OpenCode, developers can check what each model costs per day, test a code-based evaluation against recent generations, and publish a new version of a stored prompt. The OpenCode plugin sends each prompt and tool call to Speakeasy, which allows or denies it before it runs.
- Category
- Data & analytics
- Tools
- 172
- Authentication
- API key
- OpenCode
- Terminal
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.
Set up
Add PostHog to OpenCode in 4 steps
- 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.
- 02
Choose who can use PostHog
Give teams the
mcp:connectscope on the PostHog server through team access or a role. OpenCode connects to the PostHog server's own URL, and the server's authorization decides who can connect and which tools they can call. - 03
Connect OpenCode
Add the server to OpenCode's own mcp config block as a remote server.
Copy the server's URL from its hosted install page in Speakeasy.
Add it to the
mcpblock of your OpenCode config withtypeset toremote.Restart OpenCode and sign in when prompted.
{ "mcp": { "<server slug>": { "type": "remote", "url": "<URL from the hosted install page>" } } } - 04
Sign in and use PostHog from OpenCode
The first time OpenCode 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 OpenCode, limited to what the person's access allows, and every call lands in the gateway's tool logs.
OpenCode doesn't receive MCP servers from plugins. The observability package is installed separately, from a ZIP or with speakeasy-hooks install --provider=opencode, and the device agent can maintain it.
Use cases
What OpenCode users do with PostHog
Check daily model costs
Ask OpenCode what your LLM features cost over the last week. It fetches the daily cost for each model in the project so you can spot the expensive one.
Test an evaluation before saving it
OpenCode runs your Hog evaluation code against a sample of recent AI generation events without saving results, so you can fix it before it scores real traffic.
Ship a new prompt version
OpenCode reads the stored prompt your app uses, applies the change you tested locally, and publishes it as a new version under the same name.
Tools
172 tools
Each PostHog tool can be allowed or denied per team and role at the MCP Gateway before OpenCode sees it.
docs-search
Use this tool to search the PostHog documentation for information that can help the user with their request. Use it as a fallback when you cannot answer the user's request using other tools in this MCP. Only use this tool for PostHog related questions.
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.
Control
What Speakeasy can see and stop in OpenCode
The gateway covers every client the same way. The rest depends on what OpenCode 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 OpenCode. MCP-scoped policies are enabled per organization.
Prompt and tool-call blocking
OpenCode
The OpenCode plugin sends each prompt and tool call to Speakeasy, which allows or denies it before it runs.
Usage telemetry
OpenCode
Token and cost totals flow through the plugin, reported per turn.
Device agent
OpenCode
The device agent installs and maintains the observability package.
- OpenCode has no OpenTelemetry exporter, so session data comes through the plugin.
- Tool output is blocked at the gateway rather than in OpenCode's hooks.
Questions
Frequently asked questions
How does OpenCode report PostHog session usage?
Where is PostHog tool output blocked for OpenCode?
How do OpenCode users get PostHog?
Are PostHog calls from OpenCode logged?
Connect more