: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
// AUTO-GENERATED from products/context_layer/mcp/tools.yaml + OpenAPI — do not edit
import { z } from 'zod'
import type { Schemas } from '@/api/generated'
import * as orvalSchemas from '@/generated/context_layer/api'
import { WikiPageReadLimitSchema } from '@/schema/tool-inputs'
import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'
const ContextWikiChannelResolveSchema = () => {
const ContextLayerAgentChannelPagesRetrieveParams = orvalSchemas.ContextLayerAgentChannelPagesRetrieveParams()
return ContextLayerAgentChannelPagesRetrieveParams.omit({ project_id: true })
}
const contextWikiChannelResolve = (): ToolBase<
ReturnType<typeof ContextWikiChannelResolveSchema>,
Schemas.ChannelWikiPage
> => ({
name: 'context-wiki-channel-resolve',
schema: ContextWikiChannelResolveSchema(),
handler: async (context: Context, params: z.infer<ReturnType<typeof ContextWikiChannelResolveSchema>>) => {
const projectId = await context.stateManager.getProjectId()
const result = await context.api.request<Schemas.ChannelWikiPage>({
method: 'GET',
path: `/api/projects/${encodeURIComponent(String(projectId))}/context_layer/agent/channel-pages/${encodeURIComponent(String(params.channel_id))}/`,
})
return result
},
})
const ContextWikiPageRetrieveSchema = () => {
const ContextLayerAgentPagesRetrieveQueryParams = orvalSchemas.ContextLayerAgentPagesRetrieveQueryParams()
return ContextLayerAgentPagesRetrieveQueryParams.extend({ limit: WikiPageReadLimitSchema })
}
const contextWikiPageRetrieve = (): ToolBase<ReturnType<typeof ContextWikiPageRetrieveSchema>, Schemas.WikiPage> => ({
name: 'context-wiki-page-retrieve',
schema: ContextWikiPageRetrieveSchema(),
handler: async (context: Context, params: z.infer<ReturnType<typeof ContextWikiPageRetrieveSchema>>) => {
const projectId = await context.stateManager.getProjectId()
const result = await context.api.request<Schemas.WikiPage>({
method: 'GET',
path: `/api/projects/${encodeURIComponent(String(projectId))}/context_layer/agent/pages/`,
query: {
head_sha: params.head_sha,
limit: params.limit,
offset: params.offset,
path: params.path,
},
})
return result
},
})
const ContextWikiPageUpdateSchema = () => {
const ContextLayerAgentPagesUpdateBody = orvalSchemas.ContextLayerAgentPagesUpdateBody()
return ContextLayerAgentPagesUpdateBody
}
const contextWikiPageUpdate = (): ToolBase<
ReturnType<typeof ContextWikiPageUpdateSchema>,
Schemas.ContextLayerStatus
> => ({
name: 'context-wiki-page-update',
schema: ContextWikiPageUpdateSchema(),
handler: async (context: Context, params: z.infer<ReturnType<typeof ContextWikiPageUpdateSchema>>) => {
const projectId = await context.stateManager.getProjectId()
const body: Record<string, unknown> = {}
if (params.path !== undefined) {
body['path'] = params.path
}
if (params.content !== undefined) {
body['content'] = params.content
}
if (params.base_head !== undefined) {
body['base_head'] = params.base_head
}
const result = await context.api.request<Schemas.ContextLayerStatus>({
method: 'PUT',
path: `/api/projects/${encodeURIComponent(String(projectId))}/context_layer/agent/pages/`,
body,
})
return result
},
})
const TaskContextWikiChannelResolveSchema = () => {
const ContextLayerAgentChannelPagesRetrieveParams = orvalSchemas.ContextLayerAgentChannelPagesRetrieveParams()
return ContextLayerAgentChannelPagesRetrieveParams.omit({ project_id: true })
}
const taskContextWikiChannelResolve = (): ToolBase<
ReturnType<typeof TaskContextWikiChannelResolveSchema>,
Schemas.ChannelWikiPage
> => ({
name: 'task-context-wiki-channel-resolve',
schema: TaskContextWikiChannelResolveSchema(),
handler: async (context: Context, params: z.infer<ReturnType<typeof TaskContextWikiChannelResolveSchema>>) => {
const projectId = await context.stateManager.getProjectId()
const result = await context.api.request<Schemas.ChannelWikiPage>({
method: 'GET',
path: `/api/projects/${encodeURIComponent(String(projectId))}/context_layer/agent/channel-pages/${encodeURIComponent(String(params.channel_id))}/`,
})
return result
},
})
const TaskContextWikiPageProposeSchema = () => {
const ContextLayerAgentProposalsCreateBody = orvalSchemas.ContextLayerAgentProposalsCreateBody()
return ContextLayerAgentProposalsCreateBody
}
const taskContextWikiPagePropose = (): ToolBase<
ReturnType<typeof TaskContextWikiPageProposeSchema>,
Schemas.WikiPageProposal
> => ({
name: 'task-context-wiki-page-propose',
schema: TaskContextWikiPageProposeSchema(),
handler: async (context: Context, params: z.infer<ReturnType<typeof TaskContextWikiPageProposeSchema>>) => {
const projectId = await context.stateManager.getProjectId()
const body: Record<string, unknown> = {}
if (params.path !== undefined) {
body['path'] = params.path
}
if (params.content !== undefined) {
body['content'] = params.content
}
if (params.base_head !== undefined) {
body['base_head'] = params.base_head
}
const result = await context.api.request<Schemas.WikiPageProposal>({
method: 'POST',
path: `/api/projects/${encodeURIComponent(String(projectId))}/context_layer/agent/proposals/`,
body,
})
return result
},
})
const TaskContextWikiPageRetrieveSchema = () => {
const ContextLayerAgentPagesRetrieveQueryParams = orvalSchemas.ContextLayerAgentPagesRetrieveQueryParams()
return ContextLayerAgentPagesRetrieveQueryParams.extend({ limit: WikiPageReadLimitSchema })
}
const taskContextWikiPageRetrieve = (): ToolBase<
ReturnType<typeof TaskContextWikiPageRetrieveSchema>,
Schemas.WikiPage
> => ({
name: 'task-context-wiki-page-retrieve',
schema: TaskContextWikiPageRetrieveSchema(),
handler: async (context: Context, params: z.infer<ReturnType<typeof TaskContextWikiPageRetrieveSchema>>) => {
const projectId = await context.stateManager.getProjectId()
const result = await context.api.request<Schemas.WikiPage>({
method: 'GET',
path: `/api/projects/${encodeURIComponent(String(projectId))}/context_layer/agent/pages/`,
query: {
head_sha: params.head_sha,
limit: params.limit,
offset: params.offset,
path: params.path,
},
})
return result
},
})
const TaskContextWikiPageUpdateSchema = () => {
const ContextLayerAgentPagesUpdateBody = orvalSchemas.ContextLayerAgentPagesUpdateBody()
return ContextLayerAgentPagesUpdateBody
}
const taskContextWikiPageUpdate = (): ToolBase<
ReturnType<typeof TaskContextWikiPageUpdateSchema>,
Schemas.ContextLayerStatus
> => ({
name: 'task-context-wiki-page-update',
schema: TaskContextWikiPageUpdateSchema(),
handler: async (context: Context, params: z.infer<ReturnType<typeof TaskContextWikiPageUpdateSchema>>) => {
const projectId = await context.stateManager.getProjectId()
const body: Record<string, unknown> = {}
if (params.path !== undefined) {
body['path'] = params.path
}
if (params.content !== undefined) {
body['content'] = params.content
}
if (params.base_head !== undefined) {
body['base_head'] = params.base_head
}
const result = await context.api.request<Schemas.ContextLayerStatus>({
method: 'PUT',
path: `/api/projects/${encodeURIComponent(String(projectId))}/context_layer/agent/pages/`,
body,
})
return result
},
})
export const GENERATED_TOOLS: Record<string, () => ToolBase<ZodObjectAny>> = {
'context-wiki-channel-resolve': contextWikiChannelResolve,
'context-wiki-page-retrieve': contextWikiPageRetrieve,
'context-wiki-page-update': contextWikiPageUpdate,
'task-context-wiki-channel-resolve': taskContextWikiChannelResolve,
'task-context-wiki-page-propose': taskContextWikiPagePropose,
'task-context-wiki-page-retrieve': taskContextWikiPageRetrieve,
'task-context-wiki-page-update': taskContextWikiPageUpdate,
}