use-mcp-request.ts


Overview

The use-mcp-request.ts file provides a collection of custom React hooks built on top of the @tanstack/react-query library to interact with MCP (likely "Multi-Cloud Platform" or similar) server-related backend APIs. It encapsulates the logic for CRUD operations, importing/exporting MCP servers, managing associated tools, and testing or caching server tools.

These hooks enable components within the application to easily perform asynchronous queries and mutations related to MCP servers, with built-in support for caching, pagination, debounced search, and optimistic UI updates via React Query's cache invalidation.


Detailed Explanation of Exports

Enum: McpApiAction

Defines string constants used as query or mutation keys for React Query. This helps organize and uniquely identify different API interactions related to MCP servers.

Enum Member

Description

ListMcpServer

Query for listing MCP servers

GetMcpServer

Query for getting a single MCP server

CreateMcpServer

Mutation for creating MCP server

UpdateMcpServer

Mutation for updating MCP server

DeleteMcpServer

Mutation for deleting MCP servers

ImportMcpServer

Mutation for importing MCP servers

ExportMcpServer

Mutation for exporting MCP servers

ListMcpServerTools

Query for listing MCP server tools

TestMcpServerTool

Mutation for testing MCP server tools

CacheMcpServerTool

Mutation for caching MCP server tools

TestMcpServer

Mutation for testing MCP servers


Hook: useListMcpServer

Fetches a paginated list of MCP servers with optional search filtering.


Hook: useGetMcpServer(id: string)

Fetches details of a single MCP server by its ID.


Hook: useCreateMcpServer

Mutation hook to create a new MCP server.


Hook: useUpdateMcpServer

Mutation hook to update an existing MCP server.


Hook: useDeleteMcpServer

Mutation hook to delete MCP servers by IDs.


Hook: useImportMcpServer

Mutation hook to import MCP servers in bulk.


Hook: useExportMcpServer

Mutation hook to export MCP servers by IDs.


Hook: useListMcpServerTools

Queries MCP server tools for a dynamic list of MCP server IDs.


Hook: useTestMcpServer

Mutation hook to test MCP servers with provided parameters.


Hook: useCacheMcpServerTool

Mutation hook to cache a MCP server tool.


Hook: useTestMcpServerTool

Mutation hook to test a MCP server tool.


Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram: Hook Structure and Data Flow

flowchart TD
    subgraph Queries
        useListMcpServer["useListMcpServer"]
        useGetMcpServer["useGetMcpServer"]
        useListMcpServerTools["useListMcpServerTools"]
    end

    subgraph Mutations
        useCreateMcpServer["useCreateMcpServer"]
        useUpdateMcpServer["useUpdateMcpServer"]
        useDeleteMcpServer["useDeleteMcpServer"]
        useImportMcpServer["useImportMcpServer"]
        useExportMcpServer["useExportMcpServer"]
        useTestMcpServer["useTestMcpServer"]
        useCacheMcpServerTool["useCacheMcpServerTool"]
        useTestMcpServerTool["useTestMcpServerTool"]
    end

    Queries -->|fetch data| mcpServerService["mcpServerService API"]
    Mutations -->|send mutation| mcpServerService

    useListMcpServer -->|pagination, search| useHandleSearchChange["useHandleSearchChange"]
    useListMcpServer --> useGetPaginationWithRouter["useGetPaginationWithRouter"]

    mcpServerService --> message["message (UI feedback)"]
    mcpServerService --> i18n["i18n (localization)"]

Summary

The use-mcp-request.ts file is a centralized module that provides typed, reusable React hooks to interact with MCP server backend APIs efficiently. It abstracts complex asynchronous logic including caching, invalidation, debounced search, pagination, and user notifications, enabling UI components to focus on rendering and user experience. It also promotes consistent API usage patterns and integrates seamlessly with the application's localization, state management, and service layers.