Use AI Observability over PostHog MCP
Contents
The PostHog MCP server lets your AI coding agent query LLM traces directly from your code editor. Check costs, monitor errors, and analyze model performance – without switching to the PostHog app.
This works in any MCP client – Cursor, Codex, Claude Code, Windsurf, VS Code, and others.
Before you start
- Set up AI Observability – install a PostHog LLM SDK or provider integration so traces are captured.
- Connect the MCP server – install it in your AI tool and give it access to your project.
What you can do here
With MCP, your coding agent can:
- Check costs before and after deploys – "What's my LLM spend today vs yesterday?" to catch cost regressions
- Monitor error rates – "Are there any LLM errors in the last hour?" to detect issues early
- Compare models – "Compare latency between GPT-4 and Claude for the chat feature" to evaluate model choices
- Investigate specific traces – "Show me the most expensive LLM call from today" to find optimization opportunities
AI Observability tools
The MCP server ships tools for every part of AI Observability. This list is generated from the PostHog repo at build time, so it stays current as tools ship:
Traces – Find traces and read a single trace end to end
- query-llm-trace
- query-llm-traces-list
Costs – Project-wide and per-user LLM spend
- get-llm-total-costs-for-project
- llma-personal-spend
Evaluations – Create, run, and manage evaluations, reports, and directories
- llma-evaluation-config-get
- llma-evaluation-config-set-active-key
- llma-evaluation-create
- llma-evaluation-delete
- llma-evaluation-directory-create
- llma-evaluation-directory-delete
- llma-evaluation-directory-get
- llma-evaluation-directory-list
- llma-evaluation-directory-update
- llma-evaluation-get
- llma-evaluation-judge-models
- llma-evaluation-list
- llma-evaluation-report-create
- llma-evaluation-report-generate
- llma-evaluation-report-get
- llma-evaluation-report-list
- llma-evaluation-report-run-list
- llma-evaluation-report-update
- llma-evaluation-run
- llma-evaluation-test-hog
- llma-evaluation-update
Datasets – Curate datasets and dataset items
- llma-dataset-archive
- llma-dataset-create
- llma-dataset-get
- llma-dataset-item-archive
- llma-dataset-item-create
- llma-dataset-item-get
- llma-dataset-item-list
- llma-dataset-item-restore
- llma-dataset-item-update
- llma-dataset-item-version-list
- llma-dataset-list
- llma-dataset-restore
- llma-dataset-revision-list
- llma-dataset-update
Review queues – Human review queues and their items
- llma-review-queue-create
- llma-review-queue-delete
- llma-review-queue-get
- llma-review-queue-item-create
- llma-review-queue-item-delete
- llma-review-queue-item-get
- llma-review-queue-item-list
- llma-review-queue-item-update
- llma-review-queue-list
- llma-review-queue-update
Clustering – Configure clustering jobs and read their results
- llma-clustering-config-get
- llma-clustering-config-set-event-filters
- llma-clustering-job-create
- llma-clustering-job-delete
- llma-clustering-job-get
- llma-clustering-job-list
- llma-clustering-job-update
Prompts – Manage prompts and prompt labels
- llma-prompt-create
- llma-prompt-duplicate
- llma-prompt-get
- llma-prompt-label-delete
- llma-prompt-label-set
- llma-prompt-list
- llma-prompt-update
Trace reviews – Structured reviews attached to traces
- llma-trace-review-create
- llma-trace-review-delete
- llma-trace-review-get
- llma-trace-review-list
- llma-trace-review-update
Score definitions – Define and version custom scores
- llma-score-definition-create
- llma-score-definition-get
- llma-score-definition-list
- llma-score-definition-new-version
- llma-score-definition-update
Taggers – Auto-tag generations with Hog-based taggers
- llma-tagger-create
- llma-tagger-list
- llma-tagger-test-hog
Provider keys – LLM provider keys used by evaluations
- llma-provider-key-get
- llma-provider-key-list
Custom parsers – Parser recipes for custom LLM event formats
- llma-parser-recipe-create
- llma-parser-recipe-reference
Summarization – AI trace summarization
- llma-summarization-create
A typical workflow starts with query-llm-traces-list to find relevant traces, query-llm-trace to inspect one end to end, and get-llm-total-costs-for-project or execute-sql to aggregate costs and answer custom questions.
Querying prompts and completions? The large content fields –
$ai_input,$ai_output_choices,$ai_input_state,$ai_output_state, and$ai_tools– live only on theposthog.ai_eventstable, notevents. Queryposthog.ai_eventsand anchor ontrace_idto read them. Metadata like model, cost, token counts, and trace IDs stays onevents. Rows inposthog.ai_eventsare dropped after the retention period (30 days by default), but rows ineventshave the same retention policy as product analytics events.
Example prompts
Try these with your MCP-enabled agent:
What are my total LLM costs this week, broken down by model?Find the most expensive LLM calls from the last 24 hours.Are there any LLM errors today?Compare token usage between GPT-4 and Claude for the search feature.How has LLM latency changed over the past 7 days?Show me traces where a single call cost more than $0.50.
Install the MCP server
The recommended way to install is with the AI wizard:
The wizard supports Claude, Cursor, Windsurf, VS Code, and more. You can also configure it manually.
See the MCP server docs for full setup instructions.
The server also exposes tools for the scoring side of AI Observability – creating and running evaluations, managing trace reviews and review queues, and configuring clustering – so an agent can set up scoring for you as well as read the results.
Related
- Teach your agent how to use these tools with skills.
- Explore the same data in the web app.
- Call the same endpoints these tools wrap with the API.
- Learn the data model behind traces, spans, and generations.
- Score traces automatically with AI Evals.