mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-25 13:45:03 +08:00
86e802bd4b
- Add import_mcp_from_apps command that reuses existing import logic - Add Import button in MCP panel header (consistent with Skills) - Fix import count to only return truly new servers (not already in DB) - Update translations for import success/no-import messages (zh/en/ja)
75 lines
1.7 KiB
TypeScript
75 lines
1.7 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { mcpApi } from "@/lib/api/mcp";
|
|
import type { McpServer } from "@/types";
|
|
import type { AppId } from "@/lib/api/types";
|
|
|
|
/**
|
|
* 查询所有 MCP 服务器(统一管理)
|
|
*/
|
|
export function useAllMcpServers() {
|
|
return useQuery({
|
|
queryKey: ["mcp", "all"],
|
|
queryFn: () => mcpApi.getAllServers(),
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 添加或更新 MCP 服务器
|
|
*/
|
|
export function useUpsertMcpServer() {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (server: McpServer) => mcpApi.upsertUnifiedServer(server),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ["mcp", "all"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 切换 MCP 服务器在特定应用的启用状态
|
|
*/
|
|
export function useToggleMcpApp() {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: ({
|
|
serverId,
|
|
app,
|
|
enabled,
|
|
}: {
|
|
serverId: string;
|
|
app: AppId;
|
|
enabled: boolean;
|
|
}) => mcpApi.toggleApp(serverId, app, enabled),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ["mcp", "all"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 删除 MCP 服务器
|
|
*/
|
|
export function useDeleteMcpServer() {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (id: string) => mcpApi.deleteUnifiedServer(id),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ["mcp", "all"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 从所有应用导入 MCP 服务器
|
|
*/
|
|
export function useImportMcpFromApps() {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: () => mcpApi.importFromApps(),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ["mcp", "all"] });
|
|
},
|
|
});
|
|
}
|