edit-mcp-dialog.tsx


Overview

edit-mcp-dialog.tsx defines the EditMcpDialog React component, which provides a user interface dialog for adding or editing an MCP (Model Control Panel) server configuration. The dialog includes a form for MCP server details, testing capabilities for the server connection, and displays a collapsible list of MCP tools associated with the server.

This file primarily manages user input, validation, server testing, and saving MCP server configurations. It leverages form validation schemas, custom hooks for fetching and testing MCP servers, and UI components from the project’s design system.


Detailed Explanation

Main Exported Component: EditMcpDialog

function EditMcpDialog({
  hideModal,
  loading,
  onOk,
  id,
}: IModalProps<any> & { id: string }) { ... }

Purpose

Props

Prop

Type

Description

hideModal

() => void

Callback to close the dialog.

loading

boolean

Indicates if the save operation is in progress.

onOk

(values: any) => void

Callback triggered on save with form values.

id

string

MCP server ID, if editing an existing server.

Internal State & Hooks

Form Details

Key Methods

Rendering


Helper Function: transferToolToArray

function transferToolToArray(tools: IMCPToolObject): IMCPTool[] { ... }

Parameters:

Returns:


Related Interfaces and Types


Usage Example

import { EditMcpDialog } from './edit-mcp-dialog';

function ParentComponent() {
  const [showDialog, setShowDialog] = useState(false);
  const [loading, setLoading] = useState(false);

  const handleSave = async (values) => {
    setLoading(true);
    await apiSaveMcpServer(values);
    setLoading(false);
    setShowDialog(false);
  };

  return (
    <>
      <button onClick={() => setShowDialog(true)}>Edit MCP Server</button>
      {showDialog && (
        <EditMcpDialog
          id="existing-server-id"
          loading={loading}
          onOk={handleSave}
          hideModal={() => setShowDialog(false)}
        />
      )}
    </>
  );
}

Implementation Details and Algorithms


Interaction with Other Parts of the Application


Visual Diagram

The following Mermaid class diagram summarizes the structure and main methods/properties of the EditMcpDialog component and its helper function:

classDiagram
    class EditMcpDialog {
        +hideModal: () => void
        +loading: boolean
        +onOk(values: object): void
        +id: string
        -isTriggeredBySaving: boolean
        -collapseOpen: boolean
        -fieldChanged: boolean
        -form: UseFormReturn
        -tools: IMCPTool[]
        +handleTest(e: MouseEvent): void
        +handleSave(): void
        +handleOk(values: object): Promise<void>
    }

    class transferToolToArray {
        +tools: IMCPToolObject
        +return IMCPTool[]
    }

    EditMcpDialog ..> transferToolToArray : uses

Summary

This component is critical for maintaining MCP server configurations within the application.


End of Documentation for edit-mcp-dialog.tsx