Agent toolkit

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.

npm install @posthog/agent-toolkit

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.

Our MCP and agent toolkit share the same core services

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:

 MCPAgent toolkit
SetupReady to use, hosted by PostHog.Requires development and manual integration.
IntegrationIntegrates with any MCP-compatible client like Claude, Cursor, and Windsurf.Integrates with AI agent frameworks like LangChain and Vercel's AI SDK.
ControlStandardized MCP interface.You control how PostHog tool calls fit into your workflow.
Best forOut-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:

import { openai } from '@ai-sdk/openai';
import { PostHogAgentToolkit } from '@posthog/agent-toolkit/integrations/ai-sdk';
import { generateText } from 'ai';
// Initialize PostHog toolkit
const toolkit = new PostHogAgentToolkit({
posthogPersonalApiKey: process.env.POSTHOG_PERSONAL_API_KEY,
posthogApiBaseUrl: 'https://us.posthog.com' // or https://eu.posthog.com
});
// Get tools and execute the agent
const tools = await toolkit.getTools();
const result = await generateText({
model: openai('gpt-5-mini'),
tools: tools,
prompt: 'Show me my top 5 PostHog insights and summarize them'
});
console.log(result.text);

A few more example prompts you can use with PostHog tool calls within an agentic workflow:

- What feature flags do I have active?
- Add a new feature flag for our homepage redesign
- What are my most common errors?
- Show me my LLM costs this week

Check out our repo for more integration examples and instructions on how to use our agent toolkit.

Available tools

Dashboards

ToolPurpose
add-insight-to-dashboardAdd an existing insight to a dashboard.
dashboard-createCreate a new dashboard in the project.
dashboard-deleteDelete a dashboard by ID.
dashboard-getGet a specific dashboard by ID, including insights that are on the dashboard.
dashboard-updateUpdate an existing dashboard by ID.
dashboards-get-allGet all dashboards in the project with optional filtering.

Documentation

ToolPurpose
docs-searchSearch the PostHog documentation for information.

Error tracking

ToolPurpose
error-detailsGet the details of an error in the project.
list-errorsList errors in the project.

Events & properties

ToolPurpose
event-definitions-listList all event definitions in the project with optional filtering.
properties-listGet properties for events or persons.

Experiments

ToolPurpose
experiment-getGet details of a specific experiment.
experiment-get-allGet all experiments in the project.

Feature flags

ToolPurpose
create-feature-flagCreates a new feature flag in the project.
delete-feature-flagDelete a feature flag in the project.
feature-flag-get-allGet all feature flags in the project.
feature-flag-get-definitionGet the definition of a feature flag.
update-feature-flagUpdate a feature flag in the project.

Insights & analytics

ToolPurpose
insight-create-from-querySave a query as an insight.
insight-deleteDelete an insight by ID.
insight-getGet a specific insight by ID.
insight-queryExecute a query on an existing insight to get its results/data.
insight-updateUpdate an existing insight by ID.
insights-get-allGet all insights in the project with optional filtering.
query-generate-hogql-from-questionQueries project's PostHog data based on a provided natural language question.
query-runRun a trend, funnel or HogQL query.

LLM analytics

ToolPurpose
get-llm-total-costs-for-projectFetches the total LLM daily costs for each model for a project over a given number of days.

Organization & project management

ToolPurpose
organization-details-getGet the details of the active organization.
organizations-getGet the organizations the user has access to.
projects-getFetches projects that the user has access to in the current organization.
property-definitionsGet event and property definitions for the project.
switch-organizationChange the active organization from the default organization.
switch-projectChange the active project from the default project.

Surveys

ToolPurpose
survey-createCreates a new survey in the project.
survey-deleteDelete a survey by ID.
survey-getGet a specific survey by ID.
survey-statsGet response statistics for a specific survey.
survey-updateUpdate an existing survey by ID.
surveys-get-allGet all surveys in the project with optional filtering.
surveys-global-statsGet aggregated response statistics across all surveys.

Community questions

Was this page useful?

Questions about this page? or post a community question.