use-update-mcp.ts


Overview

The use-update-mcp.ts file provides React hooks designed to manage the MCP (presumably "Managed Control Points" or a similar domain-specific entity) data associated with an Agent node within a graph-based UI or application state. These hooks enable:

This file is tightly integrated with React's context and state management, leveraging custom hooks and external data fetching hooks (useListMcpServer) to sync MCP data with the UI and backend.


Detailed Explanations

Imports


Exported Hooks

1. useGetNodeMCP

Retrieves the MCP data from the current Agent node context.

Signature

function useGetNodeMCP(): IAgentForm['mcp'] | undefined

Parameters

Returns

Description

Usage Example

const mcpList = useGetNodeMCP();
console.log(mcpList);

2. useUpdateAgentNodeMCP

Provides a method to update the MCP list on the current Agent node.

Signature

function useUpdateAgentNodeMCP(): { updateNodeMCP: (value: string[]) => void }

Parameters

Returns

updateNodeMCP(value: string[])

Implementation Details

Usage Example

const { updateNodeMCP } = useUpdateAgentNodeMCP();
updateNodeMCP(['mcp1', 'mcp2']);

3. useDeleteAgentNodeMCP

Provides a method to delete a specific MCP from the current Agent node.

Signature

function useDeleteAgentNodeMCP(): { deleteNodeMCP: (value: string) => () => void }

Parameters

Returns

deleteNodeMCP(value: string)

Usage Example

const { deleteNodeMCP } = useDeleteAgentNodeMCP();
<button onClick={deleteNodeMCP('mcp1')}>Delete MCP1</button>

Important Implementation Details


Interaction with Other Parts of the System


Mermaid Diagram

flowchart TD
    A[useGetNodeMCP] -->|gets MCP| B[AgentFormContext]
    C[useUpdateAgentNodeMCP] -->|uses| B
    C -->|uses| D[useListMcpServer]
    C -->|calls| E[updateNodeForm in useGraphStore]
    C -->|calls| F[findMcpTools]
    F -->|search in| D
    G[useDeleteAgentNodeMCP] -->|uses| B
    G -->|calls| E
    G -->|uses| A

Summary

The use-update-mcp.ts file encapsulates MCP data management for Agent nodes within a React application, providing reusable hooks to get, update, and delete MCPs. It integrates context, server data fetching, and global state management to keep MCP data consistent and synchronized across the UI and backend. This modular approach facilitates maintainability and clarity in managing complex MCP-related logic in the application.