Skip to content

: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.

16.8 KB
Raw Blame
import { apiMutator } from '../../../../frontend/src/lib/api-orval-mutator'
/**
 * Auto-generated from the Django backend OpenAPI schema.
 * To modify these types, update the Django serializers or views, then run:
 *   hogli build:openapi
 * Questions or issues? #team-devex on Slack
 *
 * PostHog API - generated
 * OpenAPI spec version: 1.0.0
 */
import type {
    MCPActivityOverviewApi,
    MCPAnalyticsSubmissionApi,
    MCPCustomHarnessApi,
    MCPFeedbackCreateApi,
    MCPIntentClusterSnapshotApi,
    MCPIntentDigestApi,
    MCPMissingCapabilityCreateApi,
    MCPSessionIntentApi,
    McpAnalyticsFeedbackListParams,
    McpAnalyticsIntentClustersRetrieveParams,
    McpAnalyticsMissingCapabilitiesListParams,
    McpAnalyticsSessionsActivityOverviewParams,
    McpAnalyticsSessionsGenerateIntentParams,
    McpAnalyticsSessionsListParams,
    McpAnalyticsSessionsToolCallsParams,
    PaginatedMCPAnalyticsSubmissionListApi,
    PaginatedMCPSessionListApi,
    PaginatedMCPToolCallListApi,
    PatchedMCPCustomHarnessApi,
} from './api.schemas'

// https://stackoverflow.com/questions/49579094/typescript-conditional-types-filter-out-readonly-properties-pick-only-requir/49579497#49579497
type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B

type WritableKeys<T> = {
    [P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, P>
}[keyof T]

type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
type DistributeReadOnlyOverUnions<T> = T extends any ? NonReadonly<T> : never

type Writable<T> = Pick<T, WritableKeys<T>>
type NonReadonly<T> = [T] extends [UnionToIntersection<T>]
    ? {
          [P in keyof Writable<T>]: T[P] extends object ? NonReadonly<NonNullable<T[P]>> : T[P]
      }
    : DistributeReadOnlyOverUnions<T>

export const getMcpAnalyticsCustomHarnessesListUrl = (projectId: string) => {
    return `/api/projects/${projectId}/mcp_analytics/custom_harnesses/`
}

/**
 * A team's own harness names, shown in place of "Other" in MCP analytics.
 */
export const mcpAnalyticsCustomHarnessesList = async (
    projectId: string,
    options?: RequestInit
): Promise<MCPCustomHarnessApi[]> => {
    return apiMutator<MCPCustomHarnessApi[]>(getMcpAnalyticsCustomHarnessesListUrl(projectId), {
        ...options,
        method: 'GET',
    })
}

export const getMcpAnalyticsCustomHarnessesCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/mcp_analytics/custom_harnesses/`
}

/**
 * A team's own harness names, shown in place of "Other" in MCP analytics.
 */
export const mcpAnalyticsCustomHarnessesCreate = async (
    projectId: string,
    mCPCustomHarnessApi: NonReadonly<MCPCustomHarnessApi>,
    options?: RequestInit
): Promise<MCPCustomHarnessApi> => {
    return apiMutator<MCPCustomHarnessApi>(getMcpAnalyticsCustomHarnessesCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(mCPCustomHarnessApi),
    })
}

export const getMcpAnalyticsCustomHarnessesRetrieveUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/mcp_analytics/custom_harnesses/${id}/`
}

/**
 * A team's own harness names, shown in place of "Other" in MCP analytics.
 */
export const mcpAnalyticsCustomHarnessesRetrieve = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<MCPCustomHarnessApi> => {
    return apiMutator<MCPCustomHarnessApi>(getMcpAnalyticsCustomHarnessesRetrieveUrl(projectId, id), {
        ...options,
        method: 'GET',
    })
}

export const getMcpAnalyticsCustomHarnessesUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/mcp_analytics/custom_harnesses/${id}/`
}

/**
 * A team's own harness names, shown in place of "Other" in MCP analytics.
 */
export const mcpAnalyticsCustomHarnessesUpdate = async (
    projectId: string,
    id: string,
    mCPCustomHarnessApi: NonReadonly<MCPCustomHarnessApi>,
    options?: RequestInit
): Promise<MCPCustomHarnessApi> => {
    return apiMutator<MCPCustomHarnessApi>(getMcpAnalyticsCustomHarnessesUpdateUrl(projectId, id), {
        ...options,
        method: 'PUT',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(mCPCustomHarnessApi),
    })
}

export const getMcpAnalyticsCustomHarnessesPartialUpdateUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/mcp_analytics/custom_harnesses/${id}/`
}

/**
 * A team's own harness names, shown in place of "Other" in MCP analytics.
 */
export const mcpAnalyticsCustomHarnessesPartialUpdate = async (
    projectId: string,
    id: string,
    patchedMCPCustomHarnessApi?: NonReadonly<PatchedMCPCustomHarnessApi>,
    options?: RequestInit
): Promise<MCPCustomHarnessApi> => {
    return apiMutator<MCPCustomHarnessApi>(getMcpAnalyticsCustomHarnessesPartialUpdateUrl(projectId, id), {
        ...options,
        method: 'PATCH',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(patchedMCPCustomHarnessApi),
    })
}

export const getMcpAnalyticsCustomHarnessesDestroyUrl = (projectId: string, id: string) => {
    return `/api/projects/${projectId}/mcp_analytics/custom_harnesses/${id}/`
}

/**
 * A team's own harness names, shown in place of "Other" in MCP analytics.
 */
export const mcpAnalyticsCustomHarnessesDestroy = async (
    projectId: string,
    id: string,
    options?: RequestInit
): Promise<void> => {
    return apiMutator<void>(getMcpAnalyticsCustomHarnessesDestroyUrl(projectId, id), {
        ...options,
        method: 'DELETE',
    })
}

export const getMcpAnalyticsFeedbackListUrl = (projectId: string, params?: McpAnalyticsFeedbackListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/mcp_analytics/feedback/?${stringifiedParams}`
        : `/api/projects/${projectId}/mcp_analytics/feedback/`
}

/**
 * List MCP feedback submissions for the current project, newest first.
 */
export const mcpAnalyticsFeedbackList = async (
    projectId: string,
    params?: McpAnalyticsFeedbackListParams,
    options?: RequestInit
): Promise<PaginatedMCPAnalyticsSubmissionListApi> => {
    return apiMutator<PaginatedMCPAnalyticsSubmissionListApi>(getMcpAnalyticsFeedbackListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getMcpAnalyticsFeedbackCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/mcp_analytics/feedback/`
}

/**
 * Create a new MCP feedback submission for the current project.
 */
export const mcpAnalyticsFeedbackCreate = async (
    projectId: string,
    mCPFeedbackCreateApi: MCPFeedbackCreateApi,
    options?: RequestInit
): Promise<MCPAnalyticsSubmissionApi> => {
    return apiMutator<MCPAnalyticsSubmissionApi>(getMcpAnalyticsFeedbackCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(mCPFeedbackCreateApi),
    })
}

export const getMcpAnalyticsIntentClustersRetrieveUrl = (
    projectId: string,
    params?: McpAnalyticsIntentClustersRetrieveParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/mcp_analytics/intent_clusters/?${stringifiedParams}`
        : `/api/projects/${projectId}/mcp_analytics/intent_clusters/`
}

/**
 * Return the most recent intent cluster snapshot for the current project. Returns an empty IDLE snapshot when no clustering run has happened yet.
 */
export const mcpAnalyticsIntentClustersRetrieve = async (
    projectId: string,
    params?: McpAnalyticsIntentClustersRetrieveParams,
    options?: RequestInit
): Promise<MCPIntentClusterSnapshotApi[]> => {
    return apiMutator<MCPIntentClusterSnapshotApi[]>(getMcpAnalyticsIntentClustersRetrieveUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getMcpAnalyticsIntentClustersRecomputeUrl = (projectId: string) => {
    return `/api/projects/${projectId}/mcp_analytics/intent_clusters/recompute/`
}

/**
 * Trigger an asynchronous recompute of the intent cluster snapshot. The task runs in the background; poll the GET endpoint for progress (status transitions to 'idle' or 'error').
 */
export const mcpAnalyticsIntentClustersRecompute = async (
    projectId: string,
    options?: RequestInit
): Promise<MCPIntentClusterSnapshotApi> => {
    return apiMutator<MCPIntentClusterSnapshotApi>(getMcpAnalyticsIntentClustersRecomputeUrl(projectId), {
        ...options,
        method: 'POST',
    })
}

export const getMcpAnalyticsMissingCapabilitiesListUrl = (
    projectId: string,
    params?: McpAnalyticsMissingCapabilitiesListParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/mcp_analytics/missing_capabilities/?${stringifiedParams}`
        : `/api/projects/${projectId}/mcp_analytics/missing_capabilities/`
}

/**
 * List missing capability reports for the current project, newest first.
 */
export const mcpAnalyticsMissingCapabilitiesList = async (
    projectId: string,
    params?: McpAnalyticsMissingCapabilitiesListParams,
    options?: RequestInit
): Promise<PaginatedMCPAnalyticsSubmissionListApi> => {
    return apiMutator<PaginatedMCPAnalyticsSubmissionListApi>(
        getMcpAnalyticsMissingCapabilitiesListUrl(projectId, params),
        {
            ...options,
            method: 'GET',
        }
    )
}

export const getMcpAnalyticsMissingCapabilitiesCreateUrl = (projectId: string) => {
    return `/api/projects/${projectId}/mcp_analytics/missing_capabilities/`
}

/**
 * Create a new missing capability report for the current project.
 */
export const mcpAnalyticsMissingCapabilitiesCreate = async (
    projectId: string,
    mCPMissingCapabilityCreateApi: MCPMissingCapabilityCreateApi,
    options?: RequestInit
): Promise<MCPAnalyticsSubmissionApi> => {
    return apiMutator<MCPAnalyticsSubmissionApi>(getMcpAnalyticsMissingCapabilitiesCreateUrl(projectId), {
        ...options,
        method: 'POST',
        headers: { 'Content-Type': 'application/json', ...options?.headers },
        body: JSON.stringify(mCPMissingCapabilityCreateApi),
    })
}

export const getMcpAnalyticsSessionsListUrl = (projectId: string, params?: McpAnalyticsSessionsListParams) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/mcp_analytics/sessions/?${stringifiedParams}`
        : `/api/projects/${projectId}/mcp_analytics/sessions/`
}

/**
 * List MCP sessions for the current project, derived by grouping $mcp_tool_call events by $mcp_session_id. Ordered by newest session start first by default.
 */
export const mcpAnalyticsSessionsList = async (
    projectId: string,
    params?: McpAnalyticsSessionsListParams,
    options?: RequestInit
): Promise<PaginatedMCPSessionListApi> => {
    return apiMutator<PaginatedMCPSessionListApi>(getMcpAnalyticsSessionsListUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getMcpAnalyticsSessionsGenerateIntentUrl = (
    projectId: string,
    id: string,
    params?: McpAnalyticsSessionsGenerateIntentParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/mcp_analytics/sessions/${id}/generate_intent/?${stringifiedParams}`
        : `/api/projects/${projectId}/mcp_analytics/sessions/${id}/generate_intent/`
}

/**
 * Generate (or return the cached) LLM summary of the agent's goal for a session, derived from its recorded $mcp_intents. The first call summarises and persists the result; subsequent calls return the stored summary.
 */
export const mcpAnalyticsSessionsGenerateIntent = async (
    projectId: string,
    id: string,
    params?: McpAnalyticsSessionsGenerateIntentParams,
    options?: RequestInit
): Promise<MCPSessionIntentApi> => {
    return apiMutator<MCPSessionIntentApi>(getMcpAnalyticsSessionsGenerateIntentUrl(projectId, id, params), {
        ...options,
        method: 'POST',
    })
}

export const getMcpAnalyticsSessionsToolCallsUrl = (
    projectId: string,
    id: string,
    params?: McpAnalyticsSessionsToolCallsParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/mcp_analytics/sessions/${id}/tool_calls/?${stringifiedParams}`
        : `/api/projects/${projectId}/mcp_analytics/sessions/${id}/tool_calls/`
}

/**
 * List a page of the $mcp_tool_call events that belong to a given $session_id, in chronological order.
 */
export const mcpAnalyticsSessionsToolCalls = async (
    projectId: string,
    id: string,
    params?: McpAnalyticsSessionsToolCallsParams,
    options?: RequestInit
): Promise<PaginatedMCPToolCallListApi> => {
    return apiMutator<PaginatedMCPToolCallListApi>(getMcpAnalyticsSessionsToolCallsUrl(projectId, id, params), {
        ...options,
        method: 'GET',
    })
}

export const getMcpAnalyticsSessionsActivityOverviewUrl = (
    projectId: string,
    params?: McpAnalyticsSessionsActivityOverviewParams
) => {
    const normalizedParams = new URLSearchParams()

    Object.entries(params || {}).forEach(([key, value]) => {
        if (value !== undefined) {
            normalizedParams.append(key, value === null ? 'null' : String(value))
        }
    })

    const stringifiedParams = normalizedParams.toString()

    return stringifiedParams.length > 0
        ? `/api/projects/${projectId}/mcp_analytics/sessions/activity_overview/?${stringifiedParams}`
        : `/api/projects/${projectId}/mcp_analytics/sessions/activity_overview/`
}

/**
 * Aggregate counters, top tools, agent clients, and the most recent tool calls for the last 30 days, computed in one request. Powers the dashboard's activity view. Results are cached for up to 5 minutes, or 20 seconds when the caller has property restrictions. An empty result is never cached. Pass refresh to skip the cache.
 */
export const mcpAnalyticsSessionsActivityOverview = async (
    projectId: string,
    params?: McpAnalyticsSessionsActivityOverviewParams,
    options?: RequestInit
): Promise<MCPActivityOverviewApi> => {
    return apiMutator<MCPActivityOverviewApi>(getMcpAnalyticsSessionsActivityOverviewUrl(projectId, params), {
        ...options,
        method: 'GET',
    })
}

export const getMcpAnalyticsSessionsIntentDigestUrl = (projectId: string) => {
    return `/api/projects/${projectId}/mcp_analytics/sessions/intent_digest/`
}

/**
 * Generate (or return the cached) LLM digest of what agents are trying to do with this MCP server, derived from the most recent recorded $mcp_intents across all sessions: a one-sentence summary plus semantic themes, each sized and attributed to tools from the intents themselves. Cached by intent corpus and by recency, so repeated calls are cheap and a busy server regenerates at a bounded rate. Powers the dashboard's activity tab.
 */
export const mcpAnalyticsSessionsIntentDigest = async (
    projectId: string,
    options?: RequestInit
): Promise<MCPIntentDigestApi> => {
    return apiMutator<MCPIntentDigestApi>(getMcpAnalyticsSessionsIntentDigestUrl(projectId), {
        ...options,
        method: 'POST',
    })
}