In short.
This guide shows Python developers how to give AI agents access to PostHog, with the catch that default access can include tools that make changes. The documented integration supports analytics queries, SQL and management of resources such as feature flags and dashboards through PostHog's hosted MCP server. It explains per-user credentials, access restrictions and approval wrappers. Developers must also handle migration risks: renamed tools can stop existing approval rules from matching and disrupt durable runs. Some tools may incur PostHog AI charges; exact costs and runtime behavior are not established here.
Researched and written by an AI model and checked by a second AI model. How it works
Covers the complete selected page at [https://pydantic.dev/docs/ai/harness/posthog/index.md], including installation, examples, API attributes, authentication, access controls, custom clients, telemetry, YAML loading, the 0.x version notice and tool-name migration warnings. Linked documentation, repositories, provider setup and service terms are excluded. No code, authentication flow, hosted connection, tool call, approval handling, concurrent-user behavior or durable replay was executed or tested.
The overview
identity
The resource is the PostHog documentation page for Pydantic AI Harness at [https://pydantic.dev/docs/ai/harness/posthog/index.md]. It teaches developers to add the PostHog capability to a Python agent.
The capability connects to PostHog's hosted Model Context Protocol server. MCP provides the connection through which the agent discovers tools, calls them and receives results. The page includes installation commands, examples, configuration details and an API reference.
assessment
The guide is useful for developers already building Pydantic AI agents who want those agents to work with PostHog analytics and project resources. Its strongest practical detail is the explanation of how credentials, feature groups, read-only mode and application approval rules control different aspects of access.
The documented defaults require attention: read_only is False and features is unset, which offers every feature group. The key's permissions still limit access, but a basic PostHog() configuration does not itself request read-only tools. Accuracy, latency and reliability were not assessed.
users
The primary audience is Python developers building agents for product analytics, feature-flag inspection or PostHog resource management. Beginners receive short installation and connection examples, although the page assumes familiarity with Python packages, API keys and agent configuration.
Developers serving multiple users receive a separate authentication pattern. Their application must obtain and store each user's credentials and refresh OAuth tokens when applicable; the capability consumes those credentials rather than implementing the application's account-connection flow.
capabilities
The documented tools can query product analytics, run SQL and manage feature flags, experiments, dashboards, surveys and error tracking. Some tools make changes, and availability depends on the connected key and server configuration.
The integration supports feature-group filtering, configurable tool prefixes, per-run credentials and on-demand loading. Existing toolset wrappers can filter tools or require approval, and a separate capability can limit tool output. Core instrumentation records tool-call spans; PostHog adds no spans of its own.
Using it
requirements
The installation example uses pydantic-ai-harness[posthog] together with pydantic-ai-slim[openai]. The second package supplies the model provider used in the example; another model requires its corresponding provider extra. Python and package version requirements are not specified on this page.
The hosted setup requires PostHog credentials. The guide directs users to create a personal API key with the MCP Server preset and states that US and EU Cloud accounts use the same server. Some tools also require organization-level AI data processing to be enabled.
YAML agent loading additionally requires pydantic-ai-slim[spec]. Model-provider account setup, hardware requirements and service quotas are not established by the selected page.
mechanism
The model calls tools exposed by the capability, which communicates with [https://mcp.posthog.com/mcp] using bearer authentication. Feature selection is sent to the server, and read_only=True requests its read-only mode. By default, the server exposes a command-driven posthog tool, which the agent sees as posthog_posthog after prefixing.
Without explicit authentication, the capability uses POSTHOG_PERSONAL_API_KEY and raises an error during agent creation if no key is available. A synchronous or asynchronous auth function instead runs at the start of each run. Returning None or an empty string removes PostHog tools for that run without falling back to the environment variable.
The page documents per-run credentials for separate users. A custom client instead represents one shared connection and owns its URL and authentication; it cannot be combined with the capability's auth or features arguments.
setup
The documented pip command is pip install "pydantic-ai-harness[posthog]" "pydantic-ai-slim[openai]". Import Agent from pydantic_ai and PostHog from pydantic_ai_harness, then add a PostHog instance to the agent's capabilities.
Set POSTHOG_PERSONAL_API_KEY or pass a key through auth. Browser sign-in with auth='oauth' is documented for use on your own machine. For a restricted starting configuration, choose the required feature groups and set read_only=True.
To require approval for every tool call, the page shows wrapping capability.get_toolset() with approval_required() and including DeferredToolRequests in the output type. The application must handle those deferred requests; adding the wrapper alone does not complete that workflow.
example
The basic example creates an agent with PostHog() and asks, 'Which feature flags are active in my project?' For that narrow task, the documented options allow PostHog(features=['flags'], read_only=True). This illustrates the intended interaction; no response or successful execution is established.
The multi-user example defines a Deps object containing an optional posthog_key and an auth function that returns ctx.deps.posthog_key. Each run receives its user's credential through dependencies. For durable execution, the guide recommends reading from run dependencies rather than a global because execution may occur in another process.
Assessment & evidence
limitations
The page warns that Pydantic AI Harness APIs may change between minor releases while on 0.x versions. It provides no exact package release against which all examples can be pinned.
Custom-client read-only handling has a specific trap. In that mode, read_only=True filters tools by their server-provided read-only marking. PostHog's default command-driven tool is not marked read-only, so filtering leaves no PostHog tools and emits MCPReadOnlyNoToolsWarning. The guide says to send the x-posthog-read-only: true header from the client instead.
Local browser OAuth is not the documented multi-user application solution. Concurrent-user isolation, self-hosted compatibility, SQL behavior and recovery from connection failures were not independently assessed.
reasoning
The documented controls address distinct boundaries: feature groups select available functionality, read-only mode removes tools that make changes, key scopes limit accessible accounts and projects, and approval wrappers add application decisions before calls. Taken together, this supports using several controls when a task needs narrowly bounded access.
Tool naming is also operationally significant. The page warns that filters, approval rules and ToolGuardrail configurations using former unprefixed names may stop matching after the prefix change. An unmatched approval or guardrail rule can let calls proceed without its checks.
Durable runs can also fail to replay recorded calls that use old tool names. The documented migration options are to finish existing runs, retain tool_prefix=None temporarily, or deploy through Temporal worker versioning or a new DBOS application version.
alternatives
The page documents configuration alternatives rather than competing products. Fixed credentials suit a single-account script, local OAuth supports browser sign-in on the developer's machine, and an auth function supports credentials selected for each run.
A custom FastMCP client or transport can target a proxy or a PostHog MCP server for a self-hosted instance. That transfers connection and authentication responsibility to the client. Other analytics integrations and agent frameworks are not compared, so relative cost, capability and reliability remain unknown.
evidence
The evidence consists of the complete selected PostHog documentation page. It contains installation instructions, Python and YAML examples, authentication behavior, configuration defaults and migration warnings.
The page links to implementation code at [https://github.com/pydantic/pydantic-ai/tree/main/src/pydantic_ai_harness/pydantic_ai_harness/posthog/]. That repository and all other linked pages are outside the evidence considered here. No code was executed, and no runtime results, benchmarks or independent security findings are available.
Access & freshness
costs
Exact costs are unknown. The selected page provides no package prices, model-provider rates, PostHog plan prices, included allowances or usage limits.
It explicitly states that some PostHog tools use an LLM on PostHog's side and may be billed as PostHog AI usage. The page does not identify every affected tool or quantify those charges, so it cannot support a per-task cost estimate.
rights
The selected page does not state the software license, documentation reuse license or redistribution permissions. Its link to source code does not by itself establish those rights.
API key scopes determine technical access to organizations and projects. They do not establish data-use rights or contractual permission. PostHog service terms, data retention and processing-location guarantees are not included in this page.
freshness
The documentation snapshot was captured on 24 November 2026 at 02:07:17.561 UTC. That is a capture time, not an established publication date or software release date.
The snapshot documents prefixed tool names and a migration from earlier unprefixed names. Its 0.x compatibility warning makes installed-version alignment important. Later documentation changes, current package versions and availability of the example model identifiers are unknown.
actions
For an initial feature-flag query, use a key limited to the intended projects and configure the flags feature group with read_only=True. Establish the intended model-provider setup and applicable PostHog AI charges before estimating operating cost.
For a multi-user application, supply credentials through a per-run auth function and implement credential storage and token refresh in the application. Add and handle approval requests wherever the application requires a decision before tool execution.
Before an upgrade, review filters, approval rules and guardrails against the names the agent actually receives. Plan for durable runs that retain old tool names, and account for the custom-client read-only header behavior if supplying your own connection. These are implementation recommendations, not completed validation.
