tool-command.tsx


Overview

The tool-command.tsx file defines React components for rendering interactive command selection UIs within an application. These components present categorized command options or MCP (Microservice Control Plane) servers to users, allowing them to select one or multiple commands or servers via a searchable dropdown interface.

The file leverages reusable UI components (Command, CommandInput, CommandList, etc.) for creating accessible command palettes. It manages internal state for selected commands and supports controlled components by accepting value and onChange props.

Two main command components are exported:

Supporting these is the reusable ToolCommandItem component that renders individual selectable command items.


Components and Functions

1. ToolCommand

function ToolCommand({ value, onChange }: ToolCommandProps): JSX.Element

Description

Props

Prop

Type

Description

value

string[] (optional)

Controlled selected command IDs.

onChange

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

Callback triggered when selected commands change.

Usage Example

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

Details


2. MCPCommand

function MCPCommand({ value, onChange }: ToolCommandProps): JSX.Element

Description

Props

Prop

Type

Description

value

string[] (optional)

Controlled selected MCP server IDs.

onChange

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

Callback triggered when selected MCP server changes.

Usage Example

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

Details


3. ToolCommandItem

function ToolCommandItem({ toggleOption, id, isSelected, children }: ToolCommandItemProps & PropsWithChildren): JSX.Element

Description

Props

Prop

Type

Description

toggleOption

(id: string) => void

Function to toggle selection of this item.

id

string

Unique identifier of the command or item.

isSelected

boolean

Whether this item is currently selected.

children

React.ReactNode

Content displayed next to checkbox (e.g., icon + label).

Usage Example

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

4. useHandleSelectChange

function useHandleSelectChange({ onChange, value }: ToolCommandProps) : { toggleOption: (option: string) => void; currentValue: string[] }

Description

Parameters

Parameter

Type

Description

onChange

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

Callback when selection changes.

value

string[] (optional)

Controlled selection values.

Returns

Return

Type

Description

toggleOption

(option: string) => void

Function to toggle a single option.

currentValue

string[]

Current selected values array.

Usage Example

const { toggleOption, currentValue } = useHandleSelectChange({ value, onChange });
toggleOption('Google'); // toggles "Google" in/out of the selection

Important Implementation Details


Interactions 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 provides reusable, localized, and accessible React components to render searchable, multi-select command palettes featuring categorized commands or dynamically fetched MCP servers. It abstracts selection logic into a custom hook and composes UI from modular command components, integrating with icons, localization, and data fetching hooks to build rich interactive selection experiences.