Class HigressMcpClientWrapper

java.lang.Object
io.agentscope.core.tool.mcp.McpClientWrapper
io.agentscope.extensions.higress.HigressMcpClientWrapper
All Implemented Interfaces:
AutoCloseable

public class HigressMcpClientWrapper extends io.agentscope.core.tool.mcp.McpClientWrapper
MCP client wrapper for Higress AI Gateway.

This wrapper extends McpClientWrapper to connect to Higress's unified MCP service endpoint (union-tools-search). When semantic search is enabled in Higress, the gateway provides a special tool x_higress_tool_search that can automatically select the most suitable MCP tools based on user requests.

The wrapper delegates all MCP operations to an underlying McpClientWrapper instance (either async or sync), providing a consistent interface for Higress-specific functionality.

Example usage:


 HigressMcpClientWrapper client = HigressMcpClientBuilder
     .create("higress-mcp")
     .sseEndpoint("http://higress-gateway/mcp-servers/union-tools-search/sse")
     .build();

 // Initialize and list tools
 client.initialize().block();
 List<McpSchema.Tool> tools = client.listTools().block();

 // Call x_higress_tool_search to get recommended tools
 McpSchema.CallToolResult result = client.callTool("x_higress_tool_search",
     Map.of("query", "查询北京天气")).block();
 
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The name of the Higress tool search tool.

    Fields inherited from class io.agentscope.core.tool.mcp.McpClientWrapper

    cachedTools, initialized, name, propagateMeta
  • Method Summary

    Modifier and Type
    Method
    Description
    reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>
    callTool(String toolName, Map<String,Object> arguments)
    Invokes a tool on the Higress gateway.
    reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult>
    callTool(String toolName, Map<String,Object> arguments, Map<String,Object> meta)
     
    void
    Closes the Higress MCP client and releases all resources.
    reactor.core.publisher.Mono<Void>
    Initializes the Higress MCP client connection.
    boolean
    Checks if x_higress_tool_search mode is enabled in this client.
    reactor.core.publisher.Mono<List<io.modelcontextprotocol.spec.McpSchema.Tool>>
    Lists tools available from the Higress gateway.
    reactor.core.publisher.Mono<HigressToolSearchResult>
    Searches for tools matching the query and returns parsed result.
    reactor.core.publisher.Mono<HigressToolSearchResult>
    searchTools(String query, int topK)
    Searches for tools matching the query with topK limit.

    Methods inherited from class io.agentscope.core.tool.mcp.McpClientWrapper

    getCachedTool, getName, isInitialized, isPropagateMeta, setPropagateMeta

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TOOL_SEARCH_NAME

      public static final String TOOL_SEARCH_NAME
      The name of the Higress tool search tool.
      See Also:
  • Method Details

    • initialize

      public reactor.core.publisher.Mono<Void> initialize()
      Initializes the Higress MCP client connection.

      This method delegates to the underlying MCP client to establish connection with the Higress gateway and discover available tools.

      Specified by:
      initialize in class io.agentscope.core.tool.mcp.McpClientWrapper
      Returns:
      a Mono that completes when initialization is finished
    • listTools

      public reactor.core.publisher.Mono<List<io.modelcontextprotocol.spec.McpSchema.Tool>> listTools()
      Lists tools available from the Higress gateway.

      If enableToolSearch is true, this method will:

      1. Call x_higress_tool_search with the configured query
      2. Parse the result to get recommended tools
      3. Convert and return these tools

      If enableToolSearch is false, this method returns all tools from the MCP server.

      Specified by:
      listTools in class io.agentscope.core.tool.mcp.McpClientWrapper
      Returns:
      a Mono emitting the list of available tools
    • callTool

      public reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> callTool(String toolName, Map<String,Object> arguments)
      Invokes a tool on the Higress gateway.

      This method can be used to call any tool available on the gateway, including the x_higress_tool_search tool for intelligent tool selection.

      Specified by:
      callTool in class io.agentscope.core.tool.mcp.McpClientWrapper
      Parameters:
      toolName - the name of the tool to call
      arguments - the arguments to pass to the tool
      Returns:
      a Mono emitting the tool call result
    • callTool

      public reactor.core.publisher.Mono<io.modelcontextprotocol.spec.McpSchema.CallToolResult> callTool(String toolName, Map<String,Object> arguments, Map<String,Object> meta)
      Specified by:
      callTool in class io.agentscope.core.tool.mcp.McpClientWrapper
    • close

      public void close()
      Closes the Higress MCP client and releases all resources.

      This method closes the underlying delegate client and clears all cached data.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in class io.agentscope.core.tool.mcp.McpClientWrapper
    • isToolSearchEnabled

      public boolean isToolSearchEnabled()
      Checks if x_higress_tool_search mode is enabled in this client.

      When enabled, listTools() will call x_higress_tool_search to get semantically relevant tools instead of returning all tools.

      Returns:
      true if tool search mode is enabled
    • searchTools

      public reactor.core.publisher.Mono<HigressToolSearchResult> searchTools(String query)
      Searches for tools matching the query and returns parsed result.

      This method calls x_higress_tool_search and parses the response into a structured HigressToolSearchResult.

      Parameters:
      query - the user query to find matching tools (required)
      Returns:
      a Mono emitting the parsed tool search result
    • searchTools

      public reactor.core.publisher.Mono<HigressToolSearchResult> searchTools(String query, int topK)
      Searches for tools matching the query with topK limit.
      Parameters:
      query - the user query to find matching tools (required)
      topK - the maximum number of tools to return
      Returns:
      a Mono emitting the parsed tool search result