use-update-mcp.ts


Overview

The use-update-mcp.ts file provides React hooks designed to manage the MCP (Managed Control Points) data associated with an agent node within a graph-based UI application. It allows reading, updating, and deleting MCP information tied to an agent form context. The hooks interact with a global graph store and leverage server data to maintain consistency between UI state and backend MCP configurations.

This file is primarily used within a React functional component hierarchy where agent nodes and their MCP configurations are part of a form-driven interface. The hooks abstract MCP-related logic, facilitating cleaner component code and centralized state management.


Exports and Their Functionalities

1. useGetNodeMCP()

Purpose

Retrieves the MCP array from the current agent node's form context.

Details

Returns

Usage Example

const mcpList = useGetNodeMCP();
console.log(mcpList); // Logs the MCP array attached to the current node form

2. useUpdateAgentNodeMCP()

Purpose

Provides a function to update the MCP list for the current agent node in the global graph store.

Details

Parameters

Returns

Usage Example

const { updateNodeMCP } = useUpdateAgentNodeMCP();
updateNodeMCP(['mcp-123', 'mcp-456']); // Updates node MCPs to these two IDs

3. useDeleteAgentNodeMCP()

Purpose

Provides a function to delete a specific MCP entry from the current agent node's MCP list.

Details

Parameters

Returns

Usage Example

const { deleteNodeMCP } = useDeleteAgentNodeMCP();
const handleDelete = deleteNodeMCP('mcp-123');
handleDelete(); // Deletes MCP with id 'mcp-123' from node

Important Implementation Details


Interactions with Other Parts of the System


Visual Diagram

classDiagram
    class useGetNodeMCP {
        +() : IAgentForm['mcp']
    }

    class useUpdateAgentNodeMCP {
        +updateNodeMCP(value: string[]) : void
    }

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

    useUpdateAgentNodeMCP --> useGetNodeMCP : uses
    useDeleteAgentNodeMCP --> useGetNodeMCP : uses
    useUpdateAgentNodeMCP ..> useListMcpServer : uses server data
    useUpdateAgentNodeMCP ..> useGraphStore : updates node form
    useDeleteAgentNodeMCP ..> useGraphStore : updates node form
    useGetNodeMCP ..> AgentFormContext : reads node context
    useUpdateAgentNodeMCP ..> AgentFormContext : reads node context
    useDeleteAgentNodeMCP ..> AgentFormContext : reads node context

Summary

The use-update-mcp.ts file is a utility module of React hooks focused on manipulating MCP data attached to agent nodes within a graph/UI context. It encapsulates fetching MCP data, updating MCP lists, and deleting MCP entries while maintaining synchronization with backend data and global state. The hooks rely on React context, state management stores, and server data fetching hooks to provide a cohesive MCP management API for components in the system.