: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 { MakeLogicType, connect, kea, path, selectors } from 'kea'
import { loaders } from 'kea-loaders'
import { subscriptions } from 'kea-subscriptions'
import { teamLogic } from 'scenes/teamLogic'
import { teamSharedAgentServers } from 'products/mcp_store/frontend/gateway/agentServerUtils'
import { mcpGatewayServiceAccountsList } from 'products/mcp_store/frontend/generated/api'
import type {
MCPServiceAccountApi,
MCPServiceAccountServerApi,
} from 'products/mcp_store/frontend/generated/api.schemas'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface scoutMcpServersLogicValues {
currentTeamId: number | null // teamLogic
scoutAccount: MCPServiceAccountApi | null
scoutServers: MCPServiceAccountServerApi[]
scoutServersLoading: boolean
serviceAccounts: MCPServiceAccountApi[]
serviceAccountsLoading: boolean
teamScoutServers: MCPServiceAccountServerApi[]
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface scoutMcpServersLogicActions {
loadServiceAccounts: () => any
loadServiceAccountsFailure: (
error: string,
errorObject?: any
) => {
error: string
errorObject?: any
}
loadServiceAccountsSuccess: (
serviceAccounts: MCPServiceAccountApi[],
payload?: any
) => {
serviceAccounts: MCPServiceAccountApi[]
payload?: any
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface scoutMcpServersLogicMeta {
__keaTypeGenInternalSelectorTypes: {
scoutAccount: (serviceAccounts: MCPServiceAccountApi[]) => MCPServiceAccountApi | null
scoutServers: (scoutAccount: MCPServiceAccountApi | null) => MCPServiceAccountServerApi[]
teamScoutServers: (scoutServers: MCPServiceAccountServerApi[]) => MCPServiceAccountServerApi[]
scoutServersLoading: (serviceAccountsLoading: boolean) => boolean
}
}
export type scoutMcpServersLogicType = MakeLogicType<
scoutMcpServersLogicValues,
scoutMcpServersLogicActions,
Record<string, any>,
scoutMcpServersLogicMeta
>
export const scoutMcpServersLogic = kea<scoutMcpServersLogicType>([
path(['scenes', 'inbox', 'logics', 'scoutMcpServersLogic']),
connect({
values: [teamLogic, ['currentTeamId']],
}),
loaders(({ values }) => ({
serviceAccounts: [
[] as MCPServiceAccountApi[],
{
loadServiceAccounts: async () => {
if (values.currentTeamId === null) {
return []
}
const response = await mcpGatewayServiceAccountsList(String(values.currentTeamId), { limit: 500 })
return response.results
},
},
],
})),
selectors({
scoutAccount: [
(s) => [s.serviceAccounts],
(serviceAccounts: MCPServiceAccountApi[]): MCPServiceAccountApi | null =>
serviceAccounts.find((account) => account.agent_key === 'scout') ?? null,
],
scoutServers: [
(s) => [s.scoutAccount],
(scoutAccount: MCPServiceAccountApi | null): MCPServiceAccountServerApi[] => [
...(scoutAccount?.servers ?? []),
],
],
// Scout runs mount only team-scoped grants, so the picker offers exactly those, one row
// per server (the picker selects servers, not shares).
teamScoutServers: [
(s) => [s.scoutServers],
(scoutServers: MCPServiceAccountServerApi[]): MCPServiceAccountServerApi[] =>
teamSharedAgentServers(scoutServers),
],
scoutServersLoading: [
(s) => [s.serviceAccountsLoading],
(serviceAccountsLoading: boolean): boolean => serviceAccountsLoading,
],
}),
subscriptions(({ actions }) => ({
currentTeamId: () => {
actions.loadServiceAccounts()
},
})),
])