Agent toolkit
Contents
The PostHog agent toolkit equips your AI agents with the ability to interact with the PostHog API and platform. It provides a set of standardized function calling tools that can be integrated with frameworks like Vercel's AI SDK and LangChain.
Our agent toolkit is open source on GitHub and currently available in TypeScript and Python.
Key features
With the agent toolkit, your AI agents can:
- Select PostHog organizations and projects
- Manage insights and dashboards
- Write SQL queries using natural language
- Create, update, or remove feature flags
- Retrieve errors, experiments, and LLM analytics
- Search PostHog documentation
See the available tools section for the full list.
The toolkit also keeps track of your active PostHog project and organization across tool calls and gives you clear error messages when something goes wrong.
MCP vs agent toolkit
The PostHog MCP server and agent toolkit are two complementary ways to integrate PostHog tools into your AI workflows. They share the same foundation: a set of core services and function calls that include tool definitions, schemas, API interactions, state management, error handling, etc.
MCP provides a standardized way for AI agents to connect with external tools and data sources like PostHog. We provide a remote, cloud-hosted MCP server, which makes PostHog's tools accessible without requiring you to host anything yourself.
But with the agent toolkit, you can embed PostHog’s tools directly into your AI workflows, giving you full control over how they’re integrated and called.
Here's a high-level comparison:
 | MCP | Agent toolkit |
---|---|---|
Setup | Ready to use, hosted by PostHog. | Requires development and manual integration. |
Integration | Integrates with any MCP-compatible client like Claude, Cursor, and Windsurf. | Integrates with AI agent frameworks like LangChain and Vercel's AI SDK. |
Control | Standardized MCP interface. | You control how PostHog tool calls fit into your workflow. |
Best for | Out-of-the-box integrations that leverage the MCP ecosystem. | Custom AI workflows that need flexibility and programmatic control. |
Pick what makes sense for your use case. It also doesn't have to be one or the other. Both the MCP server and the agent toolkit can play a role in your AI engineering process.
For example, you could use our agent toolkit for in-house AI development and our MCP server for integrating with third-party agents. Fun fact: Our Python agent toolkit is actually a wrapper around our MCP server (see the source code).
These two approaches are designed to work together or on their own.
Agent toolkit example
Here’s an example of using the agent toolkit with AI frameworks such as LangChain and Vercel’s AI SDK. After installing and importing the toolkit, here’s an example of how it can be integrated:
A few more example prompts you can use with PostHog tool calls within an agentic workflow:
Check out our repo for more integration examples and instructions on how to use our agent toolkit.
Available tools
Dashboards
Tool | Purpose |
---|---|
add-insight-to-dashboard | Add an existing insight to a dashboard. |
dashboard-create | Create a new dashboard in the project. |
dashboard-delete | Delete a dashboard by ID. |
dashboard-get | Get a specific dashboard by ID, including insights that are on the dashboard. |
dashboard-update | Update an existing dashboard by ID. |
dashboards-get-all | Get all dashboards in the project with optional filtering. |
Documentation
Tool | Purpose |
---|---|
docs-search | Search the PostHog documentation for information. |
Error tracking
Tool | Purpose |
---|---|
error-details | Get the details of an error in the project. |
list-errors | List errors in the project. |
Events & properties
Tool | Purpose |
---|---|
event-definitions-list | List all event definitions in the project with optional filtering. |
properties-list | Get properties for events or persons. |
Experiments
Tool | Purpose |
---|---|
experiment-get | Get details of a specific experiment. |
experiment-get-all | Get all experiments in the project. |
Feature flags
Tool | Purpose |
---|---|
create-feature-flag | Creates a new feature flag in the project. |
delete-feature-flag | Delete a feature flag in the project. |
feature-flag-get-all | Get all feature flags in the project. |
feature-flag-get-definition | Get the definition of a feature flag. |
update-feature-flag | Update a feature flag in the project. |
Insights & analytics
Tool | Purpose |
---|---|
insight-create-from-query | Save a query as an insight. |
insight-delete | Delete an insight by ID. |
insight-get | Get a specific insight by ID. |
insight-query | Execute a query on an existing insight to get its results/data. |
insight-update | Update an existing insight by ID. |
insights-get-all | Get all insights in the project with optional filtering. |
query-generate-hogql-from-question | Queries project's PostHog data based on a provided natural language question. |
query-run | Run a trend, funnel or HogQL query. |
LLM analytics
Tool | Purpose |
---|---|
get-llm-total-costs-for-project | Fetches the total LLM daily costs for each model for a project over a given number of days. |
Organization & project management
Tool | Purpose |
---|---|
organization-details-get | Get the details of the active organization. |
organizations-get | Get the organizations the user has access to. |
projects-get | Fetches projects that the user has access to in the current organization. |
property-definitions | Get event and property definitions for the project. |
switch-organization | Change the active organization from the default organization. |
switch-project | Change the active project from the default project. |
Surveys
Tool | Purpose |
---|---|
survey-create | Creates a new survey in the project. |
survey-delete | Delete a survey by ID. |
survey-get | Get a specific survey by ID. |
survey-stats | Get response statistics for a specific survey. |
survey-update | Update an existing survey by ID. |
surveys-get-all | Get all surveys in the project with optional filtering. |
surveys-global-stats | Get aggregated response statistics across all surveys. |