11import { useMutation , useQuery , useQueryClient } from "@tanstack/react-query" ;
2- import {
3- authorizeMcpInstallation ,
4- getMcpInstallationTools ,
5- getMcpRecommendedServers ,
6- getMcpServerInstallations ,
7- installCustomMcpServer ,
8- installMcpTemplate ,
9- refreshMcpInstallationTools ,
10- uninstallMcpServer ,
11- updateMcpServerInstallation ,
12- updateMcpToolApproval ,
13- } from "./api" ;
2+ import { getPostHogApiClient } from "@/lib/posthogApiClient" ;
143import type {
154 InstallCustomMcpServerOptions ,
165 InstallMcpTemplateOptions ,
@@ -29,23 +18,24 @@ const mcpKeys = {
2918export function useMcpMarketplace ( ) {
3019 return useQuery ( {
3120 queryKey : mcpKeys . marketplace ( ) ,
32- queryFn : getMcpRecommendedServers ,
21+ queryFn : ( ) => getPostHogApiClient ( ) . getMcpServers ( ) ,
3322 staleTime : 5 * 60 * 1000 ,
3423 } ) ;
3524}
3625
3726export function useMcpInstallations ( ) {
3827 return useQuery ( {
3928 queryKey : mcpKeys . installations ( ) ,
40- queryFn : getMcpServerInstallations ,
29+ queryFn : ( ) => getPostHogApiClient ( ) . getMcpServerInstallations ( ) ,
4130 staleTime : 30 * 1000 ,
4231 } ) ;
4332}
4433
4534export function useMcpInstallationTools ( installationId : string | null ) {
4635 return useQuery ( {
4736 queryKey : mcpKeys . tools ( installationId ?? "" ) ,
48- queryFn : ( ) => getMcpInstallationTools ( installationId as string ) ,
37+ queryFn : ( ) =>
38+ getPostHogApiClient ( ) . getMcpInstallationTools ( installationId as string ) ,
4939 enabled : ! ! installationId ,
5040 staleTime : 30 * 1000 ,
5141 } ) ;
@@ -61,7 +51,7 @@ export function useInstallCustomMcpServer() {
6151 const queryClient = useQueryClient ( ) ;
6252 return useMutation ( {
6353 mutationFn : ( options : InstallCustomMcpServerOptions ) =>
64- installCustomMcpServer ( options ) ,
54+ getPostHogApiClient ( ) . installCustomMcpServer ( options ) ,
6555 onSuccess : ( ) => invalidateInstallations ( queryClient ) ,
6656 } ) ;
6757}
@@ -70,7 +60,7 @@ export function useInstallMcpTemplate() {
7060 const queryClient = useQueryClient ( ) ;
7161 return useMutation ( {
7262 mutationFn : ( options : InstallMcpTemplateOptions ) =>
73- installMcpTemplate ( options ) ,
63+ getPostHogApiClient ( ) . installMcpTemplate ( options ) ,
7464 onSuccess : ( ) => invalidateInstallations ( queryClient ) ,
7565 } ) ;
7666}
@@ -84,31 +74,39 @@ export function useUpdateMcpServerInstallation() {
8474 } : {
8575 installationId : string ;
8676 updates : UpdateMcpServerInstallationOptions ;
87- } ) => updateMcpServerInstallation ( installationId , updates ) ,
77+ } ) =>
78+ getPostHogApiClient ( ) . updateMcpServerInstallation (
79+ installationId ,
80+ updates ,
81+ ) ,
8882 onSuccess : ( ) => invalidateInstallations ( queryClient ) ,
8983 } ) ;
9084}
9185
9286export function useUninstallMcpServer ( ) {
9387 const queryClient = useQueryClient ( ) ;
9488 return useMutation ( {
95- mutationFn : ( installationId : string ) => uninstallMcpServer ( installationId ) ,
89+ mutationFn : ( installationId : string ) =>
90+ getPostHogApiClient ( ) . uninstallMcpServer ( installationId ) ,
9691 onSuccess : ( ) => invalidateInstallations ( queryClient ) ,
9792 } ) ;
9893}
9994
10095export function useAuthorizeMcpInstallation ( ) {
10196 return useMutation ( {
102- mutationFn : ( args : Parameters < typeof authorizeMcpInstallation > [ 0 ] ) =>
103- authorizeMcpInstallation ( args ) ,
97+ mutationFn : ( args : {
98+ installation_id : string ;
99+ install_source ?: "posthog" | "posthog-code" | "posthog-mobile" ;
100+ posthog_code_callback_url ?: string ;
101+ } ) => getPostHogApiClient ( ) . authorizeMcpInstallation ( args ) ,
104102 } ) ;
105103}
106104
107105export function useRefreshMcpInstallationTools ( ) {
108106 const queryClient = useQueryClient ( ) ;
109107 return useMutation ( {
110108 mutationFn : ( installationId : string ) =>
111- refreshMcpInstallationTools ( installationId ) ,
109+ getPostHogApiClient ( ) . refreshMcpInstallationTools ( installationId ) ,
112110 onSuccess : ( _ , installationId ) => {
113111 queryClient . invalidateQueries ( {
114112 queryKey : mcpKeys . tools ( installationId ) ,
@@ -129,7 +127,12 @@ export function useUpdateMcpToolApproval() {
129127 installationId : string ;
130128 toolName : string ;
131129 approval_state : McpApprovalState ;
132- } ) => updateMcpToolApproval ( installationId , toolName , approval_state ) ,
130+ } ) =>
131+ getPostHogApiClient ( ) . updateMcpToolApproval (
132+ installationId ,
133+ toolName ,
134+ approval_state ,
135+ ) ,
133136 onSuccess : ( _ , { installationId } ) => {
134137 queryClient . invalidateQueries ( {
135138 queryKey : mcpKeys . tools ( installationId ) ,
0 commit comments