tool-command.tsx


Overview

The tool-command.tsx file provides React components and hooks to render customizable command menus with selectable options. It serves as a user interface tool for selecting various operators or MCP (Multi-Cloud Platform) servers through searchable command inputs. The components support multi-selection and notify parent components via callbacks when selections change.

Key functionalities include:

This file is designed to be used within a larger React-based application that involves agents, operators, and MCP servers, facilitating user interaction with these entities.


Components and Functions

1. ToolCommand

Description

A React component rendering a command menu with predefined groups of operator options. Users can search and select multiple operators from categorized lists.

Props

Prop Name

Type

Description

value

string[]

Optional array of currently selected operator IDs.

onChange

(values: string[]) => void (optional)

Callback triggered when selected values change. Receives the updated selection array.

Usage Example

<ToolCommand
  value={['GitHub', 'Google']}
  onChange={(selected) => console.log(selected)}
/>

Details


2. MCPCommand

Description

A React component rendering a command menu populated dynamically with MCP server options fetched from a backend via useListMcpServer hook.

Props

Prop Name

Type

Description

value

string[]

Optional array of selected MCP server IDs.

onChange

(values: string[]) => void (optional)

Callback triggered on selection changes.

Usage Example

<MCPCommand
  value={['server-123']}
  onChange={(selected) => console.log(selected)}
/>

Details


3. ToolCommandItem

Description

A subcomponent representing a selectable command item with a checkbox-style indicator and label/content.

Props

Prop Name

Type

Description

toggleOption

(id: string) => void

Function to toggle selection state of this item.

id

string

Unique identifier for the option.

isSelected

boolean

Whether this item is currently selected.

children

React.ReactNode

Content to display inside the item.

Usage Example

<ToolCommandItem
  id="Google"
  isSelected={true}
  toggleOption={(id) => console.log(`Toggled: ${id}`)}
>
  <OperatorIcon name="Google" />
  <span>Google</span>
</ToolCommandItem>

Details


4. useHandleSelectChange

Description

A custom React hook managing an array of selected option IDs with toggle functionality.

Parameters

Parameter

Type

Description

{ onChange, value }

ToolCommandProps

Props containing optional value array and onChange callback.

Returns

Name

Type

Description

toggleOption

(option: string) => void

Function to toggle selection of an option by its ID.

currentValue

string[]

Current array of selected option IDs.

Usage Example

const { toggleOption, currentValue } = useHandleSelectChange({ value, onChange });

Details


Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class ToolCommand {
        +value?: string[]
        +onChange?(values: string[]): void
        +render()
    }
    class MCPCommand {
        +value?: string[]
        +onChange?(values: string[]): void
        +render()
    }
    class ToolCommandItem {
        +id: string
        +isSelected: boolean
        +toggleOption(id: string): void
        +children: ReactNode
        +render()
    }
    class useHandleSelectChange {
        +toggleOption(option: string): void
        +currentValue: string[]
    }

    ToolCommand o-- ToolCommandItem : renders >
    MCPCommand o-- ToolCommandItem : renders >
    ToolCommand ..> useHandleSelectChange : uses >
    MCPCommand ..> useHandleSelectChange : uses >

Summary

The tool-command.tsx file is a key UI utility for rendering categorized, searchable, and multi-select command menus of operators and MCP servers. It cleanly separates concerns with reusable components and hooks, supports i18n, and integrates seamlessly with backend data and shared UI components. The file enhances user experience by providing intuitive selection controls and dynamic data-driven options in a maintainable, scalable way.