mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-25 13:45:03 +08:00
2f18d6ec00
This commit finalizes the v3.7.0 unified MCP architecture migration by removing all deprecated code paths and eliminating compiler warnings. Frontend Changes (~950 lines removed): - Remove deprecated components: McpPanel, McpListItem, McpToggle - Remove deprecated hook: useMcpActions - Remove unused API methods: importFrom*, syncEnabledTo*, syncAllServers - Simplify McpFormModal by removing dual-mode logic (unified/legacy) - Remove syncOtherSide checkbox and conflict detection - Clean up unused imports and state variables - Delete associated test files Backend Changes (~400 lines cleaned): - Remove unused Tauri commands: import_mcp_from_*, sync_enabled_mcp_to_* - Delete unused Gemini MCP functions: get_mcp_status, upsert/delete_mcp_server - Add #[allow(deprecated)] to compatibility layer commands - Add #[allow(dead_code)] to legacy helper functions for future migration - Simplify boolean expression in mcp.rs per Clippy suggestion API Deprecation: - Mark legacy APIs with @deprecated JSDoc (getConfig, upsertServerInConfig, etc.) - Preserve backward compatibility for v3.x, planned removal in v4.0 Verification: - ✅ Zero TypeScript errors (pnpm typecheck) - ✅ Zero Clippy warnings (cargo clippy) - ✅ All code formatted (prettier + cargo fmt) - ✅ Builds successfully Total cleanup: ~1,350 lines of code removed/marked Breaking changes: None (all legacy APIs still functional)
62 lines
1.5 KiB
TypeScript
62 lines
1.5 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"] });
|
|
},
|
|
});
|
|
}
|