mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-04-07 00:15:23 +02:00
feat: support initialValues in MCPServerDialog for pre-filling form fields
This commit is contained in:
parent
c68066a636
commit
bda5f1c118
2 changed files with 17 additions and 9 deletions
|
|
@ -53,11 +53,17 @@ export interface MCPServerFormData {
|
|||
|
||||
interface UseMCPServerFormProps {
|
||||
server?: MCPServerDefinition | null;
|
||||
initialValues?: Partial<MCPServerFormData>;
|
||||
onSuccess?: (serverName: string, isOAuth: boolean) => void;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
export function useMCPServerForm({ server, onSuccess, onClose }: UseMCPServerFormProps) {
|
||||
export function useMCPServerForm({
|
||||
server,
|
||||
initialValues,
|
||||
onSuccess,
|
||||
onClose,
|
||||
}: UseMCPServerFormProps) {
|
||||
const localize = useLocalize();
|
||||
const { showToast } = useToastContext();
|
||||
|
||||
|
|
@ -111,11 +117,11 @@ export function useMCPServerForm({ server, onSuccess, onClose }: UseMCPServerFor
|
|||
}
|
||||
|
||||
return {
|
||||
title: '',
|
||||
description: '',
|
||||
url: '',
|
||||
type: 'streamable-http',
|
||||
icon: '',
|
||||
title: initialValues?.title ?? '',
|
||||
description: initialValues?.description ?? '',
|
||||
url: initialValues?.url ?? '',
|
||||
type: initialValues?.type ?? 'streamable-http',
|
||||
icon: initialValues?.icon ?? '',
|
||||
auth: {
|
||||
auth_type: AuthTypeEnum.None,
|
||||
api_key: '',
|
||||
|
|
@ -130,7 +136,7 @@ export function useMCPServerForm({ server, onSuccess, onClose }: UseMCPServerFor
|
|||
},
|
||||
trust: false,
|
||||
};
|
||||
}, [server]);
|
||||
}, [server, initialValues]);
|
||||
|
||||
// Form instance
|
||||
const methods = useForm<MCPServerFormData>({
|
||||
|
|
@ -142,8 +148,6 @@ export function useMCPServerForm({ server, onSuccess, onClose }: UseMCPServerFor
|
|||
|
||||
// Watch URL for auto-fill
|
||||
const watchedUrl = watch('url');
|
||||
const watchedTitle = watch('title');
|
||||
|
||||
// Auto-fill title from URL when title is empty
|
||||
const handleUrlChange = useCallback(
|
||||
(url: string) => {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import {
|
|||
} from 'librechat-data-provider';
|
||||
import { useAuthContext, useHasAccess, useResourcePermissions, MCPServerDefinition } from '~/hooks';
|
||||
import { GenericGrantAccessDialog } from '~/components/Sharing';
|
||||
import type { MCPServerFormData } from './hooks/useMCPServerForm';
|
||||
import { useMCPServerForm } from './hooks/useMCPServerForm';
|
||||
import { useLocalize, useCopyToClipboard } from '~/hooks';
|
||||
import MCPServerForm from './MCPServerForm';
|
||||
|
|
@ -33,6 +34,7 @@ interface MCPServerDialogProps {
|
|||
children?: React.ReactNode;
|
||||
triggerRef?: React.MutableRefObject<HTMLDivElement | HTMLButtonElement | null>;
|
||||
server?: MCPServerDefinition | null;
|
||||
initialValues?: Partial<MCPServerFormData>;
|
||||
}
|
||||
|
||||
export default function MCPServerDialog({
|
||||
|
|
@ -41,6 +43,7 @@ export default function MCPServerDialog({
|
|||
children,
|
||||
triggerRef,
|
||||
server,
|
||||
initialValues,
|
||||
}: MCPServerDialogProps) {
|
||||
const localize = useLocalize();
|
||||
const { user } = useAuthContext();
|
||||
|
|
@ -55,6 +58,7 @@ export default function MCPServerDialog({
|
|||
// Form hook
|
||||
const formHook = useMCPServerForm({
|
||||
server,
|
||||
initialValues,
|
||||
onSuccess: (serverName, isOAuth) => {
|
||||
if (isOAuth) {
|
||||
setCreatedServerId(serverName);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue