add update and delete mutations

This commit is contained in:
Dustin Healy 2025-06-27 12:30:38 -07:00
parent 568ec2f7d5
commit 5a7bf0b35f
8 changed files with 114 additions and 11 deletions

View file

@ -62,3 +62,45 @@ export const useCreateMCPMutation = (
},
);
};
export const useUpdateMCPMutation = (
options?: t.UpdateMCPMutationOptions,
): UseMutationResult<Record<string, unknown>, Error, { mcp_id: string; data: t.MCP }> => {
const queryClient = useQueryClient();
return useMutation(
({ mcp_id, data }: { mcp_id: string; data: t.MCP }) => {
return dataService.updateMCP({ mcp_id, data });
},
{
onMutate: (variables) => options?.onMutate?.(variables),
onError: (error, variables, context) => options?.onError?.(error, variables, context),
onSuccess: (data, variables, context) => {
// Invalidate tools list to trigger refetch
queryClient.invalidateQueries([QueryKeys.tools]);
return options?.onSuccess?.(data, variables, context);
},
},
);
};
export const useDeleteMCPMutation = (
options?: t.DeleteMCPMutationOptions,
): UseMutationResult<Record<string, unknown>, Error, { mcp_id: string }> => {
const queryClient = useQueryClient();
return useMutation(
({ mcp_id }: { mcp_id: string }) => {
return dataService.deleteMCP({ mcp_id });
},
{
onMutate: (variables) => options?.onMutate?.(variables),
onError: (error, variables, context) => options?.onError?.(error, variables, context),
onSuccess: (data, variables, context) => {
// Invalidate tools list to trigger refetch
queryClient.invalidateQueries([QueryKeys.tools]);
return options?.onSuccess?.(data, variables, context);
},
},
);
};

View file

@ -30,6 +30,8 @@ export function useMCPSelect({ conversationId }: UseMCPSelectOptions) {
const [ephemeralAgent, setEphemeralAgent] = useRecoilState(ephemeralAgentByConvoId(key));
const { data: mcpToolDetails, isFetched } = useAvailableToolsQuery(EModelEndpoint.agents, {
select: (data: TPlugin[]) => {
console.log('🔍 Raw tools data received:', JSON.stringify(data, null, 2));
const mcpToolsMap = new Map<string, TPlugin>();
data.forEach((tool) => {
const isMCP = tool.pluginKey.includes(Constants.mcp_delimiter);
@ -46,7 +48,10 @@ export function useMCPSelect({ conversationId }: UseMCPSelectOptions) {
}
}
});
return Array.from(mcpToolsMap.values());
const result = Array.from(mcpToolsMap.values());
console.log('🔧 Processed MCP tools:', JSON.stringify(result, null, 2));
return result;
},
});