mirror of
https://github.com/bytedance/deer-flow.git
synced 2026-05-21 07:26:50 +00:00
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
|
import { loadMCPConfig, updateMCPConfig } from "./api";
|
|
|
|
export function useMCPConfig() {
|
|
const { data, isLoading, error } = useQuery({
|
|
queryKey: ["mcpConfig"],
|
|
queryFn: () => loadMCPConfig(),
|
|
});
|
|
return { config: data, isLoading, error };
|
|
}
|
|
|
|
export function useEnableMCPServer() {
|
|
const queryClient = useQueryClient();
|
|
const { config } = useMCPConfig();
|
|
return useMutation({
|
|
mutationFn: async ({
|
|
serverName,
|
|
enabled,
|
|
}: {
|
|
serverName: string;
|
|
enabled: boolean;
|
|
}) => {
|
|
if (!config) {
|
|
throw new Error("MCP config not found");
|
|
}
|
|
if (!config.mcp_servers[serverName]) {
|
|
throw new Error(`MCP server ${serverName} not found`);
|
|
}
|
|
await updateMCPConfig({
|
|
mcp_servers: {
|
|
...config.mcp_servers,
|
|
[serverName]: {
|
|
...config.mcp_servers[serverName],
|
|
enabled,
|
|
},
|
|
},
|
|
});
|
|
},
|
|
onSuccess: () => {
|
|
void queryClient.invalidateQueries({ queryKey: ["mcpConfig"] });
|
|
},
|
|
});
|
|
}
|