Skip to content

Commit ae54cd5

Browse files
Reuse shared MCP and skill transport on mobile
Generated-By: PostHog Code Task-Id: 40c57a59-b4e1-4760-8e56-ecd03e9c2f0f
1 parent 407d084 commit ae54cd5

6 files changed

Lines changed: 49 additions & 365 deletions

File tree

apps/mobile/src/features/mcp/api.ts

Lines changed: 0 additions & 185 deletions
This file was deleted.

apps/mobile/src/features/mcp/hooks.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
import { 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";
143
import type {
154
InstallCustomMcpServerOptions,
165
InstallMcpTemplateOptions,
@@ -29,23 +18,24 @@ const mcpKeys = {
2918
export function useMcpMarketplace() {
3019
return useQuery({
3120
queryKey: mcpKeys.marketplace(),
32-
queryFn: getMcpRecommendedServers,
21+
queryFn: () => getPostHogApiClient().getMcpServers(),
3322
staleTime: 5 * 60 * 1000,
3423
});
3524
}
3625

3726
export function useMcpInstallations() {
3827
return useQuery({
3928
queryKey: mcpKeys.installations(),
40-
queryFn: getMcpServerInstallations,
29+
queryFn: () => getPostHogApiClient().getMcpServerInstallations(),
4130
staleTime: 30 * 1000,
4231
});
4332
}
4433

4534
export 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

9286
export 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

10095
export 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

107105
export 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),

apps/mobile/src/features/mcp/oauth.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import * as Linking from "expo-linking";
22
import * as WebBrowser from "expo-web-browser";
3-
import {
4-
authorizeMcpInstallation,
5-
installCustomMcpServer,
6-
installMcpTemplate,
7-
} from "./api";
3+
import { getPostHogApiClient } from "@/lib/posthogApiClient";
84
import type {
95
InstallCustomMcpServerOptions,
106
InstallMcpTemplateOptions,
@@ -51,11 +47,12 @@ export async function installTemplateWithOAuth(
5147
"install_source" | "posthog_code_callback_url"
5248
>,
5349
): Promise<McpServerInstallation | "cancelled"> {
54-
const response: McpInstallResponse = await installMcpTemplate({
55-
...options,
56-
install_source: INSTALL_SOURCE,
57-
posthog_code_callback_url: OAUTH_CALLBACK_URL,
58-
});
50+
const response: McpInstallResponse =
51+
await getPostHogApiClient().installMcpTemplate({
52+
...options,
53+
install_source: INSTALL_SOURCE,
54+
posthog_code_callback_url: OAUTH_CALLBACK_URL,
55+
});
5956

6057
if (!isOAuthRedirect(response)) return response;
6158

@@ -75,11 +72,12 @@ export async function installCustomWithOAuth(
7572
"install_source" | "posthog_code_callback_url"
7673
>,
7774
): Promise<McpServerInstallation | "cancelled"> {
78-
const response: McpInstallResponse = await installCustomMcpServer({
79-
...options,
80-
install_source: INSTALL_SOURCE,
81-
posthog_code_callback_url: OAUTH_CALLBACK_URL,
82-
});
75+
const response: McpInstallResponse =
76+
await getPostHogApiClient().installCustomMcpServer({
77+
...options,
78+
install_source: INSTALL_SOURCE,
79+
posthog_code_callback_url: OAUTH_CALLBACK_URL,
80+
});
8381

8482
if (!isOAuthRedirect(response)) return response;
8583
const outcome = await waitForOAuthCallback(response.redirect_url);
@@ -94,11 +92,13 @@ export async function installCustomWithOAuth(
9492
export async function reauthorizeInstallation(
9593
installationId: string,
9694
): Promise<"completed" | "cancelled"> {
97-
const { redirect_url } = await authorizeMcpInstallation({
98-
installation_id: installationId,
99-
install_source: INSTALL_SOURCE,
100-
posthog_code_callback_url: OAUTH_CALLBACK_URL,
101-
});
95+
const { redirect_url } = await getPostHogApiClient().authorizeMcpInstallation(
96+
{
97+
installation_id: installationId,
98+
install_source: INSTALL_SOURCE,
99+
posthog_code_callback_url: OAUTH_CALLBACK_URL,
100+
},
101+
);
102102
return waitForOAuthCallback(redirect_url);
103103
}
104104

0 commit comments

Comments
 (0)