mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-19 00:36:12 +01:00
nicely refactored mcp add done
This commit is contained in:
parent
234827dc57
commit
568ec2f7d5
5 changed files with 22 additions and 240 deletions
|
|
@ -1,17 +1,17 @@
|
|||
import React, { useState, useCallback, useMemo, useEffect } from 'react';
|
||||
import { ChevronLeft } from 'lucide-react';
|
||||
import { Constants } from 'librechat-data-provider';
|
||||
import { useForm, Controller } from 'react-hook-form';
|
||||
import React, { useState, useCallback, useMemo, useEffect } from 'react';
|
||||
import { useUpdateUserPluginsMutation } from 'librechat-data-provider/react-query';
|
||||
import type { TUpdateUserPlugins } from 'librechat-data-provider';
|
||||
import type { MCP } from 'librechat-data-provider';
|
||||
import { useCreateMCPMutation } from '~/data-provider';
|
||||
import { Button, Input, Label } from '~/components/ui';
|
||||
import { useGetStartupConfig } from '~/data-provider';
|
||||
import { useAddToolMutation } from '~/data-provider/Tools/mutations';
|
||||
import MCPPanelSkeleton from './MCPPanelSkeleton';
|
||||
import { useToastContext } from '~/Providers';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import MCPFormPanel from './MCPFormPanel';
|
||||
import { useLocalize } from '~/hooks';
|
||||
|
||||
interface ServerConfigWithVars {
|
||||
serverName: string;
|
||||
|
|
@ -61,7 +61,7 @@ export default function MCPPanel() {
|
|||
},
|
||||
});
|
||||
|
||||
const createMCPMutation = useAddToolMutation({
|
||||
const create = useCreateMCPMutation({
|
||||
onSuccess: () => {
|
||||
showToast({
|
||||
message: localize('com_ui_update_mcp_success'),
|
||||
|
|
@ -119,20 +119,7 @@ export default function MCPPanel() {
|
|||
};
|
||||
|
||||
const handleSaveMCP = (mcp: MCP) => {
|
||||
// Transform MCP data to match the expected format
|
||||
const mcpData = {
|
||||
name: mcp.metadata.name || '',
|
||||
description: mcp.metadata.description || '',
|
||||
url: mcp.metadata.url || '',
|
||||
icon: mcp.metadata.icon || '',
|
||||
tools: mcp.metadata.tools || [],
|
||||
trust: mcp.metadata.trust ?? false,
|
||||
customHeaders: mcp.metadata.customHeaders || [],
|
||||
requestTimeout: mcp.metadata.requestTimeout,
|
||||
connectionTimeout: mcp.metadata.connectionTimeout,
|
||||
};
|
||||
|
||||
createMCPMutation.mutate(mcpData);
|
||||
create.mutate(mcp);
|
||||
};
|
||||
|
||||
if (showMCPForm) {
|
||||
|
|
|
|||
|
|
@ -41,32 +41,14 @@ export const useToolCallMutation = <T extends t.ToolId>(
|
|||
);
|
||||
};
|
||||
|
||||
interface CreateToolData {
|
||||
name: string;
|
||||
description: string;
|
||||
metadata?: Record<string, unknown>;
|
||||
// MCP-specific fields
|
||||
url?: string;
|
||||
icon?: string;
|
||||
tools?: string[];
|
||||
trust?: boolean;
|
||||
customHeaders?: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
value: string;
|
||||
}>;
|
||||
requestTimeout?: number;
|
||||
connectionTimeout?: number;
|
||||
}
|
||||
|
||||
export const useAddToolMutation = (
|
||||
options?: t.MutationOptions<Record<string, unknown>, CreateToolData>,
|
||||
): UseMutationResult<Record<string, unknown>, Error, CreateToolData> => {
|
||||
export const useCreateMCPMutation = (
|
||||
options?: t.CreateMCPMutationOptions,
|
||||
): UseMutationResult<Record<string, unknown>, Error, t.MCP> => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(toolData: CreateToolData) => {
|
||||
return dataService.createTool(toolData);
|
||||
(mcp: t.MCP) => {
|
||||
return dataService.createMCP(mcp);
|
||||
},
|
||||
{
|
||||
onMutate: (variables) => options?.onMutate?.(variables),
|
||||
|
|
@ -74,7 +56,7 @@ export const useAddToolMutation = (
|
|||
onSuccess: (data, variables, context) => {
|
||||
// Invalidate tools list to trigger refetch
|
||||
queryClient.invalidateQueries([QueryKeys.tools]);
|
||||
queryClient.invalidateQueries([QueryKeys.mcpTools]);
|
||||
// queryClient.invalidateQueries([QueryKeys.mcpTools]);
|
||||
return options?.onSuccess?.(data, variables, context);
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue