:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { TOOL_MAP } from '@/tools'
import { GENERATED_TOOL_MAP } from '@/tools/generated'
import { mergeToolFactories } from '@/tools/mergeToolFactories'
import { type ToolDefinition, getToolDefinition, getToolsForFeatures } from '@/tools/toolDefinitions'
import type { Tool, ToolBase, ZodObjectAny } from '@/tools/types'
interface CliToolOptions {
aiConsentGiven?: boolean | undefined
}
function materializeTool(
name: string,
factory: () => ToolBase<ZodObjectAny>,
definition: ToolDefinition
): Tool<ZodObjectAny> {
return {
...factory(),
title: definition.title,
description: definition.description,
scopes: definition.required_scopes ?? [],
annotations: definition.annotations,
}
}
export function getCliTools(options: CliToolOptions = {}): Tool<ZodObjectAny>[] {
// Hand-written TOOL_MAP wins on collision (same as tool-catalog / getToolsFromContext).
const factories: Record<string, () => ToolBase<ZodObjectAny>> = mergeToolFactories({
generated: GENERATED_TOOL_MAP,
handwritten: TOOL_MAP,
})
const names = getToolsForFeatures({
aiConsentGiven: options.aiConsentGiven,
})
const tools: Tool<ZodObjectAny>[] = []
for (const name of names) {
const factory = factories[name]
if (!factory) {
continue
}
try {
const definition = getToolDefinition(name)
tools.push(materializeTool(name, () => factory(), definition))
} catch {
continue
}
}
return tools.sort((a, b) => a.name.localeCompare(b.name))
}